Drizzled Public API Documentation

server_detect.h
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.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #ifndef CLIENT_SERVER_DETECT_H
00021 #define CLIENT_SERVER_DETECT_H
00022 
00023 #include <boost/regex.hpp>
00024 
00025 class ServerDetect
00026 {
00027   public:
00028     enum server_type {
00029       SERVER_MYSQL_FOUND,
00030       SERVER_DRIZZLE_FOUND,
00031       SERVER_UNKNOWN_FOUND
00032     };
00033 
00034     server_type getServerType() { return type; }
00035     std::string& getServerVersion() { return version; }
00036 
00037     ServerDetect(drizzle_con_st *connection) :
00038       type(SERVER_UNKNOWN_FOUND),
00039       version("")
00040     {
00041       boost::match_flag_type flags = boost::match_default;
00042 
00043       boost::regex mysql_regex("(5\\.[0-9]+\\.[0-9]+)");
00044       boost::regex drizzle_regex("(20[0-9]{2}\\.(0[1-9]|1[012])\\.[0-9]+)");
00045 
00046       version= drizzle_con_server_version(connection);
00047 
00048       if (regex_search(version, mysql_regex, flags))
00049         type= SERVER_MYSQL_FOUND;
00050       else if (regex_search(version, drizzle_regex, flags))
00051         type= SERVER_DRIZZLE_FOUND;
00052       else
00053         type= SERVER_UNKNOWN_FOUND;
00054     }
00055 
00056   private:
00057     server_type type;
00058     std::string version;
00059 };
00060 
00061 #endif /* CLIENT_SERVER_DETECT_H */