Drizzled Public API Documentation

server_detect.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 Andrew Hutchings
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include "client_priv.h"
00022 
00023 #include <boost/regex.hpp>
00024 #include <iostream>
00025 #include <client/server_detect.h>
00026 
00027 ServerDetect::ServerDetect(drizzle_con_st *connection) :
00028   type(SERVER_UNKNOWN_FOUND),
00029   version("")
00030 {
00031   boost::match_flag_type flags = boost::match_default;
00032 
00033   boost::regex mysql_regex("^([3-9]\\.[0-9]+\\.[0-9]+)");
00034   boost::regex drizzle_regex("^(20[0-9]{2}\\.(0[1-9]|1[012])\\.[0-9]+)");
00035 
00036   version= drizzle_con_server_version(connection);
00037 
00038   if (regex_search(version, drizzle_regex, flags))
00039   {
00040     type= SERVER_DRIZZLE_FOUND;
00041   }
00042   else if (regex_search(version, mysql_regex, flags))
00043   {
00044     type= SERVER_MYSQL_FOUND;
00045   }
00046   else
00047   {
00048     std::cerr << "Server version not detectable. Assuming MySQL." << std::endl;
00049     type= SERVER_MYSQL_FOUND;
00050   }
00051 }