~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_func.h

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

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) 2008 Sun Microsystems
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
 
#ifndef DRIZZLED_SERVER_ITEM_FUNC_H
21
 
#define DRIZZLED_SERVER_ITEM_FUNC_H
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
22
16
 
23
17
/* Function items used by mysql */
24
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
25
22
 
26
23
#ifdef HAVE_IEEEFP_H
27
24
extern "C"                              /* Bug in BSDI include file */
30
27
}
31
28
#endif
32
29
 
33
 
#include <drizzled/functions/func.h>
34
 
#include <drizzled/functions/additive_op.h>
35
 
#include <drizzled/functions/connection_id.h>
36
 
#include <drizzled/functions/decimal_typecast.h>
37
 
#include <drizzled/functions/divide.h>
38
 
#include <drizzled/functions/int.h>
39
 
#include <drizzled/functions/int_divide.h>
40
 
#include <drizzled/functions/length.h>
41
 
#include <drizzled/functions/min_max.h>
42
 
#include <drizzled/functions/minus.h>
43
 
#include <drizzled/functions/mod.h>
44
 
#include <drizzled/functions/multiply.h>
45
 
#include <drizzled/functions/neg.h>
46
 
#include <drizzled/functions/numhybrid.h>
47
 
#include <drizzled/functions/num_op.h>
48
 
#include <drizzled/functions/num1.h>
49
 
#include <drizzled/functions/abs.h>
50
 
#include <drizzled/functions/plus.h>
51
 
#include <drizzled/functions/real.h>
52
 
#include <drizzled/functions/dec.h>
53
 
#include <drizzled/functions/int_val.h>
54
 
#include <drizzled/functions/acos.h>
55
 
#include <drizzled/functions/asin.h>
56
 
#include <drizzled/functions/atan.h>
57
 
#include <drizzled/functions/ceiling.h>
58
 
#include <drizzled/functions/cos.h>
59
 
#include <drizzled/functions/exp.h>
60
 
#include <drizzled/functions/floor.h>
61
 
#include <drizzled/functions/ln.h>
62
 
#include <drizzled/functions/log.h>
63
 
#include <drizzled/functions/pow.h>
64
 
#include <drizzled/functions/rand.h>
65
 
#include <drizzled/functions/round.h>
66
 
#include <drizzled/functions/sin.h>
67
 
#include <drizzled/functions/sqrt.h>
68
 
#include <drizzled/functions/sign.h>
69
 
#include <drizzled/functions/signed.h>
70
 
#include <drizzled/functions/tan.h>
71
 
#include <drizzled/functions/unsigned.h>
 
30
class Item_func :public Item_result_field
 
31
{
 
32
protected:
 
33
  Item **args, *tmp_arg[2];
 
34
  /*
 
35
    Allowed numbers of columns in result (usually 1, which means scalar value)
 
36
    0 means get this number from first argument
 
37
  */
 
38
  uint allowed_arg_cols;
 
39
public:
 
40
  uint arg_count;
 
41
  table_map used_tables_cache, not_null_tables_cache;
 
42
  bool const_item_cache;
 
43
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
 
44
                  GE_FUNC,GT_FUNC,FT_FUNC,
 
45
                  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
 
46
                  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
 
47
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
 
48
                  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
 
49
                  NOT_FUNC, NOT_ALL_FUNC,
 
50
                  NOW_FUNC, TRIG_COND_FUNC,
 
51
                  SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
 
52
                  EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC,
 
53
                  NEG_FUNC };
 
54
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
 
55
                       OPTIMIZE_EQUAL };
 
56
  enum Type type() const { return FUNC_ITEM; }
 
57
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
 
58
  Item_func(void):
 
59
    allowed_arg_cols(1), arg_count(0)
 
60
  {
 
61
    with_sum_func= 0;
 
62
  }
 
63
  Item_func(Item *a):
 
64
    allowed_arg_cols(1), arg_count(1)
 
65
  {
 
66
    args= tmp_arg;
 
67
    args[0]= a;
 
68
    with_sum_func= a->with_sum_func;
 
69
  }
 
70
  Item_func(Item *a,Item *b):
 
71
    allowed_arg_cols(1), arg_count(2)
 
72
  {
 
73
    args= tmp_arg;
 
74
    args[0]= a; args[1]= b;
 
75
    with_sum_func= a->with_sum_func || b->with_sum_func;
 
76
  }
 
77
  Item_func(Item *a,Item *b,Item *c):
 
78
    allowed_arg_cols(1)
 
79
  {
 
80
    arg_count= 0;
 
81
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
 
82
    {
 
83
      arg_count= 3;
 
84
      args[0]= a; args[1]= b; args[2]= c;
 
85
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
 
86
    }
 
87
  }
 
88
  Item_func(Item *a,Item *b,Item *c,Item *d):
 
89
    allowed_arg_cols(1)
 
90
  {
 
91
    arg_count= 0;
 
92
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
 
93
    {
 
94
      arg_count= 4;
 
95
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
 
96
      with_sum_func= a->with_sum_func || b->with_sum_func ||
 
97
        c->with_sum_func || d->with_sum_func;
 
98
    }
 
99
  }
 
100
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
 
101
    allowed_arg_cols(1)
 
102
  {
 
103
    arg_count= 5;
 
104
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
 
105
    {
 
106
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
 
107
      with_sum_func= a->with_sum_func || b->with_sum_func ||
 
108
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
 
109
    }
 
110
  }
 
111
  Item_func(List<Item> &list);
 
112
  // Constructor used for Item_cond_and/or (see Item comment)
 
113
  Item_func(THD *thd, Item_func *item);
 
114
  bool fix_fields(THD *, Item **ref);
 
115
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
 
116
  table_map used_tables() const;
 
117
  table_map not_null_tables() const;
 
118
  void update_used_tables();
 
119
  bool eq(const Item *item, bool binary_cmp) const;
 
120
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
 
121
  virtual bool have_rev_func() const { return 0; }
 
122
  virtual Item *key_item() const { return args[0]; }
 
123
  /*
 
124
    This method is used for debug purposes to print the name of an
 
125
    item to the debug log. The second use of this method is as
 
126
    a helper function of print(), where it is applicable.
 
127
    To suit both goals it should return a meaningful,
 
128
    distinguishable and sintactically correct string.  This method
 
129
    should not be used for runtime type identification, use enum
 
130
    {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
 
131
    instead.
 
132
  */
 
133
  virtual const char *func_name() const= 0;
 
134
  virtual bool const_item() const { return const_item_cache; }
 
135
  inline Item **arguments() const { return args; }
 
136
  void set_arguments(List<Item> &list);
 
137
  inline uint argument_count() const { return arg_count; }
 
138
  inline void remove_arguments() { arg_count=0; }
 
139
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
 
140
  virtual void print(String *str, enum_query_type query_type);
 
141
  void print_op(String *str, enum_query_type query_type);
 
142
  void print_args(String *str, uint from, enum_query_type query_type);
 
143
  virtual void fix_num_length_and_dec();
 
144
  void count_only_length();
 
145
  void count_real_length();
 
146
  void count_decimal_length();
 
147
  inline bool get_arg0_date(MYSQL_TIME *ltime, uint fuzzy_date)
 
148
  {
 
149
    return (null_value=args[0]->get_date(ltime, fuzzy_date));
 
150
  }
 
151
  inline bool get_arg0_time(MYSQL_TIME *ltime)
 
152
  {
 
153
    return (null_value=args[0]->get_time(ltime));
 
154
  }
 
155
  bool is_null() { 
 
156
    update_null_value();
 
157
    return null_value; 
 
158
  }
 
159
  void signal_divide_by_null();
 
160
  friend class udf_handler;
 
161
  Field *tmp_table_field() { return result_field; }
 
162
  Field *tmp_table_field(TABLE *t_arg);
 
163
  Item *get_tmp_table_item(THD *thd);
 
164
 
 
165
  my_decimal *val_decimal(my_decimal *);
 
166
 
 
167
  bool agg_arg_collations(DTCollation &c, Item **items, uint nitems,
 
168
                          uint flags)
 
169
  {
 
170
    return agg_item_collations(c, func_name(), items, nitems, flags, 1);
 
171
  }
 
172
  bool agg_arg_collations_for_comparison(DTCollation &c,
 
173
                                         Item **items, uint nitems,
 
174
                                         uint flags)
 
175
  {
 
176
    return agg_item_collations_for_comparison(c, func_name(),
 
177
                                              items, nitems, flags);
 
178
  }
 
179
  bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems,
 
180
                        uint flags, int item_sep)
 
181
  {
 
182
    return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep);
 
183
  }
 
184
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
 
185
  Item *transform(Item_transformer transformer, uchar *arg);
 
186
  Item* compile(Item_analyzer analyzer, uchar **arg_p,
 
187
                Item_transformer transformer, uchar *arg_t);
 
188
  void traverse_cond(Cond_traverser traverser,
 
189
                     void * arg, traverse_order order);
 
190
  inline double fix_result(double value)
 
191
  {
 
192
    if (isfinite(value))
 
193
      return value;
 
194
    null_value=1;
 
195
    return 0.0;
 
196
  }
 
197
};
 
198
 
 
199
 
 
200
class Item_real_func :public Item_func
 
201
{
 
202
public:
 
203
  Item_real_func() :Item_func() {}
 
204
  Item_real_func(Item *a) :Item_func(a) {}
 
205
  Item_real_func(Item *a,Item *b) :Item_func(a,b) {}
 
206
  Item_real_func(List<Item> &list) :Item_func(list) {}
 
207
  String *val_str(String*str);
 
208
  my_decimal *val_decimal(my_decimal *decimal_value);
 
209
  longlong val_int()
 
210
    { DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); }
 
211
  enum Item_result result_type () const { return REAL_RESULT; }
 
212
  void fix_length_and_dec()
 
213
  { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
 
214
};
 
215
 
 
216
 
 
217
class Item_func_numhybrid: public Item_func
 
218
{
 
219
protected:
 
220
  Item_result hybrid_type;
 
221
public:
 
222
  Item_func_numhybrid(Item *a) :Item_func(a), hybrid_type(REAL_RESULT)
 
223
  {}
 
224
  Item_func_numhybrid(Item *a,Item *b)
 
225
    :Item_func(a,b), hybrid_type(REAL_RESULT)
 
226
  {}
 
227
  Item_func_numhybrid(List<Item> &list)
 
228
    :Item_func(list), hybrid_type(REAL_RESULT)
 
229
  {}
 
230
 
 
231
  enum Item_result result_type () const { return hybrid_type; }
 
232
  void fix_length_and_dec();
 
233
  void fix_num_length_and_dec();
 
234
  virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */
 
235
 
 
236
  double val_real();
 
237
  longlong val_int();
 
238
  my_decimal *val_decimal(my_decimal *);
 
239
  String *val_str(String*str);
 
240
 
 
241
  /**
 
242
     @brief Performs the operation that this functions implements when the
 
243
     result type is INT.
 
244
 
 
245
     @return The result of the operation.
 
246
  */
 
247
  virtual longlong int_op()= 0;
 
248
 
 
249
  /**
 
250
     @brief Performs the operation that this functions implements when the
 
251
     result type is REAL.
 
252
 
 
253
     @return The result of the operation.
 
254
  */
 
255
  virtual double real_op()= 0;
 
256
 
 
257
  /**
 
258
     @brief Performs the operation that this functions implements when the
 
259
     result type is DECIMAL.
 
260
 
 
261
     @param A pointer where the DECIMAL value will be allocated.
 
262
     @return 
 
263
       - 0 If the result is NULL
 
264
       - The same pointer it was given, with the area initialized to the
 
265
         result of the operation.
 
266
  */
 
267
  virtual my_decimal *decimal_op(my_decimal *)= 0;
 
268
 
 
269
  /**
 
270
     @brief Performs the operation that this functions implements when the
 
271
     result type is a string type.
 
272
 
 
273
     @return The result of the operation.
 
274
  */
 
275
  virtual String *str_op(String *)= 0;
 
276
  bool is_null() { update_null_value(); return null_value; }
 
277
};
 
278
 
 
279
/* function where type of result detected by first argument */
 
280
class Item_func_num1: public Item_func_numhybrid
 
281
{
 
282
public:
 
283
  Item_func_num1(Item *a) :Item_func_numhybrid(a) {}
 
284
  Item_func_num1(Item *a, Item *b) :Item_func_numhybrid(a, b) {}
 
285
 
 
286
  void fix_num_length_and_dec();
 
287
  void find_num_type();
 
288
  String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
 
289
};
 
290
 
 
291
 
 
292
/* Base class for operations like '+', '-', '*' */
 
293
class Item_num_op :public Item_func_numhybrid
 
294
{
 
295
 public:
 
296
  Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {}
 
297
  virtual void result_precision()= 0;
 
298
 
 
299
  virtual inline void print(String *str, enum_query_type query_type)
 
300
  {
 
301
    print_op(str, query_type);
 
302
  }
 
303
 
 
304
  void find_num_type();
 
305
  String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
 
306
};
 
307
 
 
308
 
 
309
class Item_int_func :public Item_func
 
310
{
 
311
public:
 
312
  Item_int_func() :Item_func() { max_length= 21; }
 
313
  Item_int_func(Item *a) :Item_func(a) { max_length= 21; }
 
314
  Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; }
 
315
  Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c)
 
316
  { max_length= 21; }
 
317
  Item_int_func(List<Item> &list) :Item_func(list) { max_length= 21; }
 
318
  Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {}
 
319
  double val_real();
 
320
  String *val_str(String*str);
 
321
  enum Item_result result_type () const { return INT_RESULT; }
 
322
  void fix_length_and_dec() {}
 
323
};
 
324
 
 
325
 
 
326
class Item_func_connection_id :public Item_int_func
 
327
{
 
328
  longlong value;
 
329
 
 
330
public:
 
331
  Item_func_connection_id() {}
 
332
  const char *func_name() const { return "connection_id"; }
 
333
  void fix_length_and_dec();
 
334
  bool fix_fields(THD *thd, Item **ref);
 
335
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
 
336
};
 
337
 
 
338
 
 
339
class Item_func_signed :public Item_int_func
 
340
{
 
341
public:
 
342
  Item_func_signed(Item *a) :Item_int_func(a) {}
 
343
  const char *func_name() const { return "cast_as_signed"; }
 
344
  longlong val_int();
 
345
  longlong val_int_from_str(int *error);
 
346
  void fix_length_and_dec()
 
347
  { max_length=args[0]->max_length; unsigned_flag=0; }
 
348
  virtual void print(String *str, enum_query_type query_type);
 
349
  uint decimal_precision() const { return args[0]->decimal_precision(); }
 
350
};
 
351
 
 
352
 
 
353
class Item_func_unsigned :public Item_func_signed
 
354
{
 
355
public:
 
356
  Item_func_unsigned(Item *a) :Item_func_signed(a) {}
 
357
  const char *func_name() const { return "cast_as_unsigned"; }
 
358
  void fix_length_and_dec()
 
359
  { max_length=args[0]->max_length; unsigned_flag=1; }
 
360
  longlong val_int();
 
361
  virtual void print(String *str, enum_query_type query_type);
 
362
};
 
363
 
 
364
 
 
365
class Item_decimal_typecast :public Item_func
 
366
{
 
367
  my_decimal decimal_value;
 
368
public:
 
369
  Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a)
 
370
  {
 
371
    decimals= dec;
 
372
    max_length= my_decimal_precision_to_length(len, dec, unsigned_flag);
 
373
  }
 
374
  String *val_str(String *str);
 
375
  double val_real();
 
376
  longlong val_int();
 
377
  my_decimal *val_decimal(my_decimal*);
 
378
  enum Item_result result_type () const { return DECIMAL_RESULT; }
 
379
  enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
 
380
  void fix_length_and_dec() {};
 
381
  const char *func_name() const { return "decimal_typecast"; }
 
382
  virtual void print(String *str, enum_query_type query_type);
 
383
};
 
384
 
 
385
 
 
386
class Item_func_additive_op :public Item_num_op
 
387
{
 
388
public:
 
389
  Item_func_additive_op(Item *a,Item *b) :Item_num_op(a,b) {}
 
390
  void result_precision();
 
391
};
 
392
 
 
393
 
 
394
class Item_func_plus :public Item_func_additive_op
 
395
{
 
396
public:
 
397
  Item_func_plus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
 
398
  const char *func_name() const { return "+"; }
 
399
  longlong int_op();
 
400
  double real_op();
 
401
  my_decimal *decimal_op(my_decimal *);
 
402
};
 
403
 
 
404
class Item_func_minus :public Item_func_additive_op
 
405
{
 
406
public:
 
407
  Item_func_minus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
 
408
  const char *func_name() const { return "-"; }
 
409
  longlong int_op();
 
410
  double real_op();
 
411
  my_decimal *decimal_op(my_decimal *);
 
412
  void fix_length_and_dec();
 
413
};
 
414
 
 
415
 
 
416
class Item_func_mul :public Item_num_op
 
417
{
 
418
public:
 
419
  Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {}
 
420
  const char *func_name() const { return "*"; }
 
421
  longlong int_op();
 
422
  double real_op();
 
423
  my_decimal *decimal_op(my_decimal *);
 
424
  void result_precision();
 
425
};
 
426
 
 
427
 
 
428
class Item_func_div :public Item_num_op
 
429
{
 
430
public:
 
431
  uint prec_increment;
 
432
  Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {}
 
433
  longlong int_op() { DBUG_ASSERT(0); return 0; }
 
434
  double real_op();
 
435
  my_decimal *decimal_op(my_decimal *);
 
436
  const char *func_name() const { return "/"; }
 
437
  void fix_length_and_dec();
 
438
  void result_precision();
 
439
};
 
440
 
 
441
 
 
442
class Item_func_int_div :public Item_int_func
 
443
{
 
444
public:
 
445
  Item_func_int_div(Item *a,Item *b) :Item_int_func(a,b)
 
446
  {}
 
447
  longlong val_int();
 
448
  const char *func_name() const { return "DIV"; }
 
449
  void fix_length_and_dec();
 
450
 
 
451
  virtual inline void print(String *str, enum_query_type query_type)
 
452
  {
 
453
    print_op(str, query_type);
 
454
  }
 
455
 
 
456
};
 
457
 
 
458
 
 
459
class Item_func_mod :public Item_num_op
 
460
{
 
461
public:
 
462
  Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {}
 
463
  longlong int_op();
 
464
  double real_op();
 
465
  my_decimal *decimal_op(my_decimal *);
 
466
  const char *func_name() const { return "%"; }
 
467
  void result_precision();
 
468
  void fix_length_and_dec();
 
469
};
 
470
 
 
471
 
 
472
class Item_func_neg :public Item_func_num1
 
473
{
 
474
public:
 
475
  Item_func_neg(Item *a) :Item_func_num1(a) {}
 
476
  double real_op();
 
477
  longlong int_op();
 
478
  my_decimal *decimal_op(my_decimal *);
 
479
  const char *func_name() const { return "-"; }
 
480
  enum Functype functype() const   { return NEG_FUNC; }
 
481
  void fix_length_and_dec();
 
482
  void fix_num_length_and_dec();
 
483
  uint decimal_precision() const { return args[0]->decimal_precision(); }
 
484
};
 
485
 
 
486
 
 
487
class Item_func_abs :public Item_func_num1
 
488
{
 
489
public:
 
490
  Item_func_abs(Item *a) :Item_func_num1(a) {}
 
491
  double real_op();
 
492
  longlong int_op();
 
493
  my_decimal *decimal_op(my_decimal *);
 
494
  const char *func_name() const { return "abs"; }
 
495
  void fix_length_and_dec();
 
496
};
 
497
 
 
498
// A class to handle logarithmic and trigonometric functions
 
499
 
 
500
class Item_dec_func :public Item_real_func
 
501
{
 
502
 public:
 
503
  Item_dec_func(Item *a) :Item_real_func(a) {}
 
504
  Item_dec_func(Item *a,Item *b) :Item_real_func(a,b) {}
 
505
  void fix_length_and_dec()
 
506
  {
 
507
    decimals=NOT_FIXED_DEC; max_length=float_length(decimals);
 
508
    maybe_null=1;
 
509
  }
 
510
};
 
511
 
 
512
class Item_func_exp :public Item_dec_func
 
513
{
 
514
public:
 
515
  Item_func_exp(Item *a) :Item_dec_func(a) {}
 
516
  double val_real();
 
517
  const char *func_name() const { return "exp"; }
 
518
};
 
519
 
 
520
 
 
521
class Item_func_ln :public Item_dec_func
 
522
{
 
523
public:
 
524
  Item_func_ln(Item *a) :Item_dec_func(a) {}
 
525
  double val_real();
 
526
  const char *func_name() const { return "ln"; }
 
527
};
 
528
 
 
529
 
 
530
class Item_func_log :public Item_dec_func
 
531
{
 
532
public:
 
533
  Item_func_log(Item *a) :Item_dec_func(a) {}
 
534
  Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {}
 
535
  double val_real();
 
536
  const char *func_name() const { return "log"; }
 
537
};
 
538
 
 
539
 
 
540
class Item_func_log2 :public Item_dec_func
 
541
{
 
542
public:
 
543
  Item_func_log2(Item *a) :Item_dec_func(a) {}
 
544
  double val_real();
 
545
  const char *func_name() const { return "log2"; }
 
546
};
 
547
 
 
548
 
 
549
class Item_func_log10 :public Item_dec_func
 
550
{
 
551
public:
 
552
  Item_func_log10(Item *a) :Item_dec_func(a) {}
 
553
  double val_real();
 
554
  const char *func_name() const { return "log10"; }
 
555
};
 
556
 
 
557
 
 
558
class Item_func_sqrt :public Item_dec_func
 
559
{
 
560
public:
 
561
  Item_func_sqrt(Item *a) :Item_dec_func(a) {}
 
562
  double val_real();
 
563
  const char *func_name() const { return "sqrt"; }
 
564
};
 
565
 
 
566
 
 
567
class Item_func_pow :public Item_dec_func
 
568
{
 
569
public:
 
570
  Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {}
 
571
  double val_real();
 
572
  const char *func_name() const { return "pow"; }
 
573
};
 
574
 
 
575
 
 
576
class Item_func_acos :public Item_dec_func
 
577
{
 
578
public:
 
579
  Item_func_acos(Item *a) :Item_dec_func(a) {}
 
580
  double val_real();
 
581
  const char *func_name() const { return "acos"; }
 
582
};
 
583
 
 
584
class Item_func_asin :public Item_dec_func
 
585
{
 
586
public:
 
587
  Item_func_asin(Item *a) :Item_dec_func(a) {}
 
588
  double val_real();
 
589
  const char *func_name() const { return "asin"; }
 
590
};
 
591
 
 
592
class Item_func_atan :public Item_dec_func
 
593
{
 
594
public:
 
595
  Item_func_atan(Item *a) :Item_dec_func(a) {}
 
596
  Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {}
 
597
  double val_real();
 
598
  const char *func_name() const { return "atan"; }
 
599
};
 
600
 
 
601
class Item_func_cos :public Item_dec_func
 
602
{
 
603
public:
 
604
  Item_func_cos(Item *a) :Item_dec_func(a) {}
 
605
  double val_real();
 
606
  const char *func_name() const { return "cos"; }
 
607
};
 
608
 
 
609
class Item_func_sin :public Item_dec_func
 
610
{
 
611
public:
 
612
  Item_func_sin(Item *a) :Item_dec_func(a) {}
 
613
  double val_real();
 
614
  const char *func_name() const { return "sin"; }
 
615
};
 
616
 
 
617
class Item_func_tan :public Item_dec_func
 
618
{
 
619
public:
 
620
  Item_func_tan(Item *a) :Item_dec_func(a) {}
 
621
  double val_real();
 
622
  const char *func_name() const { return "tan"; }
 
623
};
72
624
 
73
625
class Item_func_integer :public Item_int_func
74
626
{
77
629
  void fix_length_and_dec();
78
630
};
79
631
 
 
632
 
 
633
class Item_func_int_val :public Item_func_num1
 
634
{
 
635
public:
 
636
  Item_func_int_val(Item *a) :Item_func_num1(a) {}
 
637
  void fix_num_length_and_dec();
 
638
  void find_num_type();
 
639
};
 
640
 
 
641
 
 
642
class Item_func_ceiling :public Item_func_int_val
 
643
{
 
644
public:
 
645
  Item_func_ceiling(Item *a) :Item_func_int_val(a) {}
 
646
  const char *func_name() const { return "ceiling"; }
 
647
  longlong int_op();
 
648
  double real_op();
 
649
  my_decimal *decimal_op(my_decimal *);
 
650
};
 
651
 
 
652
 
 
653
class Item_func_floor :public Item_func_int_val
 
654
{
 
655
public:
 
656
  Item_func_floor(Item *a) :Item_func_int_val(a) {}
 
657
  const char *func_name() const { return "floor"; }
 
658
  longlong int_op();
 
659
  double real_op();
 
660
  my_decimal *decimal_op(my_decimal *);
 
661
};
 
662
 
 
663
/* This handles round and truncate */
 
664
 
 
665
class Item_func_round :public Item_func_num1
 
666
{
 
667
  bool truncate;
 
668
public:
 
669
  Item_func_round(Item *a, Item *b, bool trunc_arg)
 
670
    :Item_func_num1(a,b), truncate(trunc_arg) {}
 
671
  const char *func_name() const { return truncate ? "truncate" : "round"; }
 
672
  double real_op();
 
673
  longlong int_op();
 
674
  my_decimal *decimal_op(my_decimal *);
 
675
  void fix_length_and_dec();
 
676
};
 
677
 
 
678
 
 
679
class Item_func_rand :public Item_real_func
 
680
{
 
681
  struct rand_struct *rand;
 
682
public:
 
683
  Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
 
684
  Item_func_rand()        :Item_real_func() {}
 
685
  double val_real();
 
686
  const char *func_name() const { return "rand"; }
 
687
  bool const_item() const { return 0; }
 
688
  void update_used_tables();
 
689
  bool fix_fields(THD *thd, Item **ref);
 
690
private:
 
691
  void seed_random (Item * val);  
 
692
};
 
693
 
 
694
 
 
695
class Item_func_sign :public Item_int_func
 
696
{
 
697
public:
 
698
  Item_func_sign(Item *a) :Item_int_func(a) {}
 
699
  const char *func_name() const { return "sign"; }
 
700
  longlong val_int();
 
701
};
 
702
 
 
703
 
80
704
class Item_func_units :public Item_real_func
81
705
{
82
706
  char *name;
91
715
};
92
716
 
93
717
 
 
718
class Item_func_min_max :public Item_func
 
719
{
 
720
  Item_result cmp_type;
 
721
  String tmp_value;
 
722
  int cmp_sign;
 
723
  /* TRUE <=> arguments should be compared in the DATETIME context. */
 
724
  bool compare_as_dates;
 
725
  /* An item used for issuing warnings while string to DATETIME conversion. */
 
726
  Item *datetime_item;
 
727
  THD *thd;
 
728
protected:
 
729
  enum_field_types cached_field_type;
 
730
public:
 
731
  Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
 
732
    cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(FALSE),
 
733
    datetime_item(0) {}
 
734
  double val_real();
 
735
  longlong val_int();
 
736
  String *val_str(String *);
 
737
  my_decimal *val_decimal(my_decimal *);
 
738
  void fix_length_and_dec();
 
739
  enum Item_result result_type () const { return cmp_type; }
 
740
  bool result_as_longlong() { return compare_as_dates; };
 
741
  uint cmp_datetimes(ulonglong *value);
 
742
  enum_field_types field_type() const { return cached_field_type; }
 
743
};
 
744
 
 
745
class Item_func_min :public Item_func_min_max
 
746
{
 
747
public:
 
748
  Item_func_min(List<Item> &list) :Item_func_min_max(list,1) {}
 
749
  const char *func_name() const { return "least"; }
 
750
};
 
751
 
 
752
class Item_func_max :public Item_func_min_max
 
753
{
 
754
public:
 
755
  Item_func_max(List<Item> &list) :Item_func_min_max(list,-1) {}
 
756
  const char *func_name() const { return "greatest"; }
 
757
};
 
758
 
 
759
 
94
760
/* 
95
761
  Objects of this class are used for ROLLUP queries to wrap up 
96
762
  each constant item referred to in GROUP BY list. 
105
771
    name_length= a->name_length;
106
772
  }
107
773
  double val_real() { return args[0]->val_real(); }
108
 
  int64_t val_int() { return args[0]->val_int(); }
 
774
  longlong val_int() { return args[0]->val_int(); }
109
775
  String *val_str(String *str) { return args[0]->val_str(str); }
110
776
  my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); }
111
777
  const char *func_name() const { return "rollup_const"; }
121
787
  }
122
788
};
123
789
 
 
790
 
 
791
class Item_func_length :public Item_int_func
 
792
{
 
793
  String value;
 
794
public:
 
795
  Item_func_length(Item *a) :Item_int_func(a) {}
 
796
  longlong val_int();
 
797
  const char *func_name() const { return "length"; }
 
798
  void fix_length_and_dec() { max_length=10; }
 
799
};
 
800
 
124
801
class Item_func_bit_length :public Item_func_length
125
802
{
126
803
public:
127
804
  Item_func_bit_length(Item *a) :Item_func_length(a) {}
128
 
  int64_t val_int()
129
 
    { assert(fixed == 1); return Item_func_length::val_int()*8; }
 
805
  longlong val_int()
 
806
    { DBUG_ASSERT(fixed == 1); return Item_func_length::val_int()*8; }
130
807
  const char *func_name() const { return "bit_length"; }
131
808
};
132
809
 
135
812
  String value;
136
813
public:
137
814
  Item_func_char_length(Item *a) :Item_int_func(a) {}
138
 
  int64_t val_int();
 
815
  longlong val_int();
139
816
  const char *func_name() const { return "char_length"; }
140
817
  void fix_length_and_dec() { max_length=10; }
141
818
};
144
821
{
145
822
public:
146
823
  Item_func_coercibility(Item *a) :Item_int_func(a) {}
147
 
  int64_t val_int();
 
824
  longlong val_int();
148
825
  const char *func_name() const { return "coercibility"; }
149
826
  void fix_length_and_dec() { max_length=10; maybe_null= 0; }
150
827
  table_map not_null_tables() const { return 0; }
158
835
  Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {}
159
836
  Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
160
837
  const char *func_name() const { return "locate"; }
161
 
  int64_t val_int();
 
838
  longlong val_int();
162
839
  void fix_length_and_dec();
163
840
  virtual void print(String *str, enum_query_type query_type);
164
841
};
171
848
  DTCollation cmp_collation;
172
849
public:
173
850
  Item_func_field(List<Item> &list) :Item_int_func(list) {}
174
 
  int64_t val_int();
 
851
  longlong val_int();
175
852
  const char *func_name() const { return "field"; }
176
853
  void fix_length_and_dec();
177
854
};
182
859
  String value;
183
860
public:
184
861
  Item_func_ascii(Item *a) :Item_int_func(a) {}
185
 
  int64_t val_int();
 
862
  longlong val_int();
186
863
  const char *func_name() const { return "ascii"; }
187
864
  void fix_length_and_dec() { max_length=3; }
188
865
};
192
869
  String value;
193
870
public:
194
871
  Item_func_ord(Item *a) :Item_int_func(a) {}
195
 
  int64_t val_int();
 
872
  longlong val_int();
196
873
  const char *func_name() const { return "ord"; }
197
874
};
198
875
 
199
876
class Item_func_find_in_set :public Item_int_func
200
877
{
201
878
  String value,value2;
202
 
  uint32_t enum_value;
203
 
  uint64_t enum_bit;
 
879
  uint enum_value;
 
880
  ulonglong enum_bit;
204
881
  DTCollation cmp_collation;
205
882
public:
206
883
  Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {}
207
 
  int64_t val_int();
 
884
  longlong val_int();
208
885
  const char *func_name() const { return "find_in_set"; }
209
886
  void fix_length_and_dec();
210
887
};
228
905
{
229
906
public:
230
907
  Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {}
231
 
  int64_t val_int();
 
908
  longlong val_int();
232
909
  const char *func_name() const { return "|"; }
233
910
};
234
911
 
236
913
{
237
914
public:
238
915
  Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {}
239
 
  int64_t val_int();
 
916
  longlong val_int();
240
917
  const char *func_name() const { return "&"; }
241
918
};
242
919
 
244
921
{
245
922
public:
246
923
  Item_func_bit_count(Item *a) :Item_int_func(a) {}
247
 
  int64_t val_int();
 
924
  longlong val_int();
248
925
  const char *func_name() const { return "bit_count"; }
249
926
  void fix_length_and_dec() { max_length=2; }
250
927
};
253
930
{
254
931
public:
255
932
  Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {}
256
 
  int64_t val_int();
 
933
  longlong val_int();
257
934
  const char *func_name() const { return "<<"; }
258
935
};
259
936
 
261
938
{
262
939
public:
263
940
  Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {}
264
 
  int64_t val_int();
 
941
  longlong val_int();
265
942
  const char *func_name() const { return ">>"; }
266
943
};
267
944
 
269
946
{
270
947
public:
271
948
  Item_func_bit_neg(Item *a) :Item_func_bit(a) {}
272
 
  int64_t val_int();
 
949
  longlong val_int();
273
950
  const char *func_name() const { return "~"; }
274
951
 
275
952
  virtual inline void print(String *str, enum_query_type query_type)
284
961
public:
285
962
  Item_func_last_insert_id() :Item_int_func() {}
286
963
  Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
287
 
  int64_t val_int();
 
964
  longlong val_int();
288
965
  const char *func_name() const { return "last_insert_id"; }
289
966
  void fix_length_and_dec()
290
967
  {
292
969
      max_length= args[0]->max_length;
293
970
  }
294
971
  bool fix_fields(THD *thd, Item **ref);
295
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
296
 
  { return true; }
297
972
};
298
973
 
299
974
 
303
978
  Item_func_benchmark(Item *count_expr, Item *expr)
304
979
    :Item_int_func(count_expr, expr)
305
980
  {}
306
 
  int64_t val_int();
 
981
  longlong val_int();
307
982
  const char *func_name() const { return "benchmark"; }
308
983
  void fix_length_and_dec() { max_length=1; maybe_null=0; }
309
984
  virtual void print(String *str, enum_query_type query_type);
310
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
311
 
  { return true; }
312
 
};
 
985
};
 
986
 
 
987
 
 
988
#ifdef HAVE_DLOPEN
 
989
 
 
990
class Item_udf_func :public Item_func
 
991
{
 
992
protected:
 
993
  udf_handler udf;
 
994
  bool is_expensive_processor(uchar *arg) { return TRUE; }
 
995
 
 
996
public:
 
997
  Item_udf_func(udf_func *udf_arg)
 
998
    :Item_func(), udf(udf_arg) {}
 
999
  Item_udf_func(udf_func *udf_arg, List<Item> &list)
 
1000
    :Item_func(list), udf(udf_arg) {}
 
1001
  const char *func_name() const { return udf.name(); }
 
1002
  enum Functype functype() const   { return UDF_FUNC; }
 
1003
  bool fix_fields(THD *thd, Item **ref)
 
1004
  {
 
1005
    DBUG_ASSERT(fixed == 0);
 
1006
    bool res= udf.fix_fields(thd, this, arg_count, args);
 
1007
    used_tables_cache= udf.used_tables_cache;
 
1008
    const_item_cache= udf.const_item_cache;
 
1009
    fixed= 1;
 
1010
    return res;
 
1011
  }
 
1012
  void update_used_tables() 
 
1013
  {
 
1014
    /*
 
1015
      TODO: Make a member in UDF_INIT and return if a UDF is deterministic or
 
1016
      not.
 
1017
      Currently UDF_INIT has a member (const_item) that is an in/out 
 
1018
      parameter to the init() call.
 
1019
      The code in udf_handler::fix_fields also duplicates the arguments 
 
1020
      handling code in Item_func::fix_fields().
 
1021
      
 
1022
      The lack of information if a UDF is deterministic makes writing
 
1023
      a correct update_used_tables() for UDFs impossible.
 
1024
      One solution to this would be :
 
1025
       - Add a is_deterministic member of UDF_INIT
 
1026
       - (optionally) deprecate the const_item member of UDF_INIT
 
1027
       - Take away the duplicate code from udf_handler::fix_fields() and
 
1028
         make Item_udf_func call Item_func::fix_fields() to process its 
 
1029
         arguments as for any other function.
 
1030
       - Store the deterministic flag returned by <udf>_init into the 
 
1031
       udf_handler. 
 
1032
       - Don't implement Item_udf_func::fix_fields, implement
 
1033
       Item_udf_func::fix_length_and_dec() instead (similar to non-UDF
 
1034
       functions).
 
1035
       - Override Item_func::update_used_tables to call 
 
1036
       Item_func::update_used_tables() and add a RAND_TABLE_BIT to the 
 
1037
       result of Item_func::update_used_tables() if the UDF is 
 
1038
       non-deterministic.
 
1039
       - (optionally) rename RAND_TABLE_BIT to NONDETERMINISTIC_BIT to
 
1040
       better describe its usage.
 
1041
       
 
1042
      The above would require a change of the UDF API.
 
1043
      Until that change is done here's how the current code works:
 
1044
      We call Item_func::update_used_tables() only when we know that
 
1045
      the function depends on real non-const tables and is deterministic.
 
1046
      This can be done only because we know that the optimizer will
 
1047
      call update_used_tables() only when there's possibly a new const
 
1048
      table. So update_used_tables() can only make a Item_func more
 
1049
      constant than it is currently.
 
1050
      That's why we don't need to do anything if a function is guaranteed
 
1051
      to return non-constant (it's non-deterministic) or is already a
 
1052
      const.
 
1053
    */  
 
1054
    if ((used_tables_cache & ~PSEUDO_TABLE_BITS) && 
 
1055
        !(used_tables_cache & RAND_TABLE_BIT))
 
1056
    {
 
1057
      Item_func::update_used_tables();
 
1058
      if (!const_item_cache && !used_tables_cache)
 
1059
        used_tables_cache= RAND_TABLE_BIT;
 
1060
    }
 
1061
  }
 
1062
  void cleanup();
 
1063
  Item_result result_type () const { return udf.result_type(); }
 
1064
  table_map not_null_tables() const { return 0; }
 
1065
  virtual void print(String *str, enum_query_type query_type);
 
1066
};
 
1067
 
 
1068
 
 
1069
class Item_func_udf_float :public Item_udf_func
 
1070
{
 
1071
 public:
 
1072
  Item_func_udf_float(udf_func *udf_arg)
 
1073
    :Item_udf_func(udf_arg) {}
 
1074
  Item_func_udf_float(udf_func *udf_arg,
 
1075
                      List<Item> &list)
 
1076
    :Item_udf_func(udf_arg, list) {}
 
1077
  longlong val_int()
 
1078
  {
 
1079
    DBUG_ASSERT(fixed == 1);
 
1080
    return (longlong) rint(Item_func_udf_float::val_real());
 
1081
  }
 
1082
  my_decimal *val_decimal(my_decimal *dec_buf)
 
1083
  {
 
1084
    double res=val_real();
 
1085
    if (null_value)
 
1086
      return NULL;
 
1087
    double2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf);
 
1088
    return dec_buf;
 
1089
  }
 
1090
  double val_real();
 
1091
  String *val_str(String *str);
 
1092
  void fix_length_and_dec() { fix_num_length_and_dec(); }
 
1093
};
 
1094
 
 
1095
 
 
1096
class Item_func_udf_int :public Item_udf_func
 
1097
{
 
1098
public:
 
1099
  Item_func_udf_int(udf_func *udf_arg)
 
1100
    :Item_udf_func(udf_arg) {}
 
1101
  Item_func_udf_int(udf_func *udf_arg,
 
1102
                    List<Item> &list)
 
1103
    :Item_udf_func(udf_arg, list) {}
 
1104
  longlong val_int();
 
1105
  double val_real() { return (double) Item_func_udf_int::val_int(); }
 
1106
  String *val_str(String *str);
 
1107
  enum Item_result result_type () const { return INT_RESULT; }
 
1108
  void fix_length_and_dec() { decimals= 0; max_length= 21; }
 
1109
};
 
1110
 
 
1111
 
 
1112
class Item_func_udf_decimal :public Item_udf_func
 
1113
{
 
1114
public:
 
1115
  Item_func_udf_decimal(udf_func *udf_arg)
 
1116
    :Item_udf_func(udf_arg) {}
 
1117
  Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list)
 
1118
    :Item_udf_func(udf_arg, list) {}
 
1119
  longlong val_int();
 
1120
  double val_real();
 
1121
  my_decimal *val_decimal(my_decimal *);
 
1122
  String *val_str(String *str);
 
1123
  enum Item_result result_type () const { return DECIMAL_RESULT; }
 
1124
  void fix_length_and_dec();
 
1125
};
 
1126
 
 
1127
 
 
1128
class Item_func_udf_str :public Item_udf_func
 
1129
{
 
1130
public:
 
1131
  Item_func_udf_str(udf_func *udf_arg)
 
1132
    :Item_udf_func(udf_arg) {}
 
1133
  Item_func_udf_str(udf_func *udf_arg, List<Item> &list)
 
1134
    :Item_udf_func(udf_arg, list) {}
 
1135
  String *val_str(String *);
 
1136
  double val_real()
 
1137
  {
 
1138
    int err_not_used;
 
1139
    char *end_not_used;
 
1140
    String *res;
 
1141
    res= val_str(&str_value);
 
1142
    return res ? my_strntod(res->charset(),(char*) res->ptr(), 
 
1143
                            res->length(), &end_not_used, &err_not_used) : 0.0;
 
1144
  }
 
1145
  longlong val_int()
 
1146
  {
 
1147
    int err_not_used;
 
1148
    String *res;  res=val_str(&str_value);
 
1149
    return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,
 
1150
                             (char**) 0, &err_not_used) : (longlong) 0;
 
1151
  }
 
1152
  my_decimal *val_decimal(my_decimal *dec_buf)
 
1153
  {
 
1154
    String *res=val_str(&str_value);
 
1155
    if (!res)
 
1156
      return NULL;
 
1157
    string2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf);
 
1158
    return dec_buf;
 
1159
  }
 
1160
  enum Item_result result_type () const { return STRING_RESULT; }
 
1161
  void fix_length_and_dec();
 
1162
};
 
1163
 
 
1164
#else /* Dummy functions to get sql_yacc.cc compiled */
 
1165
 
 
1166
class Item_func_udf_float :public Item_real_func
 
1167
{
 
1168
 public:
 
1169
  Item_func_udf_float(udf_func *udf_arg)
 
1170
    :Item_real_func() {}
 
1171
  Item_func_udf_float(udf_func *udf_arg, List<Item> &list)
 
1172
    :Item_real_func(list) {}
 
1173
  double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
 
1174
};
 
1175
 
 
1176
 
 
1177
class Item_func_udf_int :public Item_int_func
 
1178
{
 
1179
public:
 
1180
  Item_func_udf_int(udf_func *udf_arg)
 
1181
    :Item_int_func() {}
 
1182
  Item_func_udf_int(udf_func *udf_arg, List<Item> &list)
 
1183
    :Item_int_func(list) {}
 
1184
  longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; }
 
1185
};
 
1186
 
 
1187
 
 
1188
class Item_func_udf_decimal :public Item_int_func
 
1189
{
 
1190
public:
 
1191
  Item_func_udf_decimal(udf_func *udf_arg)
 
1192
    :Item_int_func() {}
 
1193
  Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list)
 
1194
    :Item_int_func(list) {}
 
1195
  my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; }
 
1196
};
 
1197
 
 
1198
 
 
1199
class Item_func_udf_str :public Item_func
 
1200
{
 
1201
public:
 
1202
  Item_func_udf_str(udf_func *udf_arg)
 
1203
    :Item_func() {}
 
1204
  Item_func_udf_str(udf_func *udf_arg, List<Item> &list)
 
1205
    :Item_func(list) {}
 
1206
  String *val_str(String *)
 
1207
    { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
 
1208
  double val_real() { DBUG_ASSERT(fixed == 1); null_value= 1; return 0.0; }
 
1209
  longlong val_int() { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
 
1210
  enum Item_result result_type () const { return STRING_RESULT; }
 
1211
  void fix_length_and_dec() { maybe_null=1; max_length=0; }
 
1212
};
 
1213
 
 
1214
#endif /* HAVE_DLOPEN */
313
1215
 
314
1216
/* replication functions */
315
1217
 
319
1221
public:
320
1222
  Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {}
321
1223
  Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
322
 
  int64_t val_int();
 
1224
  longlong val_int();
323
1225
  const char *func_name() const { return "master_pos_wait"; }
324
1226
  void fix_length_and_dec() { max_length=21; maybe_null=1;}
325
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
326
 
  { return true; }
327
1227
};
328
1228
 
329
1229
 
341
1241
  bool null_item;
342
1242
  union
343
1243
  {
344
 
    int64_t vint;
 
1244
    longlong vint;
345
1245
    double vreal;
346
1246
    String *vstr;
347
1247
    my_decimal *vdec;
354
1254
  {}
355
1255
  enum Functype functype() const { return SUSERVAR_FUNC; }
356
1256
  double val_real();
357
 
  int64_t val_int();
 
1257
  longlong val_int();
358
1258
  String *val_str(String *str);
359
1259
  my_decimal *val_decimal(my_decimal *);
360
1260
  double val_result();
361
 
  int64_t val_int_result();
 
1261
  longlong val_int_result();
362
1262
  String *str_result(String *str);
363
1263
  my_decimal *val_decimal_result(my_decimal *);
364
 
  bool update_hash(void *ptr, uint32_t length, enum Item_result type,
365
 
                   const CHARSET_INFO * const cs, Derivation dv, bool unsigned_arg);
 
1264
  bool update_hash(void *ptr, uint length, enum Item_result type,
 
1265
                   CHARSET_INFO *cs, Derivation dv, bool unsigned_arg);
366
1266
  bool send(Protocol *protocol, String *str_arg);
367
1267
  void make_field(Send_field *tmp_field);
368
1268
  bool check(bool use_result_field);
380
1280
    return save_in_field(field, no_conversions, 1);
381
1281
  }
382
1282
  void save_org_in_field(Field *field) { (void)save_in_field(field, 1, 0); }
383
 
  bool register_field_in_read_map(unsigned char *arg);
384
 
  bool register_field_in_bitmap(unsigned char *arg);
 
1283
  bool register_field_in_read_map(uchar *arg);
385
1284
};
386
1285
 
387
1286
 
397
1296
  enum Functype functype() const { return GUSERVAR_FUNC; }
398
1297
  LEX_STRING get_name() { return name; }
399
1298
  double val_real();
400
 
  int64_t val_int();
 
1299
  longlong val_int();
401
1300
  my_decimal *val_decimal(my_decimal*);
402
1301
  String *val_str(String* str);
403
1302
  void fix_length_and_dec();
433
1332
  /* We should return something different from FIELD_ITEM here */
434
1333
  enum Type type() const { return STRING_ITEM;}
435
1334
  double val_real();
436
 
  int64_t val_int();
 
1335
  longlong val_int();
437
1336
  String *val_str(String *str);
438
1337
  my_decimal *val_decimal(my_decimal *decimal_buffer);
439
1338
  /* fix_fields() binds variable name with its entry structure */
440
1339
  bool fix_fields(THD *thd, Item **ref);
441
1340
  virtual void print(String *str, enum_query_type query_type);
442
 
  void set_null_value(const CHARSET_INFO * const cs);
443
 
  void set_value(const char *str, uint32_t length, const CHARSET_INFO * const cs);
 
1341
  void set_null_value(CHARSET_INFO* cs);
 
1342
  void set_value(const char *str, uint length, CHARSET_INFO* cs);
444
1343
};
445
1344
 
446
1345
 
460
1359
    Stubs for pure virtual methods. Should never be called: this
461
1360
    item is always substituted with a constant in fix_fields().
462
1361
  */
463
 
  double val_real()         { assert(0); return 0.0; }
464
 
  int64_t val_int()        { assert(0); return 0; }
465
 
  String* val_str(String*)  { assert(0); return 0; }
466
 
  void fix_length_and_dec() { assert(0); }
 
1362
  double val_real()         { DBUG_ASSERT(0); return 0.0; }
 
1363
  longlong val_int()        { DBUG_ASSERT(0); return 0; }
 
1364
  String* val_str(String*)  { DBUG_ASSERT(0); return 0; }
 
1365
  void fix_length_and_dec() { DBUG_ASSERT(0); }
467
1366
  /* TODO: fix to support views */
468
1367
  const char *func_name() const { return "get_system_var"; }
469
1368
  /**
481
1380
{
482
1381
public:
483
1382
  Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {}
484
 
  int64_t val_int();
 
1383
  longlong val_int();
485
1384
  const char *func_name() const { return "^"; }
486
1385
};
487
1386
 
490
1389
  String value;
491
1390
public:
492
1391
  Item_func_is_free_lock(Item *a) :Item_int_func(a) {}
493
 
  int64_t val_int();
 
1392
  longlong val_int();
494
1393
  const char *func_name() const { return "is_free_lock"; }
495
1394
  void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;}
496
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
497
 
  { return true; }
498
1395
};
499
1396
 
500
1397
class Item_func_is_used_lock :public Item_int_func
502
1399
  String value;
503
1400
public:
504
1401
  Item_func_is_used_lock(Item *a) :Item_int_func(a) {}
505
 
  int64_t val_int();
 
1402
  longlong val_int();
506
1403
  const char *func_name() const { return "is_used_lock"; }
507
1404
  void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;}
508
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
509
 
  { return true; }
510
1405
};
511
1406
 
512
1407
/* For type casts */
523
1418
{
524
1419
public:
525
1420
  Item_func_row_count() :Item_int_func() {}
526
 
  int64_t val_int();
 
1421
  longlong val_int();
527
1422
  const char *func_name() const { return "row_count"; }
528
1423
  void fix_length_and_dec() { decimals= 0; maybe_null=0; }
529
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
530
 
  { return true; }
531
1424
};
532
1425
 
533
1426
 
543
1436
{
544
1437
public:
545
1438
  Item_func_found_rows() :Item_int_func() {}
546
 
  int64_t val_int();
 
1439
  longlong val_int();
547
1440
  const char *func_name() const { return "found_rows"; }
548
1441
  void fix_length_and_dec() { decimals= 0; maybe_null=0; }
549
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
550
 
  { return true; }
551
 
};
552
 
 
553
 
#endif /* DRIZZLE_SERVER_ITEM_FUNC_H */
 
1442
};
 
1443
 
 
1444
 
 
1445
void uuid_short_init();
 
1446
 
 
1447
class Item_func_uuid_short :public Item_int_func
 
1448
{
 
1449
public:
 
1450
  Item_func_uuid_short() :Item_int_func() {}
 
1451
  const char *func_name() const { return "uuid_short"; }
 
1452
  longlong val_int();
 
1453
  void fix_length_and_dec()
 
1454
  { max_length= 21; unsigned_flag=1; }
 
1455
};
 
1456