~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/collation_dictionary/collations.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 Sun Microsystems, Inc.
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; either 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 "config.h"
22
 
#include "plugin/collation_dictionary/dictionary.h"
23
 
 
24
 
using namespace std;
25
 
using namespace drizzled;
26
 
 
27
 
 
28
 
CollationsTool::CollationsTool() :
29
 
  CharacterSetsTool("COLLATIONS")
30
 
{
31
 
  add_field("CHARACTER_SET_NAME");
32
 
  add_field("COLLATION_NAME");
33
 
  add_field("DESCRIPTION");
34
 
  add_field("ID", plugin::TableFunction::NUMBER, 0, false);
35
 
  add_field("IS_DEFAULT", plugin::TableFunction::BOOLEAN, 0, false);
36
 
  add_field("IS_COMPILED", plugin::TableFunction::BOOLEAN, 0, false);
37
 
  add_field("SORTLEN", plugin::TableFunction::NUMBER, 0, false);
38
 
}
39
 
 
40
 
CollationsTool::Generator::Generator(Field **arg) :
41
 
  CharacterSetsTool::Generator(arg),
42
 
  is_collation_primed(false)
43
 
{
44
 
}
45
 
 
46
 
 
47
 
bool CollationsTool::Generator::end()
48
 
{
49
 
  return collation_iter == all_charsets+255;
50
 
}
51
 
 
52
 
 
53
 
bool CollationsTool::Generator::check()
54
 
{
55
 
  const CHARSET_INFO *tmp_cs= character_set();
56
 
  const CHARSET_INFO *tmp_cl= collation();
57
 
 
58
 
  if (not tmp_cl || 
59
 
      not (tmp_cl->state & MY_CS_AVAILABLE) ||
60
 
      not my_charset_same(tmp_cs, tmp_cl))
61
 
    return true;
62
 
 
63
 
  return false;
64
 
}
65
 
 
66
 
bool CollationsTool::Generator::nextCollationCore()
67
 
{
68
 
  if (isPrimed())
69
 
  {
70
 
    collation_iter++;
71
 
  }
72
 
  else
73
 
  {
74
 
    if (not isCharacterSetPrimed())
75
 
     return false;
76
 
 
77
 
    collation_iter= all_charsets;
78
 
    prime();
79
 
  }
80
 
 
81
 
  if (end())
82
 
    return false;
83
 
 
84
 
  if (check())
85
 
      return false;
86
 
 
87
 
  return true;
88
 
}
89
 
 
90
 
 
91
 
bool CollationsTool::Generator::next()
92
 
{
93
 
  while (not nextCollationCore())
94
 
  {
95
 
 
96
 
    if (isPrimed() && not end())
97
 
      continue;
98
 
 
99
 
    if (not nextCharacterSet())
100
 
      return false;
101
 
 
102
 
    prime(false);
103
 
  }
104
 
 
105
 
  return true;
106
 
}
107
 
 
108
 
bool CollationsTool::Generator::populate()
109
 
{
110
 
  if (not next())
111
 
    return false;
112
 
 
113
 
  fill();
114
 
 
115
 
  return true;
116
 
}
117
 
 
118
 
void CollationsTool::Generator::fill()
119
 
{
120
 
  const CHARSET_INFO *tmp_cs= character_set();
121
 
  const CHARSET_INFO *tmp_cl= collation_iter[0];
122
 
 
123
 
  assert(tmp_cs);
124
 
  assert(tmp_cl);
125
 
 
126
 
  assert(tmp_cs->name);
127
 
  /* CHARACTER_SET_NAME */
128
 
  push(tmp_cs->name);
129
 
 
130
 
  /* "COLLATION_NAME" */
131
 
  assert(tmp_cl->name);
132
 
  push(tmp_cl->name);
133
 
 
134
 
  /* "DESCRIPTION" */
135
 
  push(tmp_cl->csname);
136
 
 
137
 
  /* COLLATION_ID */
138
 
  push(static_cast<int64_t>(tmp_cl->number));
139
 
 
140
 
  /* IS_DEFAULT */
141
 
  push((bool)(tmp_cl->state & MY_CS_PRIMARY));
142
 
 
143
 
  /* IS_COMPILED */
144
 
  push((bool)(tmp_cl->state & MY_CS_COMPILED));
145
 
 
146
 
  /* SORTLEN */
147
 
  push(static_cast<int64_t>(tmp_cl->strxfrm_multiply));
148
 
}