~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.h

  • 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
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
 
21
 
 
22
20
#ifndef DRIZZLED_FUNCTION_FUNC_H
23
21
#define DRIZZLED_FUNCTION_FUNC_H
24
22
 
25
23
/// TODO: Rename this file - func.h is stupid.
26
24
 
27
 
#include <drizzled/charset_info.h>
28
 
#include <drizzled/current_session.h>
29
25
#include <drizzled/item.h>
 
26
#include <drizzled/sql_list.h>
30
27
#include <drizzled/item/bin_string.h>
31
 
#include <drizzled/lex_string.h>
32
 
#include <drizzled/sql_list.h>
33
 
#include <drizzled/type/decimal.h>
34
 
 
35
 
#include "drizzled/visibility.h"
36
 
 
37
 
namespace drizzled
38
 
{
39
 
 
40
 
class DRIZZLED_API Item_func :
41
 
  public Item_result_field
42
 
{
43
 
  Session &_session;
44
 
 
 
28
 
 
29
 
 
30
class Item_func :public Item_result_field
 
31
{
45
32
protected:
46
33
  Item **args, *tmp_arg[2];
47
34
  /*
71
58
                       OPTIMIZE_EQUAL };
72
59
  enum Type type() const { return FUNC_ITEM; }
73
60
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
74
 
  virtual ~Item_func() {}
75
 
 
76
61
  Item_func(void):
77
 
    _session(*current_session),
78
 
    allowed_arg_cols(1), arg_count(0),
79
 
    const_item_cache(false)
 
62
    allowed_arg_cols(1), arg_count(0)
80
63
  {
81
64
    with_sum_func= 0;
82
 
    collation.set(DERIVATION_SYSCONST);
83
65
  }
84
 
 
85
66
  Item_func(Item *a):
86
 
    _session(*current_session),
87
 
    allowed_arg_cols(1), arg_count(1),
88
 
    const_item_cache(false)
 
67
    allowed_arg_cols(1), arg_count(1)
89
68
  {
90
69
    args= tmp_arg;
91
70
    args[0]= a;
92
71
    with_sum_func= a->with_sum_func;
93
 
    collation.set(DERIVATION_SYSCONST);
94
72
  }
95
 
  
96
73
  Item_func(Item *a,Item *b):
97
 
    _session(*current_session),
98
 
    allowed_arg_cols(1), arg_count(2),
99
 
    const_item_cache(false)
 
74
    allowed_arg_cols(1), arg_count(2)
100
75
  {
101
76
    args= tmp_arg;
102
77
    args[0]= a; args[1]= b;
103
78
    with_sum_func= a->with_sum_func || b->with_sum_func;
104
 
    collation.set(DERIVATION_SYSCONST);
105
79
  }
106
 
  
107
80
  Item_func(Item *a,Item *b,Item *c):
108
 
    _session(*current_session),
109
 
    allowed_arg_cols(1),
110
 
    const_item_cache(false)
 
81
    allowed_arg_cols(1)
111
82
  {
112
83
    arg_count= 0;
113
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
 
84
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
114
85
    {
115
86
      arg_count= 3;
116
87
      args[0]= a; args[1]= b; args[2]= c;
117
88
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
118
89
    }
119
 
    collation.set(DERIVATION_SYSCONST);
120
90
  }
121
 
  
122
91
  Item_func(Item *a,Item *b,Item *c,Item *d):
123
 
    _session(*current_session),
124
 
    allowed_arg_cols(1),
125
 
    const_item_cache(false)
 
92
    allowed_arg_cols(1)
126
93
  {
127
94
    arg_count= 0;
128
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
 
95
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
129
96
    {
130
97
      arg_count= 4;
131
98
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
132
99
      with_sum_func= a->with_sum_func || b->with_sum_func ||
133
100
        c->with_sum_func || d->with_sum_func;
134
101
    }
135
 
    collation.set(DERIVATION_SYSCONST);
136
102
  }
137
 
  
138
103
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
139
 
    _session(*current_session),
140
 
    allowed_arg_cols(1),
141
 
    const_item_cache(false)
 
104
    allowed_arg_cols(1)
142
105
  {
143
106
    arg_count= 5;
144
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
 
107
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
145
108
    {
146
109
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
147
110
      with_sum_func= a->with_sum_func || b->with_sum_func ||
148
111
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
149
112
    }
150
 
    collation.set(DERIVATION_SYSCONST);
151
113
  }
152
 
  
153
114
  Item_func(List<Item> &list);
154
 
  
155
115
  // Constructor used for Item_cond_and/or (see Item comment)
156
116
  Item_func(Session *session, Item_func *item);
157
 
  
158
117
  bool fix_fields(Session *, Item **ref);
159
118
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
160
119
  table_map used_tables() const;
174
133
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
175
134
    instead.
176
135
  */
177
 
  virtual const char *func_name() const { return NULL; }
 
136
  virtual const char *func_name() const { return NULL; };
178
137
  virtual bool const_item() const { return const_item_cache; }
179
138
  Item **arguments() const { return args; }
180
139
  void set_arguments(List<Item> &list);
197
156
  void count_real_length();
198
157
  void count_decimal_length();
199
158
 
200
 
  bool get_arg0_date(type::Time &ltime, uint32_t fuzzy_date);
201
 
  bool get_arg0_time(type::Time &ltime);
 
159
  bool get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
 
160
  bool get_arg0_time(DRIZZLE_TIME *ltime);
202
161
 
203
162
  bool is_null();
204
163
 
205
 
  virtual bool deterministic() const
206
 
  {
207
 
    return false;
208
 
  }
209
 
 
210
164
  void signal_divide_by_null();
211
165
 
212
166
  virtual Field *tmp_table_field() { return result_field; }
214
168
 
215
169
  Item *get_tmp_table_item(Session *session);
216
170
 
217
 
  type::Decimal *val_decimal(type::Decimal *);
 
171
  my_decimal *val_decimal(my_decimal *);
218
172
 
219
173
  bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
220
174
                          uint32_t flags);
231
185
                     void * arg, traverse_order order);
232
186
  double fix_result(double value);
233
187
 
234
 
  Session &getSession()
235
 
  {
236
 
    return _session;
237
 
  }
238
 
 
239
 
  Session *getSessionPtr()
240
 
  {
241
 
    return &_session;
242
 
  }
243
 
 
244
188
};
245
189
 
246
 
} /* namespace drizzled */
247
 
 
248
190
 
249
191
#endif /* DRIZZLED_FUNCTION_FUNC_H */