Drizzled Public API Documentation

server_detect.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2011 Andrew Hutchings
5  2012 Ajaya K. Agrawal
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "client/client_priv.h"
23 #include "client/server_detect.h"
24 
25 #include <iostream>
26 
27 ServerDetect::ServerDetect(drizzle_con_st *connection) :
28  type(SERVER_UNKNOWN_FOUND),
29  version("")
30 {
31  version= drizzle_con_server_version(connection);
32 
33  const char *safe_query = "SHOW VARIABLES LIKE 'vc_release_id'";
34  drizzle_result_st* result= NULL;
35  drizzle_return_t ret_ptr;
36  result = drizzle_query_str(connection, NULL, safe_query, &ret_ptr);
37 
38  if(ret_ptr == DRIZZLE_RETURN_OK)
39  {
40  ret_ptr = drizzle_result_buffer(result);
41  if(drizzle_result_row_count(result) > 0)
42  {
43  type = SERVER_DRIZZLE_FOUND;
44  }
45  else
46  {
47  type = SERVER_MYSQL_FOUND;
48  }
49  }
50  else
51  {
52  std::cerr << "Server version not detectable. Assuming MySQL." << std::endl;
53  type= SERVER_MYSQL_FOUND;
54  }
55 
56  drizzle_result_free(result);
57 }