20
20
#ifndef DRIZZLED_SERVER_ITEM_FUNC_H
21
21
#define DRIZZLED_SERVER_ITEM_FUNC_H
23
/* Function items used by mysql */
25
#ifdef USE_PRAGMA_INTERFACE
26
#pragma interface /* gcc class implementation */
30
extern "C" /* Bug in BSDI include file */
36
class Item_func :public Item_result_field
39
Item **args, *tmp_arg[2];
41
Allowed numbers of columns in result (usually 1, which means scalar value)
42
0 means get this number from first argument
44
uint32_t allowed_arg_cols;
47
table_map used_tables_cache, not_null_tables_cache;
48
bool const_item_cache;
49
enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
51
LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
52
COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
53
BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
54
INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
55
NOT_FUNC, NOT_ALL_FUNC,
56
NOW_FUNC, TRIG_COND_FUNC,
57
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
58
EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP,
60
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
62
enum Type type() const { return FUNC_ITEM; }
63
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
65
allowed_arg_cols(1), arg_count(0)
70
allowed_arg_cols(1), arg_count(1)
74
with_sum_func= a->with_sum_func;
76
Item_func(Item *a,Item *b):
77
allowed_arg_cols(1), arg_count(2)
80
args[0]= a; args[1]= b;
81
with_sum_func= a->with_sum_func || b->with_sum_func;
83
Item_func(Item *a,Item *b,Item *c):
87
if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
90
args[0]= a; args[1]= b; args[2]= c;
91
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
94
Item_func(Item *a,Item *b,Item *c,Item *d):
98
if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
101
args[0]= a; args[1]= b; args[2]= c; args[3]= d;
102
with_sum_func= a->with_sum_func || b->with_sum_func ||
103
c->with_sum_func || d->with_sum_func;
106
Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
110
if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
112
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
113
with_sum_func= a->with_sum_func || b->with_sum_func ||
114
c->with_sum_func || d->with_sum_func || e->with_sum_func ;
117
Item_func(List<Item> &list);
118
// Constructor used for Item_cond_and/or (see Item comment)
119
Item_func(THD *thd, Item_func *item);
120
bool fix_fields(THD *, Item **ref);
121
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
122
table_map used_tables() const;
123
table_map not_null_tables() const;
124
void update_used_tables();
125
bool eq(const Item *item, bool binary_cmp) const;
126
virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
127
virtual bool have_rev_func() const { return 0; }
128
virtual Item *key_item() const { return args[0]; }
130
This method is used for debug purposes to print the name of an
131
item to the debug log. The second use of this method is as
132
a helper function of print(), where it is applicable.
133
To suit both goals it should return a meaningful,
134
distinguishable and sintactically correct string. This method
135
should not be used for runtime type identification, use enum
136
{Sum}Functype and Item_func::functype()/Item_sum::sum_func()
139
virtual const char *func_name() const { return NULL; };
140
virtual bool const_item() const { return const_item_cache; }
141
inline Item **arguments() const { return args; }
142
void set_arguments(List<Item> &list);
143
inline uint32_t argument_count() const { return arg_count; }
144
inline void remove_arguments() { arg_count=0; }
145
void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
146
virtual void print(String *str, enum_query_type query_type);
147
void print_op(String *str, enum_query_type query_type);
148
void print_args(String *str, uint32_t from, enum_query_type query_type);
149
virtual void fix_num_length_and_dec();
150
void count_only_length();
151
void count_real_length();
152
void count_decimal_length();
153
inline bool get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
155
return (null_value=args[0]->get_date(ltime, fuzzy_date));
157
inline bool get_arg0_time(DRIZZLE_TIME *ltime)
159
return (null_value=args[0]->get_time(ltime));
165
void signal_divide_by_null();
167
Field *tmp_table_field() { return result_field; }
168
Field *tmp_table_field(Table *t_arg);
169
Item *get_tmp_table_item(THD *thd);
171
my_decimal *val_decimal(my_decimal *);
173
bool agg_arg_collations(DTCollation &c, Item **items, uint32_t nitems,
176
return agg_item_collations(c, func_name(), items, nitems, flags, 1);
178
bool agg_arg_collations_for_comparison(DTCollation &c,
179
Item **items, uint32_t nitems,
182
return agg_item_collations_for_comparison(c, func_name(),
183
items, nitems, flags);
185
bool agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems,
186
uint32_t flags, int item_sep)
188
return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep);
190
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
191
Item *transform(Item_transformer transformer, unsigned char *arg);
192
Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
193
Item_transformer transformer, unsigned char *arg_t);
194
void traverse_cond(Cond_traverser traverser,
195
void * arg, traverse_order order);
196
inline double fix_result(double value)
206
class Item_real_func :public Item_func
209
Item_real_func() :Item_func() {}
210
Item_real_func(Item *a) :Item_func(a) {}
211
Item_real_func(Item *a,Item *b) :Item_func(a,b) {}
212
Item_real_func(List<Item> &list) :Item_func(list) {}
213
String *val_str(String*str);
214
my_decimal *val_decimal(my_decimal *decimal_value);
216
{ assert(fixed == 1); return (int64_t) rint(val_real()); }
217
enum Item_result result_type () const { return REAL_RESULT; }
218
void fix_length_and_dec()
219
{ decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
223
class Item_func_numhybrid: public Item_func
226
Item_result hybrid_type;
228
Item_func_numhybrid(Item *a) :Item_func(a), hybrid_type(REAL_RESULT)
230
Item_func_numhybrid(Item *a,Item *b)
231
:Item_func(a,b), hybrid_type(REAL_RESULT)
233
Item_func_numhybrid(List<Item> &list)
234
:Item_func(list), hybrid_type(REAL_RESULT)
237
enum Item_result result_type () const { return hybrid_type; }
238
void fix_length_and_dec();
239
void fix_num_length_and_dec();
240
virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */
244
my_decimal *val_decimal(my_decimal *);
245
String *val_str(String*str);
248
@brief Performs the operation that this functions implements when the
251
@return The result of the operation.
253
virtual int64_t int_op()= 0;
256
@brief Performs the operation that this functions implements when the
259
@return The result of the operation.
261
virtual double real_op()= 0;
264
@brief Performs the operation that this functions implements when the
265
result type is DECIMAL.
267
@param A pointer where the DECIMAL value will be allocated.
269
- 0 If the result is NULL
270
- The same pointer it was given, with the area initialized to the
271
result of the operation.
273
virtual my_decimal *decimal_op(my_decimal *)= 0;
276
@brief Performs the operation that this functions implements when the
277
result type is a string type.
279
@return The result of the operation.
281
virtual String *str_op(String *)= 0;
282
bool is_null() { update_null_value(); return null_value; }
285
/* function where type of result detected by first argument */
286
class Item_func_num1: public Item_func_numhybrid
289
Item_func_num1(Item *a) :Item_func_numhybrid(a) {}
290
Item_func_num1(Item *a, Item *b) :Item_func_numhybrid(a, b) {}
292
void fix_num_length_and_dec();
293
void find_num_type();
294
String *str_op(String *str __attribute__((unused)))
295
{ assert(0); return 0; }
299
/* Base class for operations like '+', '-', '*' */
300
class Item_num_op :public Item_func_numhybrid
303
Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {}
304
virtual void result_precision()= 0;
306
virtual inline void print(String *str, enum_query_type query_type)
308
print_op(str, query_type);
311
void find_num_type();
312
String *str_op(String *str __attribute__((unused)))
313
{ assert(0); return 0; }
317
class Item_int_func :public Item_func
320
Item_int_func() :Item_func() { max_length= 21; }
321
Item_int_func(Item *a) :Item_func(a) { max_length= 21; }
322
Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; }
323
Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c)
325
Item_int_func(List<Item> &list) :Item_func(list) { max_length= 21; }
326
Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {}
328
String *val_str(String*str);
329
enum Item_result result_type () const { return INT_RESULT; }
330
void fix_length_and_dec() {}
334
class Item_func_connection_id :public Item_int_func
339
Item_func_connection_id() {}
340
const char *func_name() const { return "connection_id"; }
341
void fix_length_and_dec();
342
bool fix_fields(THD *thd, Item **ref);
343
int64_t val_int() { assert(fixed == 1); return value; }
347
class Item_func_signed :public Item_int_func
350
Item_func_signed(Item *a) :Item_int_func(a) {}
351
const char *func_name() const { return "cast_as_signed"; }
353
int64_t val_int_from_str(int *error);
354
void fix_length_and_dec()
355
{ max_length=args[0]->max_length; unsigned_flag=0; }
356
virtual void print(String *str, enum_query_type query_type);
357
uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
361
class Item_func_unsigned :public Item_func_signed
364
Item_func_unsigned(Item *a) :Item_func_signed(a) {}
365
const char *func_name() const { return "cast_as_unsigned"; }
366
void fix_length_and_dec()
367
{ max_length=args[0]->max_length; unsigned_flag=1; }
369
virtual void print(String *str, enum_query_type query_type);
373
class Item_decimal_typecast :public Item_func
375
my_decimal decimal_value;
377
Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a)
380
max_length= my_decimal_precision_to_length(len, dec, unsigned_flag);
382
String *val_str(String *str);
385
my_decimal *val_decimal(my_decimal*);
386
enum Item_result result_type () const { return DECIMAL_RESULT; }
387
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
388
void fix_length_and_dec() {};
389
const char *func_name() const { return "decimal_typecast"; }
390
virtual void print(String *str, enum_query_type query_type);
394
class Item_func_additive_op :public Item_num_op
397
Item_func_additive_op(Item *a,Item *b) :Item_num_op(a,b) {}
398
void result_precision();
402
class Item_func_plus :public Item_func_additive_op
405
Item_func_plus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
406
const char *func_name() const { return "+"; }
409
my_decimal *decimal_op(my_decimal *);
412
class Item_func_minus :public Item_func_additive_op
415
Item_func_minus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
416
const char *func_name() const { return "-"; }
419
my_decimal *decimal_op(my_decimal *);
420
void fix_length_and_dec();
424
class Item_func_mul :public Item_num_op
427
Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {}
428
const char *func_name() const { return "*"; }
431
my_decimal *decimal_op(my_decimal *);
432
void result_precision();
436
class Item_func_div :public Item_num_op
439
uint32_t prec_increment;
440
Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {}
441
int64_t int_op() { assert(0); return 0; }
443
my_decimal *decimal_op(my_decimal *);
444
const char *func_name() const { return "/"; }
445
void fix_length_and_dec();
446
void result_precision();
450
class Item_func_int_div :public Item_int_func
453
Item_func_int_div(Item *a,Item *b) :Item_int_func(a,b)
456
const char *func_name() const { return "DIV"; }
457
void fix_length_and_dec();
459
virtual inline void print(String *str, enum_query_type query_type)
461
print_op(str, query_type);
467
class Item_func_mod :public Item_num_op
470
Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {}
473
my_decimal *decimal_op(my_decimal *);
474
const char *func_name() const { return "%"; }
475
void result_precision();
476
void fix_length_and_dec();
480
class Item_func_neg :public Item_func_num1
483
Item_func_neg(Item *a) :Item_func_num1(a) {}
486
my_decimal *decimal_op(my_decimal *);
487
const char *func_name() const { return "-"; }
488
enum Functype functype() const { return NEG_FUNC; }
489
void fix_length_and_dec();
490
void fix_num_length_and_dec();
491
uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
495
class Item_func_abs :public Item_func_num1
498
Item_func_abs(Item *a) :Item_func_num1(a) {}
501
my_decimal *decimal_op(my_decimal *);
502
const char *func_name() const { return "abs"; }
503
void fix_length_and_dec();
506
// A class to handle logarithmic and trigonometric functions
508
class Item_dec_func :public Item_real_func
511
Item_dec_func(Item *a) :Item_real_func(a) {}
512
Item_dec_func(Item *a,Item *b) :Item_real_func(a,b) {}
513
void fix_length_and_dec()
515
decimals=NOT_FIXED_DEC; max_length=float_length(decimals);
520
class Item_func_exp :public Item_dec_func
523
Item_func_exp(Item *a) :Item_dec_func(a) {}
525
const char *func_name() const { return "exp"; }
529
class Item_func_ln :public Item_dec_func
532
Item_func_ln(Item *a) :Item_dec_func(a) {}
534
const char *func_name() const { return "ln"; }
538
class Item_func_log :public Item_dec_func
541
Item_func_log(Item *a) :Item_dec_func(a) {}
542
Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {}
544
const char *func_name() const { return "log"; }
548
class Item_func_log2 :public Item_dec_func
551
Item_func_log2(Item *a) :Item_dec_func(a) {}
553
const char *func_name() const { return "log2"; }
557
class Item_func_log10 :public Item_dec_func
560
Item_func_log10(Item *a) :Item_dec_func(a) {}
562
const char *func_name() const { return "log10"; }
566
class Item_func_sqrt :public Item_dec_func
569
Item_func_sqrt(Item *a) :Item_dec_func(a) {}
571
const char *func_name() const { return "sqrt"; }
575
class Item_func_pow :public Item_dec_func
578
Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {}
580
const char *func_name() const { return "pow"; }
584
class Item_func_acos :public Item_dec_func
587
Item_func_acos(Item *a) :Item_dec_func(a) {}
589
const char *func_name() const { return "acos"; }
592
class Item_func_asin :public Item_dec_func
595
Item_func_asin(Item *a) :Item_dec_func(a) {}
597
const char *func_name() const { return "asin"; }
600
class Item_func_atan :public Item_dec_func
603
Item_func_atan(Item *a) :Item_dec_func(a) {}
604
Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {}
606
const char *func_name() const { return "atan"; }
609
class Item_func_cos :public Item_dec_func
612
Item_func_cos(Item *a) :Item_dec_func(a) {}
614
const char *func_name() const { return "cos"; }
617
class Item_func_sin :public Item_dec_func
620
Item_func_sin(Item *a) :Item_dec_func(a) {}
622
const char *func_name() const { return "sin"; }
625
class Item_func_tan :public Item_dec_func
628
Item_func_tan(Item *a) :Item_dec_func(a) {}
630
const char *func_name() const { return "tan"; }
633
class Item_func_integer :public Item_int_func
636
inline Item_func_integer(Item *a) :Item_int_func(a) {}
637
void fix_length_and_dec();
641
class Item_func_int_val :public Item_func_num1
644
Item_func_int_val(Item *a) :Item_func_num1(a) {}
645
void fix_num_length_and_dec();
646
void find_num_type();
650
class Item_func_ceiling :public Item_func_int_val
653
Item_func_ceiling(Item *a) :Item_func_int_val(a) {}
654
const char *func_name() const { return "ceiling"; }
657
my_decimal *decimal_op(my_decimal *);
661
class Item_func_floor :public Item_func_int_val
664
Item_func_floor(Item *a) :Item_func_int_val(a) {}
665
const char *func_name() const { return "floor"; }
668
my_decimal *decimal_op(my_decimal *);
671
/* This handles round and truncate */
673
class Item_func_round :public Item_func_num1
677
Item_func_round(Item *a, Item *b, bool trunc_arg)
678
:Item_func_num1(a,b), truncate(trunc_arg) {}
679
const char *func_name() const { return truncate ? "truncate" : "round"; }
682
my_decimal *decimal_op(my_decimal *);
683
void fix_length_and_dec();
687
class Item_func_rand :public Item_real_func
689
struct rand_struct *rand;
691
Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
692
Item_func_rand() :Item_real_func() {}
694
const char *func_name() const { return "rand"; }
695
bool const_item() const { return 0; }
696
void update_used_tables();
697
bool fix_fields(THD *thd, Item **ref);
699
void seed_random (Item * val);
703
class Item_func_sign :public Item_int_func
706
Item_func_sign(Item *a) :Item_int_func(a) {}
707
const char *func_name() const { return "sign"; }
712
class Item_func_units :public Item_real_func
717
Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg)
718
:Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {}
720
const char *func_name() const { return name; }
721
void fix_length_and_dec()
722
{ decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
726
class Item_func_min_max :public Item_func
728
Item_result cmp_type;
731
/* TRUE <=> arguments should be compared in the DATETIME context. */
732
bool compare_as_dates;
733
/* An item used for issuing warnings while string to DATETIME conversion. */
737
enum_field_types cached_field_type;
739
Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
740
cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(false),
744
String *val_str(String *);
745
my_decimal *val_decimal(my_decimal *);
746
void fix_length_and_dec();
747
enum Item_result result_type () const { return cmp_type; }
748
bool result_as_int64_t() { return compare_as_dates; };
749
uint32_t cmp_datetimes(uint64_t *value);
750
enum_field_types field_type() const { return cached_field_type; }
753
class Item_func_min :public Item_func_min_max
756
Item_func_min(List<Item> &list) :Item_func_min_max(list,1) {}
757
const char *func_name() const { return "least"; }
760
class Item_func_max :public Item_func_min_max
763
Item_func_max(List<Item> &list) :Item_func_min_max(list,-1) {}
764
const char *func_name() const { return "greatest"; }
769
Objects of this class are used for ROLLUP queries to wrap up
770
each constant item referred to in GROUP BY list.
773
class Item_func_rollup_const :public Item_func
776
Item_func_rollup_const(Item *a) :Item_func(a)
779
name_length= a->name_length;
781
double val_real() { return args[0]->val_real(); }
782
int64_t val_int() { return args[0]->val_int(); }
783
String *val_str(String *str) { return args[0]->val_str(str); }
784
my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); }
785
const char *func_name() const { return "rollup_const"; }
786
bool const_item() const { return 0; }
787
Item_result result_type() const { return args[0]->result_type(); }
788
void fix_length_and_dec()
790
collation= args[0]->collation;
791
max_length= args[0]->max_length;
792
decimals=args[0]->decimals;
793
/* The item could be a NULL constant. */
794
null_value= args[0]->is_null();
799
class Item_func_length :public Item_int_func
803
Item_func_length(Item *a) :Item_int_func(a) {}
805
const char *func_name() const { return "length"; }
806
void fix_length_and_dec() { max_length=10; }
809
class Item_func_bit_length :public Item_func_length
812
Item_func_bit_length(Item *a) :Item_func_length(a) {}
814
{ assert(fixed == 1); return Item_func_length::val_int()*8; }
815
const char *func_name() const { return "bit_length"; }
818
class Item_func_char_length :public Item_int_func
822
Item_func_char_length(Item *a) :Item_int_func(a) {}
824
const char *func_name() const { return "char_length"; }
825
void fix_length_and_dec() { max_length=10; }
828
class Item_func_coercibility :public Item_int_func
831
Item_func_coercibility(Item *a) :Item_int_func(a) {}
833
const char *func_name() const { return "coercibility"; }
834
void fix_length_and_dec() { max_length=10; maybe_null= 0; }
835
table_map not_null_tables() const { return 0; }
838
class Item_func_locate :public Item_int_func
840
String value1,value2;
841
DTCollation cmp_collation;
843
Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {}
844
Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
845
const char *func_name() const { return "locate"; }
847
void fix_length_and_dec();
848
virtual void print(String *str, enum_query_type query_type);
852
class Item_func_field :public Item_int_func
855
Item_result cmp_type;
856
DTCollation cmp_collation;
858
Item_func_field(List<Item> &list) :Item_int_func(list) {}
860
const char *func_name() const { return "field"; }
861
void fix_length_and_dec();
865
class Item_func_ascii :public Item_int_func
869
Item_func_ascii(Item *a) :Item_int_func(a) {}
871
const char *func_name() const { return "ascii"; }
872
void fix_length_and_dec() { max_length=3; }
875
class Item_func_ord :public Item_int_func
879
Item_func_ord(Item *a) :Item_int_func(a) {}
881
const char *func_name() const { return "ord"; }
884
class Item_func_find_in_set :public Item_int_func
889
DTCollation cmp_collation;
891
Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {}
893
const char *func_name() const { return "find_in_set"; }
894
void fix_length_and_dec();
897
/* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */
899
class Item_func_bit: public Item_int_func
902
Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {}
903
Item_func_bit(Item *a) :Item_int_func(a) {}
904
void fix_length_and_dec() { unsigned_flag= 1; }
906
virtual inline void print(String *str, enum_query_type query_type)
908
print_op(str, query_type);
912
class Item_func_bit_or :public Item_func_bit
915
Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {}
917
const char *func_name() const { return "|"; }
920
class Item_func_bit_and :public Item_func_bit
923
Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {}
925
const char *func_name() const { return "&"; }
928
class Item_func_bit_count :public Item_int_func
931
Item_func_bit_count(Item *a) :Item_int_func(a) {}
933
const char *func_name() const { return "bit_count"; }
934
void fix_length_and_dec() { max_length=2; }
937
class Item_func_shift_left :public Item_func_bit
940
Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {}
942
const char *func_name() const { return "<<"; }
945
class Item_func_shift_right :public Item_func_bit
948
Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {}
950
const char *func_name() const { return ">>"; }
953
class Item_func_bit_neg :public Item_func_bit
956
Item_func_bit_neg(Item *a) :Item_func_bit(a) {}
958
const char *func_name() const { return "~"; }
960
virtual inline void print(String *str, enum_query_type query_type)
962
Item_func::print(str, query_type);
967
class Item_func_last_insert_id :public Item_int_func
970
Item_func_last_insert_id() :Item_int_func() {}
971
Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
973
const char *func_name() const { return "last_insert_id"; }
974
void fix_length_and_dec()
977
max_length= args[0]->max_length;
979
bool fix_fields(THD *thd, Item **ref);
983
class Item_func_benchmark :public Item_int_func
986
Item_func_benchmark(Item *count_expr, Item *expr)
987
:Item_int_func(count_expr, expr)
990
const char *func_name() const { return "benchmark"; }
991
void fix_length_and_dec() { max_length=1; maybe_null=0; }
992
virtual void print(String *str, enum_query_type query_type);
995
/* replication functions */
997
class Item_master_pos_wait :public Item_int_func
1001
Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {}
1002
Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
1004
const char *func_name() const { return "master_pos_wait"; }
1005
void fix_length_and_dec() { max_length=21; maybe_null=1;}
1009
/* Handling of user definable variables */
1011
class user_var_entry;
1013
class Item_func_set_user_var :public Item_func
1015
enum Item_result cached_result_type;
1016
user_var_entry *entry;
1017
char buffer[MAX_FIELD_WIDTH];
1019
my_decimal decimal_buff;
1030
LEX_STRING name; // keep it public
1031
Item_func_set_user_var(LEX_STRING a,Item *b)
1032
:Item_func(b), cached_result_type(INT_RESULT), name(a)
1034
enum Functype functype() const { return SUSERVAR_FUNC; }
1037
String *val_str(String *str);
1038
my_decimal *val_decimal(my_decimal *);
1039
double val_result();
1040
int64_t val_int_result();
1041
String *str_result(String *str);
1042
my_decimal *val_decimal_result(my_decimal *);
1043
bool update_hash(void *ptr, uint32_t length, enum Item_result type,
1044
const CHARSET_INFO * const cs, Derivation dv, bool unsigned_arg);
1045
bool send(Protocol *protocol, String *str_arg);
1046
void make_field(Send_field *tmp_field);
1047
bool check(bool use_result_field);
1049
enum Item_result result_type () const { return cached_result_type; }
1050
bool fix_fields(THD *thd, Item **ref);
1051
void fix_length_and_dec();
1052
virtual void print(String *str, enum_query_type query_type);
1053
void print_as_stmt(String *str, enum_query_type query_type);
1054
const char *func_name() const { return "set_user_var"; }
1055
int save_in_field(Field *field, bool no_conversions,
1056
bool can_use_result_field);
1057
int save_in_field(Field *field, bool no_conversions)
1059
return save_in_field(field, no_conversions, 1);
1061
void save_org_in_field(Field *field) { (void)save_in_field(field, 1, 0); }
1062
bool register_field_in_read_map(unsigned char *arg);
1066
class Item_func_get_user_var :public Item_func
1068
user_var_entry *var_entry;
1069
Item_result m_cached_result_type;
1072
LEX_STRING name; // keep it public
1073
Item_func_get_user_var(LEX_STRING a):
1074
Item_func(), m_cached_result_type(STRING_RESULT), name(a) {}
1075
enum Functype functype() const { return GUSERVAR_FUNC; }
1076
LEX_STRING get_name() { return name; }
1079
my_decimal *val_decimal(my_decimal*);
1080
String *val_str(String* str);
1081
void fix_length_and_dec();
1082
virtual void print(String *str, enum_query_type query_type);
1083
enum Item_result result_type() const;
1085
We must always return variables as strings to guard against selects of type
1086
select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b)
1088
const char *func_name() const { return "get_user_var"; }
1089
bool const_item() const;
1090
table_map used_tables() const
1091
{ return const_item() ? 0 : RAND_TABLE_BIT; }
1092
bool eq(const Item *item, bool binary_cmp) const;
1097
This item represents user variable used as out parameter (e.g in LOAD DATA),
1098
and it is supposed to be used only for this purprose. So it is simplified
1099
a lot. Actually you should never obtain its value.
1101
The only two reasons for this thing being an Item is possibility to store it
1102
in List<Item> and desire to place this code somewhere near other functions
1103
working with user variables.
1105
class Item_user_var_as_out_param :public Item
1108
user_var_entry *entry;
1110
Item_user_var_as_out_param(LEX_STRING a) : name(a) {}
1111
/* We should return something different from FIELD_ITEM here */
1112
enum Type type() const { return STRING_ITEM;}
1115
String *val_str(String *str);
1116
my_decimal *val_decimal(my_decimal *decimal_buffer);
1117
/* fix_fields() binds variable name with its entry structure */
1118
bool fix_fields(THD *thd, Item **ref);
1119
virtual void print(String *str, enum_query_type query_type);
1120
void set_null_value(const CHARSET_INFO * const cs);
1121
void set_value(const char *str, uint32_t length, const CHARSET_INFO * const cs);
1125
/* A system variable */
1127
class Item_func_get_system_var :public Item_func
1130
enum_var_type var_type;
1131
LEX_STRING component;
1133
Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
1134
LEX_STRING *component_arg, const char *name_arg,
1135
size_t name_len_arg);
1136
bool fix_fields(THD *thd, Item **ref);
1138
Stubs for pure virtual methods. Should never be called: this
1139
item is always substituted with a constant in fix_fields().
1141
double val_real() { assert(0); return 0.0; }
1142
int64_t val_int() { assert(0); return 0; }
1143
String* val_str(String*) { assert(0); return 0; }
1144
void fix_length_and_dec() { assert(0); }
1145
/* TODO: fix to support views */
1146
const char *func_name() const { return "get_system_var"; }
1148
Indicates whether this system variable is written to the binlog or not.
1150
Variables are written to the binlog as part of "status_vars" in
1151
Query_log_event, as an Intvar_log_event, or a Rand_log_event.
1153
@return true if the variable is written to the binlog, false otherwise.
1155
bool is_written_to_binlog();
1158
class Item_func_bit_xor : public Item_func_bit
1161
Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {}
1163
const char *func_name() const { return "^"; }
1166
class Item_func_is_free_lock :public Item_int_func
1170
Item_func_is_free_lock(Item *a) :Item_int_func(a) {}
1172
const char *func_name() const { return "is_free_lock"; }
1173
void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;}
1176
class Item_func_is_used_lock :public Item_int_func
1180
Item_func_is_used_lock(Item *a) :Item_int_func(a) {}
1182
const char *func_name() const { return "is_used_lock"; }
1183
void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;}
24
/* If you fix the parser to no longer create functions these can be moved to create.cc */
25
#include <drizzled/function/math/divide.h>
26
#include <drizzled/function/get_user_var.h>
27
#include <drizzled/function/math/int.h>
28
#include <drizzled/function/math/int_divide.h>
29
#include <drizzled/function/math/minus.h>
30
#include <drizzled/function/math/mod.h>
31
#include <drizzled/function/math/multiply.h>
32
#include <drizzled/function/math/neg.h>
33
#include <drizzled/function/math/plus.h>
34
#include <drizzled/function/rollup_const.h>
35
#include <drizzled/function/math/round.h>
36
#include <drizzled/function/user_var_as_out_param.h>
1186
38
/* For type casts */