~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/server_detect.h

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
 
8
 *  the Free Software Foundation; version 2 of the License, or
 
9
 *  (at your option) any later version.
9
10
 *
10
11
 *  This program is distributed in the hope that it will be useful,
11
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19
 */
19
20
 
20
 
#ifndef CLIENT_SERVER_DETECT_H
21
 
#define CLIENT_SERVER_DETECT_H
 
21
#pragma once
22
22
 
23
 
#include <boost/regex.hpp>
 
23
#include <string>
24
24
 
25
25
class ServerDetect
26
26
{
27
 
  public:
28
 
    enum server_type {
29
 
      SERVER_MYSQL_FOUND,
30
 
      SERVER_DRIZZLE_FOUND,
31
 
      SERVER_UNKNOWN_FOUND
32
 
    };
33
 
 
34
 
    server_type getServerType() { return type; }
35
 
    std::string& getServerVersion() { return version; }
36
 
 
37
 
    ServerDetect(drizzle_con_st *connection) :
38
 
      type(SERVER_UNKNOWN_FOUND),
39
 
      version("")
40
 
    {
41
 
      boost::match_flag_type flags = boost::match_default;
42
 
 
43
 
      boost::regex mysql_regex("(5\\.[0-9]+\\.[0-9]+)");
44
 
      boost::regex drizzle_regex("(20[0-9]{2}\\.(0[1-9]|1[012])\\.[0-9]+)");
45
 
 
46
 
      version= drizzle_con_server_version(connection);
47
 
 
48
 
      if (regex_search(version, mysql_regex, flags))
49
 
        type= SERVER_MYSQL_FOUND;
50
 
      else if (regex_search(version, drizzle_regex, flags))
51
 
        type= SERVER_DRIZZLE_FOUND;
52
 
      else
53
 
        type= SERVER_UNKNOWN_FOUND;
54
 
    }
55
 
 
56
 
  private:
57
 
    server_type type;
58
 
    std::string version;
 
27
public:
 
28
  enum server_type 
 
29
  {
 
30
    SERVER_MYSQL_FOUND,
 
31
    SERVER_DRIZZLE_FOUND,
 
32
    SERVER_UNKNOWN_FOUND
 
33
  };
 
34
 
 
35
  server_type getServerType() const { return type; }
 
36
  const std::string& getServerVersion() const { return version; }
 
37
 
 
38
  ServerDetect(drizzle_con_st*);
 
39
 
 
40
private:
 
41
  server_type type;
 
42
  std::string version;
59
43
};
60
 
 
61
 
#endif /* CLIENT_SERVER_DETECT_H */