~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/option_context.cc

  • Committer: Stewart Smith
  • Date: 2009-05-15 06:57:12 UTC
  • mto: (991.1.5 for-brian)
  • mto: This revision was merged to the branch mainline in revision 1022.
  • Revision ID: stewart@flamingspork.com-20090515065712-bmionylacjmexmmm
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.

Also fix DEFAULT keyword handling for auto-increment so that it defaults to
NULL and not 0 so that the following is valid and generates two auto-inc
values:

create table t1 (a int auto_increment primary key)
insert into t1 (a) values (default);
insert into t1 (a) values (default);

Important to note that 0 is no longer magic. So this gives you duplicate
primary key error:

insert into t1 (a) values(0);
insert into t1 (a) values(0);

as you've inserted the explicit value of 0 twice.

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) 2010 Monty Taylor
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.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
 
22
 
#include "option_context.h"
23
 
 
24
 
namespace drizzled
25
 
{
26
 
namespace module
27
 
{
28
 
 
29
 
 
30
 
option_context::option_context(const std::string &module_name_in,
31
 
                               po::options_description_easy_init po_options_in) :
32
 
  module_name(module_name_in),
33
 
  po_options(po_options_in)
34
 
{ }
35
 
 
36
 
option_context& option_context::operator()(const char* name,
37
 
                                           const char* description)
38
 
{
39
 
  const std::string new_name(prepend_name(module_name, name));
40
 
  po_options(new_name.c_str(), description);
41
 
  return *this;
42
 
}
43
 
 
44
 
 
45
 
option_context& option_context::operator()(const char* name,
46
 
                                           const po::value_semantic* s)
47
 
{
48
 
  const std::string new_name(prepend_name(module_name, name));
49
 
  po_options(new_name.c_str(), s);
50
 
  return *this;
51
 
}
52
 
 
53
 
 
54
 
option_context& option_context::operator()(const char* name,
55
 
                             const po::value_semantic* s,
56
 
                             const char* description)
57
 
{
58
 
  const std::string new_name(prepend_name(module_name, name));
59
 
  po_options(new_name.c_str(), s, description);
60
 
  return *this;
61
 
}
62
 
 
63
 
namespace
64
 
{
65
 
 
66
 
class SwapUnderscores
67
 
{
68
 
public:
69
 
  char operator()(char a) const
70
 
  {
71
 
    if (a == '_')
72
 
      return '-';
73
 
    return a;
74
 
  }
75
 
};
76
 
 
77
 
} /* namespace */
78
 
 
79
 
/*
80
 
 * Private methods.
81
 
 */
82
 
std::string option_context::prepend_name(std::string in_module_name,
83
 
                                         const char *name_in)
84
 
{
85
 
  in_module_name.push_back('.');
86
 
  std::transform(in_module_name.begin(), in_module_name.end(),
87
 
                 in_module_name.begin(), SwapUnderscores());
88
 
  std::transform(in_module_name.begin(), in_module_name.end(),
89
 
                 in_module_name.begin(), ::tolower);
90
 
  in_module_name.append(name_in);
91
 
  return in_module_name;
92
 
}
93
 
 
94
 
 
95
 
} /* namespace module */
96
 
} /* namespace drizzled */
97