~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to client/server_detect.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "client_priv.h"
 
22
 
 
23
#include <boost/regex.hpp>
 
24
#include <iostream>
 
25
#include <client/server_detect.h>
 
26
 
 
27
ServerDetect::ServerDetect(drizzle_con_st *connection) :
 
28
  type(SERVER_UNKNOWN_FOUND),
 
29
  version("")
 
30
{
 
31
  boost::match_flag_type flags = boost::match_default;
 
32
 
 
33
  // FIXME: Detecting capabilities from a version number is a recipe for
 
34
  // disaster, like we've seen with 15 years of JavaScript :-)
 
35
  // Anyway, as there is no MySQL 7.x yet, this will do for tonight.
 
36
  // I will get back to detect something tangible after the release (like
 
37
  // presence of some table or its record in DATA_DICTIONARY.
 
38
  boost::regex mysql_regex("^([3-6]\\.[0-9]+\\.[0-9]+)");
 
39
  boost::regex drizzle_regex7("^(20[0-9]{2}\\.(0[1-9]|1[012])\\.[0-9]+)");
 
40
  boost::regex drizzle_regex71("^([7-9]\\.[0-9]+\\.[0-9]+)");
 
41
 
 
42
  version= drizzle_con_server_version(connection);
 
43
 
 
44
  if (regex_search(version, drizzle_regex7, flags))
 
45
  {
 
46
    type= SERVER_DRIZZLE_FOUND;
 
47
  }
 
48
  else if (regex_search(version, drizzle_regex71, flags))
 
49
  {
 
50
    type= SERVER_DRIZZLE_FOUND;
 
51
  }
 
52
  else if (regex_search(version, mysql_regex, flags))
 
53
  {
 
54
    type= SERVER_MYSQL_FOUND;
 
55
  }
 
56
  else
 
57
  {
 
58
    std::cerr << "Server version not detectable. Assuming MySQL." << std::endl;
 
59
    type= SERVER_MYSQL_FOUND;
 
60
  }
 
61
}