~drizzle-trunk/drizzle/development

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