My Project
|
00001 #ifndef ITEM_FUNC_INCLUDED 00002 #define ITEM_FUNC_INCLUDED 00003 00004 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; version 2 of the License. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00018 00019 00020 /* Function items used by mysql */ 00021 00022 #ifdef HAVE_IEEEFP_H 00023 extern "C" /* Bug in BSDI include file */ 00024 { 00025 #include <ieeefp.h> 00026 } 00027 #endif 00028 00029 class Item_func :public Item_result_field 00030 { 00031 protected: 00032 Item **args, *tmp_arg[2]; 00034 bool const_item_cache; 00035 /* 00036 Allowed numbers of columns in result (usually 1, which means scalar value) 00037 0 means get this number from first argument 00038 */ 00039 uint allowed_arg_cols; 00041 table_map used_tables_cache; 00043 table_map not_null_tables_cache; 00044 public: 00045 uint arg_count; 00046 //bool const_item_cache; 00047 enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC, 00048 GE_FUNC,GT_FUNC,FT_FUNC, 00049 LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC, 00050 COND_AND_FUNC, COND_OR_FUNC, XOR_FUNC, 00051 BETWEEN, IN_FUNC, MULT_EQUAL_FUNC, 00052 INTERVAL_FUNC, ISNOTNULLTEST_FUNC, 00053 SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC, 00054 SP_TOUCHES_FUNC,SP_CROSSES_FUNC,SP_WITHIN_FUNC, 00055 SP_CONTAINS_FUNC,SP_OVERLAPS_FUNC, 00056 SP_STARTPOINT,SP_ENDPOINT,SP_EXTERIORRING, 00057 SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN, 00058 NOT_FUNC, NOT_ALL_FUNC, 00059 NOW_FUNC, TRIG_COND_FUNC, 00060 SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC, 00061 EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC, 00062 NEG_FUNC, GSYSVAR_FUNC }; 00063 enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL, 00064 OPTIMIZE_EQUAL }; 00065 enum Type type() const { return FUNC_ITEM; } 00066 virtual enum Functype functype() const { return UNKNOWN_FUNC; } 00067 Item_func(void): 00068 allowed_arg_cols(1), arg_count(0) 00069 { 00070 with_sum_func= 0; 00071 } 00072 Item_func(Item *a): 00073 allowed_arg_cols(1), arg_count(1) 00074 { 00075 args= tmp_arg; 00076 args[0]= a; 00077 with_sum_func= a->with_sum_func; 00078 } 00079 Item_func(Item *a,Item *b): 00080 allowed_arg_cols(1), arg_count(2) 00081 { 00082 args= tmp_arg; 00083 args[0]= a; args[1]= b; 00084 with_sum_func= a->with_sum_func || b->with_sum_func; 00085 } 00086 Item_func(Item *a,Item *b,Item *c): 00087 allowed_arg_cols(1) 00088 { 00089 arg_count= 0; 00090 if ((args= (Item**) sql_alloc(sizeof(Item*)*3))) 00091 { 00092 arg_count= 3; 00093 args[0]= a; args[1]= b; args[2]= c; 00094 with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func; 00095 } 00096 } 00097 Item_func(Item *a,Item *b,Item *c,Item *d): 00098 allowed_arg_cols(1) 00099 { 00100 arg_count= 0; 00101 if ((args= (Item**) sql_alloc(sizeof(Item*)*4))) 00102 { 00103 arg_count= 4; 00104 args[0]= a; args[1]= b; args[2]= c; args[3]= d; 00105 with_sum_func= a->with_sum_func || b->with_sum_func || 00106 c->with_sum_func || d->with_sum_func; 00107 } 00108 } 00109 Item_func(Item *a,Item *b,Item *c,Item *d,Item* e): 00110 allowed_arg_cols(1) 00111 { 00112 arg_count= 5; 00113 if ((args= (Item**) sql_alloc(sizeof(Item*)*5))) 00114 { 00115 args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e; 00116 with_sum_func= a->with_sum_func || b->with_sum_func || 00117 c->with_sum_func || d->with_sum_func || e->with_sum_func ; 00118 } 00119 } 00120 Item_func(List<Item> &list); 00121 // Constructor used for Item_cond_and/or (see Item comment) 00122 Item_func(THD *thd, Item_func *item); 00123 bool fix_fields(THD *, Item **ref); 00124 void fix_after_pullout(st_select_lex *parent_select, 00125 st_select_lex *removed_select); 00126 table_map used_tables() const; 00132 virtual table_map get_initial_pseudo_tables() const { return 0; } 00133 table_map not_null_tables() const; 00134 void update_used_tables(); 00135 void set_used_tables(table_map map) { used_tables_cache= map; } 00136 void set_not_null_tables(table_map map) { not_null_tables_cache= map; } 00137 bool eq(const Item *item, bool binary_cmp) const; 00138 virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; } 00139 virtual bool have_rev_func() const { return 0; } 00140 virtual Item *key_item() const { return args[0]; } 00141 virtual bool const_item() const { return const_item_cache; } 00142 inline Item **arguments() const 00143 { DBUG_ASSERT(argument_count() > 0); return args; } 00144 void set_arguments(List<Item> &list); 00145 inline uint argument_count() const { return arg_count; } 00146 inline void remove_arguments() { arg_count=0; } 00147 void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, 00148 List<Item> &fields); 00149 virtual void print(String *str, enum_query_type query_type); 00150 void print_op(String *str, enum_query_type query_type); 00151 void print_args(String *str, uint from, enum_query_type query_type); 00152 virtual void fix_num_length_and_dec(); 00153 void count_only_length(Item **item, uint nitems); 00154 void count_real_length(); 00155 void count_decimal_length(); 00156 void count_datetime_length(Item **item, uint nitems); 00157 bool count_string_result_length(enum_field_types field_type, 00158 Item **item, uint nitems); 00159 inline bool get_arg0_date(MYSQL_TIME *ltime, uint fuzzy_date) 00160 { 00161 return (null_value=args[0]->get_date(ltime, fuzzy_date)); 00162 } 00163 inline bool get_arg0_time(MYSQL_TIME *ltime) 00164 { 00165 return (null_value= args[0]->get_time(ltime)); 00166 } 00167 bool is_null() { 00168 update_null_value(); 00169 return null_value; 00170 } 00171 void signal_divide_by_null(); 00172 friend class udf_handler; 00173 Field *tmp_table_field() { return result_field; } 00174 Field *tmp_table_field(TABLE *t_arg); 00175 Item *get_tmp_table_item(THD *thd); 00176 00177 my_decimal *val_decimal(my_decimal *); 00178 00179 bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems, 00180 uint flags, int item_sep) 00181 { 00182 return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep); 00183 } 00184 /* 00185 Aggregate arguments for string result, e.g: CONCAT(a,b) 00186 - convert to @@character_set_connection if all arguments are numbers 00187 - allow DERIVATION_NONE 00188 */ 00189 bool agg_arg_charsets_for_string_result(DTCollation &c, 00190 Item **items, uint nitems, 00191 int item_sep= 1) 00192 { 00193 return agg_item_charsets_for_string_result(c, func_name(), 00194 items, nitems, item_sep); 00195 } 00196 /* 00197 Aggregate arguments for comparison, e.g: a=b, a LIKE b, a RLIKE b 00198 - don't convert to @@character_set_connection if all arguments are numbers 00199 - don't allow DERIVATION_NONE 00200 */ 00201 bool agg_arg_charsets_for_comparison(DTCollation &c, 00202 Item **items, uint nitems, 00203 int item_sep= 1) 00204 { 00205 return agg_item_charsets_for_comparison(c, func_name(), 00206 items, nitems, item_sep); 00207 } 00208 /* 00209 Aggregate arguments for string result, when some comparison 00210 is involved internally, e.g: REPLACE(a,b,c) 00211 - convert to @@character_set_connection if all arguments are numbers 00212 - disallow DERIVATION_NONE 00213 */ 00214 bool agg_arg_charsets_for_string_result_with_comparison(DTCollation &c, 00215 Item **items, 00216 uint nitems, 00217 int item_sep= 1) 00218 { 00219 return agg_item_charsets_for_string_result_with_comparison(c, func_name(), 00220 items, nitems, 00221 item_sep); 00222 } 00223 bool walk(Item_processor processor, bool walk_subquery, uchar *arg); 00224 Item *transform(Item_transformer transformer, uchar *arg); 00225 Item* compile(Item_analyzer analyzer, uchar **arg_p, 00226 Item_transformer transformer, uchar *arg_t); 00227 void traverse_cond(Cond_traverser traverser, 00228 void * arg, traverse_order order); 00229 inline double fix_result(double value) 00230 { 00231 if (my_isfinite(value)) 00232 return value; 00233 null_value=1; 00234 return 0.0; 00235 } 00236 inline void raise_numeric_overflow(const char *type_name) 00237 { 00238 char buf[256]; 00239 String str(buf, sizeof(buf), system_charset_info); 00240 str.length(0); 00241 print(&str, QT_ORDINARY); 00242 my_error(ER_DATA_OUT_OF_RANGE, MYF(0), type_name, str.c_ptr_safe()); 00243 } 00244 inline double raise_float_overflow() 00245 { 00246 raise_numeric_overflow("DOUBLE"); 00247 return 0.0; 00248 } 00249 inline longlong raise_integer_overflow() 00250 { 00251 raise_numeric_overflow(unsigned_flag ? "BIGINT UNSIGNED": "BIGINT"); 00252 return 0; 00253 } 00254 inline int raise_decimal_overflow() 00255 { 00256 raise_numeric_overflow("DECIMAL"); 00257 return E_DEC_OVERFLOW; 00258 } 00263 inline double check_float_overflow(double value) 00264 { 00265 return my_isfinite(value) ? value : raise_float_overflow(); 00266 } 00272 inline longlong check_integer_overflow(longlong value, bool val_unsigned) 00273 { 00274 if ((unsigned_flag && !val_unsigned && value < 0) || 00275 (!unsigned_flag && val_unsigned && 00276 (ulonglong) value > (ulonglong) LONGLONG_MAX)) 00277 return raise_integer_overflow(); 00278 return value; 00279 } 00283 inline int check_decimal_overflow(int error) 00284 { 00285 return (error == E_DEC_OVERFLOW) ? raise_decimal_overflow() : error; 00286 } 00287 00288 bool has_timestamp_args() 00289 { 00290 DBUG_ASSERT(fixed == TRUE); 00291 for (uint i= 0; i < arg_count; i++) 00292 { 00293 if (args[i]->type() == Item::FIELD_ITEM && 00294 args[i]->field_type() == MYSQL_TYPE_TIMESTAMP) 00295 return TRUE; 00296 } 00297 return FALSE; 00298 } 00299 00300 bool has_date_args() 00301 { 00302 DBUG_ASSERT(fixed == TRUE); 00303 for (uint i= 0; i < arg_count; i++) 00304 { 00305 if (args[i]->type() == Item::FIELD_ITEM && 00306 (args[i]->field_type() == MYSQL_TYPE_DATE || 00307 args[i]->field_type() == MYSQL_TYPE_DATETIME)) 00308 return TRUE; 00309 } 00310 return FALSE; 00311 } 00312 00313 bool has_time_args() 00314 { 00315 DBUG_ASSERT(fixed == TRUE); 00316 for (uint i= 0; i < arg_count; i++) 00317 { 00318 if (args[i]->type() == Item::FIELD_ITEM && 00319 (args[i]->field_type() == MYSQL_TYPE_TIME || 00320 args[i]->field_type() == MYSQL_TYPE_DATETIME)) 00321 return TRUE; 00322 } 00323 return FALSE; 00324 } 00325 00326 bool has_datetime_args() 00327 { 00328 DBUG_ASSERT(fixed == TRUE); 00329 for (uint i= 0; i < arg_count; i++) 00330 { 00331 if (args[i]->type() == Item::FIELD_ITEM && 00332 args[i]->field_type() == MYSQL_TYPE_DATETIME) 00333 return TRUE; 00334 } 00335 return FALSE; 00336 } 00337 00338 /* 00339 We assume the result of any function that has a TIMESTAMP argument to be 00340 timezone-dependent, since a TIMESTAMP value in both numeric and string 00341 contexts is interpreted according to the current timezone. 00342 The only exception is UNIX_TIMESTAMP() which returns the internal 00343 representation of a TIMESTAMP argument verbatim, and thus does not depend on 00344 the timezone. 00345 */ 00346 virtual bool check_valid_arguments_processor(uchar *bool_arg) 00347 { 00348 return has_timestamp_args(); 00349 } 00350 00351 virtual bool find_function_processor (uchar *arg) 00352 { 00353 return functype() == *(Functype *) arg; 00354 } 00355 }; 00356 00357 00358 class Item_real_func :public Item_func 00359 { 00360 public: 00361 Item_real_func() :Item_func() { collation.set_numeric(); } 00362 Item_real_func(Item *a) :Item_func(a) { collation.set_numeric(); } 00363 Item_real_func(Item *a,Item *b) :Item_func(a,b) { collation.set_numeric(); } 00364 Item_real_func(List<Item> &list) :Item_func(list) { collation.set_numeric(); } 00365 String *val_str(String*str); 00366 my_decimal *val_decimal(my_decimal *decimal_value); 00367 longlong val_int() 00368 { DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); } 00369 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00370 { 00371 return get_date_from_real(ltime, fuzzydate); 00372 } 00373 bool get_time(MYSQL_TIME *ltime) 00374 { 00375 return get_time_from_real(ltime); 00376 } 00377 enum Item_result result_type () const { return REAL_RESULT; } 00378 void fix_length_and_dec() 00379 { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); } 00380 }; 00381 00382 00383 class Item_func_numhybrid: public Item_func 00384 { 00385 protected: 00386 Item_result hybrid_type; 00387 public: 00388 Item_func_numhybrid(Item *a) :Item_func(a), hybrid_type(REAL_RESULT) 00389 { collation.set_numeric(); } 00390 Item_func_numhybrid(Item *a,Item *b) 00391 :Item_func(a,b), hybrid_type(REAL_RESULT) 00392 { collation.set_numeric(); } 00393 Item_func_numhybrid(List<Item> &list) 00394 :Item_func(list), hybrid_type(REAL_RESULT) 00395 { collation.set_numeric(); } 00396 00397 enum Item_result result_type () const { return hybrid_type; } 00398 void fix_length_and_dec(); 00399 void fix_num_length_and_dec(); 00400 virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */ 00401 00402 double val_real(); 00403 longlong val_int(); 00404 my_decimal *val_decimal(my_decimal *); 00405 String *val_str(String*str); 00406 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 00407 bool get_time(MYSQL_TIME *ltime); 00414 virtual longlong int_op()= 0; 00415 00422 virtual double real_op()= 0; 00423 00434 virtual my_decimal *decimal_op(my_decimal *)= 0; 00435 00442 virtual String *str_op(String *)= 0; 00449 virtual bool date_op(MYSQL_TIME *ltime, uint fuzzydate)= 0; 00450 virtual bool time_op(MYSQL_TIME *ltime)= 0; 00451 bool is_null() { update_null_value(); return null_value; } 00452 }; 00453 00454 /* function where type of result detected by first argument */ 00455 class Item_func_num1: public Item_func_numhybrid 00456 { 00457 public: 00458 Item_func_num1(Item *a) :Item_func_numhybrid(a) {} 00459 Item_func_num1(Item *a, Item *b) :Item_func_numhybrid(a, b) {} 00460 00461 void fix_num_length_and_dec(); 00462 void find_num_type(); 00463 String *str_op(String *str) { DBUG_ASSERT(0); return 0; } 00464 bool date_op(MYSQL_TIME *ltime, uint fuzzydate) 00465 { DBUG_ASSERT(0); return 0; } 00466 bool time_op(MYSQL_TIME *ltime) 00467 { DBUG_ASSERT(0); return 0; } 00468 }; 00469 00470 00471 /* Base class for operations like '+', '-', '*' */ 00472 class Item_num_op :public Item_func_numhybrid 00473 { 00474 public: 00475 Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {} 00476 virtual void result_precision()= 0; 00477 00478 virtual inline void print(String *str, enum_query_type query_type) 00479 { 00480 print_op(str, query_type); 00481 } 00482 00483 void find_num_type(); 00484 String *str_op(String *str) { DBUG_ASSERT(0); return 0; } 00485 bool date_op(MYSQL_TIME *ltime, uint fuzzydate) 00486 { DBUG_ASSERT(0); return 0; } 00487 bool time_op(MYSQL_TIME *ltime) 00488 { DBUG_ASSERT(0); return 0; } 00489 }; 00490 00491 00492 class Item_int_func :public Item_func 00493 { 00494 public: 00495 Item_int_func() :Item_func() 00496 { collation.set_numeric(); fix_char_length(21); } 00497 Item_int_func(Item *a) :Item_func(a) 00498 { collation.set_numeric(); fix_char_length(21); } 00499 Item_int_func(Item *a,Item *b) :Item_func(a,b) 00500 { collation.set_numeric(); fix_char_length(21); } 00501 Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) 00502 { collation.set_numeric(); fix_char_length(21); } 00503 Item_int_func(List<Item> &list) :Item_func(list) 00504 { collation.set_numeric(); fix_char_length(21); } 00505 Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) 00506 { collation.set_numeric(); } 00507 double val_real(); 00508 String *val_str(String*str); 00509 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00510 { 00511 return get_date_from_int(ltime, fuzzydate); 00512 } 00513 bool get_time(MYSQL_TIME *ltime) 00514 { 00515 return get_time_from_int(ltime); 00516 } 00517 enum Item_result result_type () const { return INT_RESULT; } 00518 void fix_length_and_dec() {} 00519 }; 00520 00521 00522 class Item_func_connection_id :public Item_int_func 00523 { 00524 longlong value; 00525 00526 public: 00527 Item_func_connection_id() {} 00528 const char *func_name() const { return "connection_id"; } 00529 void fix_length_and_dec(); 00530 bool fix_fields(THD *thd, Item **ref); 00531 longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } 00532 }; 00533 00534 00535 class Item_func_signed :public Item_int_func 00536 { 00537 public: 00538 Item_func_signed(Item *a) :Item_int_func(a) 00539 { 00540 unsigned_flag= 0; 00541 } 00542 const char *func_name() const { return "cast_as_signed"; } 00543 longlong val_int(); 00544 longlong val_int_from_str(int *error); 00545 void fix_length_and_dec() 00546 { 00547 fix_char_length(std::min<uint32>(args[0]->max_char_length(), 00548 MY_INT64_NUM_DECIMAL_DIGITS)); 00549 } 00550 virtual void print(String *str, enum_query_type query_type); 00551 uint decimal_precision() const { return args[0]->decimal_precision(); } 00552 }; 00553 00554 00555 class Item_func_unsigned :public Item_func_signed 00556 { 00557 public: 00558 Item_func_unsigned(Item *a) :Item_func_signed(a) 00559 { 00560 unsigned_flag= 1; 00561 } 00562 const char *func_name() const { return "cast_as_unsigned"; } 00563 longlong val_int(); 00564 virtual void print(String *str, enum_query_type query_type); 00565 }; 00566 00567 00568 class Item_decimal_typecast :public Item_func 00569 { 00570 my_decimal decimal_value; 00571 public: 00572 Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a) 00573 { 00574 decimals= dec; 00575 collation.set_numeric(); 00576 fix_char_length(my_decimal_precision_to_length_no_truncation(len, dec, 00577 unsigned_flag)); 00578 } 00579 String *val_str(String *str); 00580 double val_real(); 00581 longlong val_int(); 00582 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00583 { 00584 return get_date_from_decimal(ltime, fuzzydate); 00585 } 00586 bool get_time(MYSQL_TIME *ltime) 00587 { 00588 return get_time_from_decimal(ltime); 00589 } 00590 my_decimal *val_decimal(my_decimal*); 00591 enum Item_result result_type () const { return DECIMAL_RESULT; } 00592 enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } 00593 void fix_length_and_dec() {}; 00594 const char *func_name() const { return "decimal_typecast"; } 00595 virtual void print(String *str, enum_query_type query_type); 00596 }; 00597 00598 00599 class Item_func_additive_op :public Item_num_op 00600 { 00601 public: 00602 Item_func_additive_op(Item *a,Item *b) :Item_num_op(a,b) {} 00603 void result_precision(); 00604 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00605 }; 00606 00607 00608 class Item_func_plus :public Item_func_additive_op 00609 { 00610 public: 00611 Item_func_plus(Item *a,Item *b) :Item_func_additive_op(a,b) {} 00612 const char *func_name() const { return "+"; } 00613 longlong int_op(); 00614 double real_op(); 00615 my_decimal *decimal_op(my_decimal *); 00616 }; 00617 00618 class Item_func_minus :public Item_func_additive_op 00619 { 00620 public: 00621 Item_func_minus(Item *a,Item *b) :Item_func_additive_op(a,b) {} 00622 const char *func_name() const { return "-"; } 00623 longlong int_op(); 00624 double real_op(); 00625 my_decimal *decimal_op(my_decimal *); 00626 void fix_length_and_dec(); 00627 }; 00628 00629 00630 class Item_func_mul :public Item_num_op 00631 { 00632 public: 00633 Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {} 00634 const char *func_name() const { return "*"; } 00635 longlong int_op(); 00636 double real_op(); 00637 my_decimal *decimal_op(my_decimal *); 00638 void result_precision(); 00639 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00640 }; 00641 00642 00643 class Item_func_div :public Item_num_op 00644 { 00645 public: 00646 uint prec_increment; 00647 Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {} 00648 longlong int_op() { DBUG_ASSERT(0); return 0; } 00649 double real_op(); 00650 my_decimal *decimal_op(my_decimal *); 00651 const char *func_name() const { return "/"; } 00652 void fix_length_and_dec(); 00653 void result_precision(); 00654 }; 00655 00656 00657 class Item_func_int_div :public Item_int_func 00658 { 00659 public: 00660 Item_func_int_div(Item *a,Item *b) :Item_int_func(a,b) 00661 {} 00662 longlong val_int(); 00663 const char *func_name() const { return "DIV"; } 00664 void fix_length_and_dec(); 00665 00666 virtual inline void print(String *str, enum_query_type query_type) 00667 { 00668 print_op(str, query_type); 00669 } 00670 00671 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00672 }; 00673 00674 00675 class Item_func_mod :public Item_num_op 00676 { 00677 public: 00678 Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {} 00679 longlong int_op(); 00680 double real_op(); 00681 my_decimal *decimal_op(my_decimal *); 00682 const char *func_name() const { return "%"; } 00683 void result_precision(); 00684 void fix_length_and_dec(); 00685 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00686 }; 00687 00688 00689 class Item_func_neg :public Item_func_num1 00690 { 00691 public: 00692 Item_func_neg(Item *a) :Item_func_num1(a) {} 00693 double real_op(); 00694 longlong int_op(); 00695 my_decimal *decimal_op(my_decimal *); 00696 const char *func_name() const { return "-"; } 00697 enum Functype functype() const { return NEG_FUNC; } 00698 void fix_length_and_dec(); 00699 void fix_num_length_and_dec(); 00700 uint decimal_precision() const { return args[0]->decimal_precision(); } 00701 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00702 }; 00703 00704 00705 class Item_func_abs :public Item_func_num1 00706 { 00707 public: 00708 Item_func_abs(Item *a) :Item_func_num1(a) {} 00709 double real_op(); 00710 longlong int_op(); 00711 my_decimal *decimal_op(my_decimal *); 00712 const char *func_name() const { return "abs"; } 00713 void fix_length_and_dec(); 00714 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00715 }; 00716 00717 // A class to handle logarithmic and trigonometric functions 00718 00719 class Item_dec_func :public Item_real_func 00720 { 00721 public: 00722 Item_dec_func(Item *a) :Item_real_func(a) {} 00723 Item_dec_func(Item *a,Item *b) :Item_real_func(a,b) {} 00724 void fix_length_and_dec() 00725 { 00726 decimals=NOT_FIXED_DEC; max_length=float_length(decimals); 00727 maybe_null=1; 00728 } 00729 }; 00730 00731 class Item_func_exp :public Item_dec_func 00732 { 00733 public: 00734 Item_func_exp(Item *a) :Item_dec_func(a) {} 00735 double val_real(); 00736 const char *func_name() const { return "exp"; } 00737 }; 00738 00739 00740 class Item_func_ln :public Item_dec_func 00741 { 00742 public: 00743 Item_func_ln(Item *a) :Item_dec_func(a) {} 00744 double val_real(); 00745 const char *func_name() const { return "ln"; } 00746 }; 00747 00748 00749 class Item_func_log :public Item_dec_func 00750 { 00751 public: 00752 Item_func_log(Item *a) :Item_dec_func(a) {} 00753 Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {} 00754 double val_real(); 00755 const char *func_name() const { return "log"; } 00756 }; 00757 00758 00759 class Item_func_log2 :public Item_dec_func 00760 { 00761 public: 00762 Item_func_log2(Item *a) :Item_dec_func(a) {} 00763 double val_real(); 00764 const char *func_name() const { return "log2"; } 00765 }; 00766 00767 00768 class Item_func_log10 :public Item_dec_func 00769 { 00770 public: 00771 Item_func_log10(Item *a) :Item_dec_func(a) {} 00772 double val_real(); 00773 const char *func_name() const { return "log10"; } 00774 }; 00775 00776 00777 class Item_func_sqrt :public Item_dec_func 00778 { 00779 public: 00780 Item_func_sqrt(Item *a) :Item_dec_func(a) {} 00781 double val_real(); 00782 const char *func_name() const { return "sqrt"; } 00783 }; 00784 00785 00786 class Item_func_pow :public Item_dec_func 00787 { 00788 public: 00789 Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {} 00790 double val_real(); 00791 const char *func_name() const { return "pow"; } 00792 }; 00793 00794 00795 class Item_func_acos :public Item_dec_func 00796 { 00797 public: 00798 Item_func_acos(Item *a) :Item_dec_func(a) {} 00799 double val_real(); 00800 const char *func_name() const { return "acos"; } 00801 }; 00802 00803 class Item_func_asin :public Item_dec_func 00804 { 00805 public: 00806 Item_func_asin(Item *a) :Item_dec_func(a) {} 00807 double val_real(); 00808 const char *func_name() const { return "asin"; } 00809 }; 00810 00811 class Item_func_atan :public Item_dec_func 00812 { 00813 public: 00814 Item_func_atan(Item *a) :Item_dec_func(a) {} 00815 Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {} 00816 double val_real(); 00817 const char *func_name() const { return "atan"; } 00818 }; 00819 00820 class Item_func_cos :public Item_dec_func 00821 { 00822 public: 00823 Item_func_cos(Item *a) :Item_dec_func(a) {} 00824 double val_real(); 00825 const char *func_name() const { return "cos"; } 00826 }; 00827 00828 class Item_func_sin :public Item_dec_func 00829 { 00830 public: 00831 Item_func_sin(Item *a) :Item_dec_func(a) {} 00832 double val_real(); 00833 const char *func_name() const { return "sin"; } 00834 }; 00835 00836 class Item_func_tan :public Item_dec_func 00837 { 00838 public: 00839 Item_func_tan(Item *a) :Item_dec_func(a) {} 00840 double val_real(); 00841 const char *func_name() const { return "tan"; } 00842 }; 00843 00844 class Item_func_cot :public Item_dec_func 00845 { 00846 public: 00847 Item_func_cot(Item *a) :Item_dec_func(a) {} 00848 double val_real(); 00849 const char *func_name() const { return "cot"; } 00850 }; 00851 00852 class Item_func_integer :public Item_int_func 00853 { 00854 public: 00855 inline Item_func_integer(Item *a) :Item_int_func(a) {} 00856 void fix_length_and_dec(); 00857 }; 00858 00859 00860 class Item_func_int_val :public Item_func_num1 00861 { 00862 public: 00863 Item_func_int_val(Item *a) :Item_func_num1(a) {} 00864 void fix_num_length_and_dec(); 00865 void find_num_type(); 00866 }; 00867 00868 00869 class Item_func_ceiling :public Item_func_int_val 00870 { 00871 public: 00872 Item_func_ceiling(Item *a) :Item_func_int_val(a) {} 00873 const char *func_name() const { return "ceiling"; } 00874 longlong int_op(); 00875 double real_op(); 00876 my_decimal *decimal_op(my_decimal *); 00877 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00878 }; 00879 00880 00881 class Item_func_floor :public Item_func_int_val 00882 { 00883 public: 00884 Item_func_floor(Item *a) :Item_func_int_val(a) {} 00885 const char *func_name() const { return "floor"; } 00886 longlong int_op(); 00887 double real_op(); 00888 my_decimal *decimal_op(my_decimal *); 00889 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00890 }; 00891 00892 /* This handles round and truncate */ 00893 00894 class Item_func_round :public Item_func_num1 00895 { 00896 bool truncate; 00897 public: 00898 Item_func_round(Item *a, Item *b, bool trunc_arg) 00899 :Item_func_num1(a,b), truncate(trunc_arg) {} 00900 const char *func_name() const { return truncate ? "truncate" : "round"; } 00901 double real_op(); 00902 longlong int_op(); 00903 my_decimal *decimal_op(my_decimal *); 00904 void fix_length_and_dec(); 00905 }; 00906 00907 00908 class Item_func_rand :public Item_real_func 00909 { 00910 struct rand_struct *rand; 00911 bool first_eval; // TRUE if val_real() is called 1st time 00912 public: 00913 Item_func_rand(Item *a) :Item_real_func(a), rand(0), first_eval(TRUE) {} 00914 Item_func_rand() :Item_real_func() {} 00915 double val_real(); 00916 const char *func_name() const { return "rand"; } 00917 bool const_item() const { return 0; } 00924 table_map get_initial_pseudo_tables() const { return RAND_TABLE_BIT; } 00925 bool fix_fields(THD *thd, Item **ref); 00926 void cleanup() { first_eval= TRUE; Item_real_func::cleanup(); } 00927 private: 00928 void seed_random (Item * val); 00929 }; 00930 00931 00932 class Item_func_sign :public Item_int_func 00933 { 00934 public: 00935 Item_func_sign(Item *a) :Item_int_func(a) {} 00936 const char *func_name() const { return "sign"; } 00937 longlong val_int(); 00938 }; 00939 00940 00941 class Item_func_units :public Item_real_func 00942 { 00943 char *name; 00944 double mul,add; 00945 public: 00946 Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg) 00947 :Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {} 00948 double val_real(); 00949 const char *func_name() const { return name; } 00950 void fix_length_and_dec() 00951 { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); } 00952 }; 00953 00954 00955 class Item_func_min_max :public Item_func 00956 { 00957 Item_result cmp_type; 00958 String tmp_value; 00959 int cmp_sign; 00960 /* TRUE <=> arguments should be compared in the DATETIME context. */ 00961 bool compare_as_dates; 00962 /* An item used for issuing warnings while string to DATETIME conversion. */ 00963 Item *datetime_item; 00964 THD *thd; 00965 protected: 00966 enum_field_types cached_field_type; 00967 uint cmp_datetimes(longlong *value); 00968 uint cmp_times(longlong *value); 00969 public: 00970 Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list), 00971 cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(FALSE), 00972 datetime_item(0) {} 00973 double val_real(); 00974 longlong val_int(); 00975 String *val_str(String *); 00976 my_decimal *val_decimal(my_decimal *); 00977 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 00978 bool get_time(MYSQL_TIME *ltime); 00979 void fix_length_and_dec(); 00980 enum Item_result result_type () const 00981 { 00982 /* 00983 If we compare as dates, then: 00984 - field_type is MYSQL_TYPE_VARSTRING, MYSQL_TYPE_DATETIME 00985 or MYSQL_TYPE_DATE. 00986 - cmp_type is INT_RESULT or DECIMAL_RESULT, 00987 depending on the amount of fractional digits. 00988 We need to return STRING_RESULT in this case instead of cmp_type. 00989 */ 00990 return compare_as_dates ? STRING_RESULT : cmp_type; 00991 } 00992 enum Item_result cast_to_int_type () const 00993 { 00994 /* 00995 make CAST(LEAST_OR_GREATEST(datetime_expr, varchar_expr)) 00996 return a number in format "YYYMMDDhhmmss". 00997 */ 00998 return compare_as_dates ? INT_RESULT : result_type(); 00999 } 01000 enum_field_types field_type() const { return cached_field_type; } 01001 }; 01002 01003 class Item_func_min :public Item_func_min_max 01004 { 01005 public: 01006 Item_func_min(List<Item> &list) :Item_func_min_max(list,1) {} 01007 const char *func_name() const { return "least"; } 01008 }; 01009 01010 class Item_func_max :public Item_func_min_max 01011 { 01012 public: 01013 Item_func_max(List<Item> &list) :Item_func_min_max(list,-1) {} 01014 const char *func_name() const { return "greatest"; } 01015 }; 01016 01017 01018 /* 01019 Objects of this class are used for ROLLUP queries to wrap up 01020 each constant item referred to in GROUP BY list. 01021 */ 01022 01023 class Item_func_rollup_const :public Item_func 01024 { 01025 public: 01026 Item_func_rollup_const(Item *a) :Item_func(a) 01027 { 01028 item_name= a->item_name; 01029 } 01030 double val_real() { return args[0]->val_real(); } 01031 longlong val_int() { return args[0]->val_int(); } 01032 String *val_str(String *str) { return args[0]->val_str(str); } 01033 my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); } 01034 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01035 { 01036 return args[0]->get_date(ltime, fuzzydate); 01037 } 01038 bool get_time(MYSQL_TIME *ltime) 01039 { 01040 return args[0]->get_time(ltime); 01041 } 01042 const char *func_name() const { return "rollup_const"; } 01043 bool const_item() const { return 0; } 01044 Item_result result_type() const { return args[0]->result_type(); } 01045 void fix_length_and_dec() 01046 { 01047 collation= args[0]->collation; 01048 max_length= args[0]->max_length; 01049 decimals=args[0]->decimals; 01050 /* The item could be a NULL constant. */ 01051 null_value= args[0]->is_null(); 01052 } 01053 enum_field_types field_type() const { return args[0]->field_type(); } 01054 }; 01055 01056 01057 class Item_func_length :public Item_int_func 01058 { 01059 String value; 01060 public: 01061 Item_func_length(Item *a) :Item_int_func(a) {} 01062 longlong val_int(); 01063 const char *func_name() const { return "length"; } 01064 void fix_length_and_dec() { max_length=10; } 01065 }; 01066 01067 class Item_func_bit_length :public Item_func_length 01068 { 01069 public: 01070 Item_func_bit_length(Item *a) :Item_func_length(a) {} 01071 longlong val_int() 01072 { DBUG_ASSERT(fixed == 1); return Item_func_length::val_int()*8; } 01073 const char *func_name() const { return "bit_length"; } 01074 }; 01075 01076 class Item_func_char_length :public Item_int_func 01077 { 01078 String value; 01079 public: 01080 Item_func_char_length(Item *a) :Item_int_func(a) {} 01081 longlong val_int(); 01082 const char *func_name() const { return "char_length"; } 01083 void fix_length_and_dec() { max_length=10; } 01084 }; 01085 01086 class Item_func_coercibility :public Item_int_func 01087 { 01088 public: 01089 Item_func_coercibility(Item *a) :Item_int_func(a) {} 01090 longlong val_int(); 01091 const char *func_name() const { return "coercibility"; } 01092 void fix_length_and_dec() { max_length=10; maybe_null= 0; } 01093 table_map not_null_tables() const { return 0; } 01094 }; 01095 01096 class Item_func_locate :public Item_int_func 01097 { 01098 String value1,value2; 01099 DTCollation cmp_collation; 01100 public: 01101 Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {} 01102 Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {} 01103 const char *func_name() const { return "locate"; } 01104 longlong val_int(); 01105 void fix_length_and_dec(); 01106 virtual void print(String *str, enum_query_type query_type); 01107 }; 01108 01109 01110 class Item_func_validate_password_strength :public Item_int_func 01111 { 01112 String value; 01113 public: 01114 Item_func_validate_password_strength(Item *a) :Item_int_func(a) {} 01115 longlong val_int(); 01116 const char *func_name() const { return "validate_password_strength"; } 01117 void fix_length_and_dec() { max_length= 10; maybe_null= 1; } 01118 }; 01119 01120 01121 class Item_func_field :public Item_int_func 01122 { 01123 String value,tmp; 01124 Item_result cmp_type; 01125 DTCollation cmp_collation; 01126 public: 01127 Item_func_field(List<Item> &list) :Item_int_func(list) {} 01128 longlong val_int(); 01129 const char *func_name() const { return "field"; } 01130 void fix_length_and_dec(); 01131 }; 01132 01133 01134 class Item_func_ascii :public Item_int_func 01135 { 01136 String value; 01137 public: 01138 Item_func_ascii(Item *a) :Item_int_func(a) {} 01139 longlong val_int(); 01140 const char *func_name() const { return "ascii"; } 01141 void fix_length_and_dec() { max_length=3; } 01142 }; 01143 01144 class Item_func_ord :public Item_int_func 01145 { 01146 String value; 01147 public: 01148 Item_func_ord(Item *a) :Item_int_func(a) {} 01149 longlong val_int(); 01150 const char *func_name() const { return "ord"; } 01151 }; 01152 01153 class Item_func_find_in_set :public Item_int_func 01154 { 01155 String value,value2; 01156 uint enum_value; 01157 ulonglong enum_bit; 01158 DTCollation cmp_collation; 01159 public: 01160 Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {} 01161 longlong val_int(); 01162 const char *func_name() const { return "find_in_set"; } 01163 void fix_length_and_dec(); 01164 }; 01165 01166 /* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */ 01167 01168 class Item_func_bit: public Item_int_func 01169 { 01170 public: 01171 Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {} 01172 Item_func_bit(Item *a) :Item_int_func(a) {} 01173 void fix_length_and_dec() { unsigned_flag= 1; } 01174 01175 virtual inline void print(String *str, enum_query_type query_type) 01176 { 01177 print_op(str, query_type); 01178 } 01179 }; 01180 01181 class Item_func_bit_or :public Item_func_bit 01182 { 01183 public: 01184 Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {} 01185 longlong val_int(); 01186 const char *func_name() const { return "|"; } 01187 }; 01188 01189 class Item_func_bit_and :public Item_func_bit 01190 { 01191 public: 01192 Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {} 01193 longlong val_int(); 01194 const char *func_name() const { return "&"; } 01195 }; 01196 01197 class Item_func_bit_count :public Item_int_func 01198 { 01199 public: 01200 Item_func_bit_count(Item *a) :Item_int_func(a) {} 01201 longlong val_int(); 01202 const char *func_name() const { return "bit_count"; } 01203 void fix_length_and_dec() { max_length=2; } 01204 }; 01205 01206 class Item_func_shift_left :public Item_func_bit 01207 { 01208 public: 01209 Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {} 01210 longlong val_int(); 01211 const char *func_name() const { return "<<"; } 01212 }; 01213 01214 class Item_func_shift_right :public Item_func_bit 01215 { 01216 public: 01217 Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {} 01218 longlong val_int(); 01219 const char *func_name() const { return ">>"; } 01220 }; 01221 01222 class Item_func_bit_neg :public Item_func_bit 01223 { 01224 public: 01225 Item_func_bit_neg(Item *a) :Item_func_bit(a) {} 01226 longlong val_int(); 01227 const char *func_name() const { return "~"; } 01228 01229 virtual inline void print(String *str, enum_query_type query_type) 01230 { 01231 Item_func::print(str, query_type); 01232 } 01233 }; 01234 01235 01236 class Item_func_last_insert_id :public Item_int_func 01237 { 01238 public: 01239 Item_func_last_insert_id() :Item_int_func() {} 01240 Item_func_last_insert_id(Item *a) :Item_int_func(a) {} 01241 longlong val_int(); 01242 const char *func_name() const { return "last_insert_id"; } 01243 void fix_length_and_dec() 01244 { 01245 unsigned_flag= TRUE; 01246 if (arg_count) 01247 max_length= args[0]->max_length; 01248 } 01249 bool fix_fields(THD *thd, Item **ref); 01250 }; 01251 01252 01253 class Item_func_benchmark :public Item_int_func 01254 { 01255 public: 01256 Item_func_benchmark(Item *count_expr, Item *expr) 01257 :Item_int_func(count_expr, expr) 01258 {} 01259 longlong val_int(); 01260 const char *func_name() const { return "benchmark"; } 01261 void fix_length_and_dec() { max_length=1; maybe_null=0; } 01262 virtual void print(String *str, enum_query_type query_type); 01263 }; 01264 01265 01266 class Item_func_sleep :public Item_int_func 01267 { 01268 public: 01269 Item_func_sleep(Item *a) :Item_int_func(a) {} 01270 bool const_item() const { return 0; } 01271 const char *func_name() const { return "sleep"; } 01278 table_map get_initial_pseudo_tables() const { return RAND_TABLE_BIT; } 01279 longlong val_int(); 01280 }; 01281 01282 01283 01284 #ifdef HAVE_DLOPEN 01285 01286 class Item_udf_func :public Item_func 01287 { 01288 protected: 01289 udf_handler udf; 01290 bool is_expensive_processor(uchar *arg) { return TRUE; } 01291 01292 public: 01293 Item_udf_func(udf_func *udf_arg) 01294 :Item_func(), udf(udf_arg) {} 01295 Item_udf_func(udf_func *udf_arg, List<Item> &list) 01296 :Item_func(list), udf(udf_arg) {} 01297 const char *func_name() const { return udf.name(); } 01298 enum Functype functype() const { return UDF_FUNC; } 01299 bool fix_fields(THD *thd, Item **ref) 01300 { 01301 DBUG_ASSERT(fixed == 0); 01302 bool res= udf.fix_fields(thd, this, arg_count, args); 01303 used_tables_cache= udf.used_tables_cache; 01304 const_item_cache= udf.const_item_cache; 01305 fixed= 1; 01306 return res; 01307 } 01308 void update_used_tables() 01309 { 01310 /* 01311 TODO: Make a member in UDF_INIT and return if a UDF is deterministic or 01312 not. 01313 Currently UDF_INIT has a member (const_item) that is an in/out 01314 parameter to the init() call. 01315 The code in udf_handler::fix_fields also duplicates the arguments 01316 handling code in Item_func::fix_fields(). 01317 01318 The lack of information if a UDF is deterministic makes writing 01319 a correct update_used_tables() for UDFs impossible. 01320 One solution to this would be : 01321 - Add a is_deterministic member of UDF_INIT 01322 - (optionally) deprecate the const_item member of UDF_INIT 01323 - Take away the duplicate code from udf_handler::fix_fields() and 01324 make Item_udf_func call Item_func::fix_fields() to process its 01325 arguments as for any other function. 01326 - Store the deterministic flag returned by <udf>_init into the 01327 udf_handler. 01328 - Don't implement Item_udf_func::fix_fields, implement 01329 Item_udf_func::fix_length_and_dec() instead (similar to non-UDF 01330 functions). 01331 - Override Item_func::update_used_tables to call 01332 Item_func::update_used_tables() and add a RAND_TABLE_BIT to the 01333 result of Item_func::update_used_tables() if the UDF is 01334 non-deterministic. 01335 - (optionally) rename RAND_TABLE_BIT to NONDETERMINISTIC_BIT to 01336 better describe its usage. 01337 01338 The above would require a change of the UDF API. 01339 Until that change is done here's how the current code works: 01340 We call Item_func::update_used_tables() only when we know that 01341 the function depends on real non-const tables and is deterministic. 01342 This can be done only because we know that the optimizer will 01343 call update_used_tables() only when there's possibly a new const 01344 table. So update_used_tables() can only make a Item_func more 01345 constant than it is currently. 01346 That's why we don't need to do anything if a function is guaranteed 01347 to return non-constant (it's non-deterministic) or is already a 01348 const. 01349 */ 01350 if ((used_tables_cache & ~PSEUDO_TABLE_BITS) && 01351 !(used_tables_cache & RAND_TABLE_BIT)) 01352 { 01353 Item_func::update_used_tables(); 01354 if (!const_item_cache && !used_tables_cache) 01355 used_tables_cache= RAND_TABLE_BIT; 01356 } 01357 } 01358 void cleanup(); 01359 Item_result result_type () const { return udf.result_type(); } 01360 table_map not_null_tables() const { return 0; } 01361 bool is_expensive() { return 1; } 01362 virtual void print(String *str, enum_query_type query_type); 01363 }; 01364 01365 01366 class Item_func_udf_float :public Item_udf_func 01367 { 01368 public: 01369 Item_func_udf_float(udf_func *udf_arg) 01370 :Item_udf_func(udf_arg) {} 01371 Item_func_udf_float(udf_func *udf_arg, 01372 List<Item> &list) 01373 :Item_udf_func(udf_arg, list) {} 01374 longlong val_int() 01375 { 01376 DBUG_ASSERT(fixed == 1); 01377 return (longlong) rint(Item_func_udf_float::val_real()); 01378 } 01379 my_decimal *val_decimal(my_decimal *dec_buf) 01380 { 01381 double res=val_real(); 01382 if (null_value) 01383 return NULL; 01384 double2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf); 01385 return dec_buf; 01386 } 01387 double val_real(); 01388 String *val_str(String *str); 01389 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01390 { 01391 return get_date_from_real(ltime, fuzzydate); 01392 } 01393 bool get_time(MYSQL_TIME *ltime) 01394 { 01395 return get_time_from_real(ltime); 01396 } 01397 void fix_length_and_dec() { fix_num_length_and_dec(); } 01398 }; 01399 01400 01401 class Item_func_udf_int :public Item_udf_func 01402 { 01403 public: 01404 Item_func_udf_int(udf_func *udf_arg) 01405 :Item_udf_func(udf_arg) {} 01406 Item_func_udf_int(udf_func *udf_arg, 01407 List<Item> &list) 01408 :Item_udf_func(udf_arg, list) {} 01409 longlong val_int(); 01410 double val_real() { return (double) Item_func_udf_int::val_int(); } 01411 String *val_str(String *str); 01412 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01413 { 01414 return get_date_from_int(ltime, fuzzydate); 01415 } 01416 bool get_time(MYSQL_TIME *ltime) 01417 { 01418 return get_time_from_int(ltime); 01419 } 01420 enum Item_result result_type () const { return INT_RESULT; } 01421 void fix_length_and_dec() { decimals= 0; max_length= 21; } 01422 }; 01423 01424 01425 class Item_func_udf_decimal :public Item_udf_func 01426 { 01427 public: 01428 Item_func_udf_decimal(udf_func *udf_arg) 01429 :Item_udf_func(udf_arg) {} 01430 Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list) 01431 :Item_udf_func(udf_arg, list) {} 01432 longlong val_int(); 01433 double val_real(); 01434 my_decimal *val_decimal(my_decimal *); 01435 String *val_str(String *str); 01436 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01437 { 01438 return get_date_from_decimal(ltime, fuzzydate); 01439 } 01440 bool get_time(MYSQL_TIME *ltime) 01441 { 01442 return get_time_from_decimal(ltime); 01443 } 01444 enum Item_result result_type () const { return DECIMAL_RESULT; } 01445 void fix_length_and_dec(); 01446 }; 01447 01448 01449 class Item_func_udf_str :public Item_udf_func 01450 { 01451 public: 01452 Item_func_udf_str(udf_func *udf_arg) 01453 :Item_udf_func(udf_arg) {} 01454 Item_func_udf_str(udf_func *udf_arg, List<Item> &list) 01455 :Item_udf_func(udf_arg, list) {} 01456 String *val_str(String *); 01457 double val_real() 01458 { 01459 int err_not_used; 01460 char *end_not_used; 01461 String *res; 01462 res= val_str(&str_value); 01463 return res ? my_strntod(res->charset(),(char*) res->ptr(), 01464 res->length(), &end_not_used, &err_not_used) : 0.0; 01465 } 01466 longlong val_int() 01467 { 01468 int err_not_used; 01469 String *res; res=val_str(&str_value); 01470 return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10, 01471 (char**) 0, &err_not_used) : (longlong) 0; 01472 } 01473 my_decimal *val_decimal(my_decimal *dec_buf) 01474 { 01475 String *res=val_str(&str_value); 01476 if (!res) 01477 return NULL; 01478 string2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf); 01479 return dec_buf; 01480 } 01481 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01482 { 01483 return get_date_from_string(ltime, fuzzydate); 01484 } 01485 bool get_time(MYSQL_TIME *ltime) 01486 { 01487 return get_time_from_string(ltime); 01488 } 01489 enum Item_result result_type () const { return STRING_RESULT; } 01490 void fix_length_and_dec(); 01491 }; 01492 01493 #else /* Dummy functions to get sql_yacc.cc compiled */ 01494 01495 01496 class Item_func_udf_float :public Item_real_func 01497 { 01498 public: 01499 Item_func_udf_float(udf_func *udf_arg) 01500 :Item_real_func() {} 01501 Item_func_udf_float(udf_func *udf_arg, List<Item> &list) 01502 :Item_real_func(list) {} 01503 double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; } 01504 }; 01505 01506 01507 class Item_func_udf_int :public Item_int_func 01508 { 01509 public: 01510 Item_func_udf_int(udf_func *udf_arg) 01511 :Item_int_func() {} 01512 Item_func_udf_int(udf_func *udf_arg, List<Item> &list) 01513 :Item_int_func(list) {} 01514 longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; } 01515 }; 01516 01517 01518 class Item_func_udf_decimal :public Item_int_func 01519 { 01520 public: 01521 Item_func_udf_decimal(udf_func *udf_arg) 01522 :Item_int_func() {} 01523 Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list) 01524 :Item_int_func(list) {} 01525 my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; } 01526 }; 01527 01528 01529 class Item_func_udf_str :public Item_func 01530 { 01531 public: 01532 Item_func_udf_str(udf_func *udf_arg) 01533 :Item_func() {} 01534 Item_func_udf_str(udf_func *udf_arg, List<Item> &list) 01535 :Item_func(list) {} 01536 String *val_str(String *) 01537 { DBUG_ASSERT(fixed == 1); null_value=1; return 0; } 01538 double val_real() { DBUG_ASSERT(fixed == 1); null_value= 1; return 0.0; } 01539 longlong val_int() { DBUG_ASSERT(fixed == 1); null_value=1; return 0; } 01540 enum Item_result result_type () const { return STRING_RESULT; } 01541 void fix_length_and_dec() { maybe_null=1; max_length=0; } 01542 }; 01543 01544 #endif /* HAVE_DLOPEN */ 01545 01546 /* 01547 ** User level locks 01548 */ 01549 01550 class User_level_lock; 01551 void item_user_lock_init(void); 01552 void item_user_lock_release(User_level_lock *ull); 01553 void item_user_lock_free(void); 01554 01555 class Item_func_get_lock :public Item_int_func 01556 { 01557 String value; 01558 public: 01559 Item_func_get_lock(Item *a,Item *b) :Item_int_func(a,b) {} 01560 longlong val_int(); 01561 const char *func_name() const { return "get_lock"; } 01562 void fix_length_and_dec() { max_length=1; maybe_null=1;} 01563 }; 01564 01565 class Item_func_release_lock :public Item_int_func 01566 { 01567 String value; 01568 public: 01569 Item_func_release_lock(Item *a) :Item_int_func(a) {} 01570 longlong val_int(); 01571 const char *func_name() const { return "release_lock"; } 01572 void fix_length_and_dec() { max_length=1; maybe_null=1;} 01573 }; 01574 01575 /* replication functions */ 01576 01577 class Item_master_pos_wait :public Item_int_func 01578 { 01579 String value; 01580 public: 01581 Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {} 01582 Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {} 01583 longlong val_int(); 01584 const char *func_name() const { return "master_pos_wait"; } 01585 void fix_length_and_dec() { max_length=21; maybe_null=1;} 01586 }; 01587 01588 class Item_master_gtid_set_wait :public Item_int_func 01589 { 01590 String value; 01591 public: 01592 Item_master_gtid_set_wait(Item *a) :Item_int_func(a) {} 01593 Item_master_gtid_set_wait(Item *a, Item *b) :Item_int_func(a,b) {} 01594 longlong val_int(); 01595 const char *func_name() const { return "wait_until_sql_thread_after_gtids"; } 01596 void fix_length_and_dec() { max_length= 21; maybe_null= 1; } 01597 }; 01598 01599 class Item_func_gtid_subset : public Item_int_func 01600 { 01601 String buf1; 01602 String buf2; 01603 public: 01604 Item_func_gtid_subset(Item *a, Item *b) : Item_int_func(a, b) {} 01605 longlong val_int(); 01606 const char *func_name() const { return "gtid_subset"; } 01607 void fix_length_and_dec() { max_length= 21; maybe_null= 0; } 01608 }; 01609 01610 01617 class Item_var_func :public Item_func 01618 { 01619 public: 01620 Item_var_func() :Item_func() { } 01621 Item_var_func(THD *thd, Item_var_func *item) :Item_func(thd, item) { } 01622 Item_var_func(Item *a) :Item_func(a) { } 01623 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01624 { 01625 return get_date_from_non_temporal(ltime, fuzzydate); 01626 } 01627 bool get_time(MYSQL_TIME *ltime) 01628 { 01629 return get_time_from_non_temporal(ltime); 01630 } 01631 }; 01632 01633 01634 /* Handling of user definable variables */ 01635 01636 class user_var_entry; 01637 01638 class Item_func_set_user_var :public Item_var_func 01639 { 01640 enum Item_result cached_result_type; 01641 user_var_entry *entry; 01642 /* 01643 The entry_thread_id variable is used: 01644 1) to skip unnecessary updates of the entry field (see above); 01645 2) to reset the entry field that was initialized in the other thread 01646 (for example, an item tree of a trigger that updates user variables 01647 may be shared between several connections, and the entry_thread_id field 01648 prevents updates of one connection user variables from a concurrent 01649 connection calling the same trigger that initially updated some 01650 user variable it the first connection context). 01651 */ 01652 my_thread_id entry_thread_id; 01666 bool delayed_non_constness; 01667 char buffer[MAX_FIELD_WIDTH]; 01668 String value; 01669 my_decimal decimal_buff; 01670 bool null_item; 01671 union 01672 { 01673 longlong vint; 01674 double vreal; 01675 String *vstr; 01676 my_decimal *vdec; 01677 } save_result; 01678 01679 public: 01680 Name_string name; // keep it public 01681 Item_func_set_user_var(Name_string a, Item *b, bool delayed) 01682 :Item_var_func(b), cached_result_type(INT_RESULT), 01683 entry(NULL), entry_thread_id(0), delayed_non_constness(delayed), name(a) 01684 {} 01685 Item_func_set_user_var(THD *thd, Item_func_set_user_var *item) 01686 :Item_var_func(thd, item), cached_result_type(item->cached_result_type), 01687 entry(item->entry), entry_thread_id(item->entry_thread_id), 01688 delayed_non_constness(item->delayed_non_constness), value(item->value), 01689 decimal_buff(item->decimal_buff), null_item(item->null_item), 01690 save_result(item->save_result), name(item->name) 01691 {} 01692 enum Functype functype() const { return SUSERVAR_FUNC; } 01693 double val_real(); 01694 longlong val_int(); 01695 String *val_str(String *str); 01696 my_decimal *val_decimal(my_decimal *); 01697 double val_result(); 01698 longlong val_int_result(); 01699 bool val_bool_result(); 01700 String *str_result(String *str); 01701 my_decimal *val_decimal_result(my_decimal *); 01702 bool is_null_result(); 01703 bool update_hash(void *ptr, uint length, enum Item_result type, 01704 const CHARSET_INFO *cs, Derivation dv, bool unsigned_arg); 01705 bool send(Protocol *protocol, String *str_arg); 01706 void make_field(Send_field *tmp_field); 01707 bool check(bool use_result_field); 01708 void save_item_result(Item *item); 01709 bool update(); 01710 enum Item_result result_type () const { return cached_result_type; } 01711 bool fix_fields(THD *thd, Item **ref); 01712 void fix_length_and_dec(); 01713 virtual void print(String *str, enum_query_type query_type); 01714 void print_assignment(String *str, enum_query_type query_type); 01715 const char *func_name() const { return "set_user_var"; } 01716 type_conversion_status save_in_field(Field *field, bool no_conversions, 01717 bool can_use_result_field); 01718 type_conversion_status save_in_field(Field *field, bool no_conversions) 01719 { 01720 return save_in_field(field, no_conversions, 1); 01721 } 01722 void save_org_in_field(Field *field) { (void)save_in_field(field, 1, 0); } 01723 bool register_field_in_read_map(uchar *arg); 01724 bool set_entry(THD *thd, bool create_if_not_exists); 01725 void cleanup(); 01726 }; 01727 01728 01729 class Item_func_get_user_var :public Item_var_func, 01730 private Settable_routine_parameter 01731 { 01732 user_var_entry *var_entry; 01733 Item_result m_cached_result_type; 01734 01735 public: 01736 Name_string name; // keep it public 01737 Item_func_get_user_var(Name_string a): 01738 Item_var_func(), m_cached_result_type(STRING_RESULT), name(a) {} 01739 enum Functype functype() const { return GUSERVAR_FUNC; } 01740 double val_real(); 01741 longlong val_int(); 01742 my_decimal *val_decimal(my_decimal*); 01743 String *val_str(String* str); 01744 void fix_length_and_dec(); 01745 virtual void print(String *str, enum_query_type query_type); 01746 enum Item_result result_type() const; 01747 /* 01748 We must always return variables as strings to guard against selects of type 01749 select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b) 01750 */ 01751 const char *func_name() const { return "get_user_var"; } 01752 bool const_item() const; 01753 table_map used_tables() const 01754 { return const_item() ? 0 : RAND_TABLE_BIT; } 01755 bool eq(const Item *item, bool binary_cmp) const; 01756 private: 01757 bool set_value(THD *thd, sp_rcontext *ctx, Item **it); 01758 01759 public: 01760 Settable_routine_parameter *get_settable_routine_parameter() 01761 { 01762 return this; 01763 } 01764 }; 01765 01766 01767 /* 01768 This item represents user variable used as out parameter (e.g in LOAD DATA), 01769 and it is supposed to be used only for this purprose. So it is simplified 01770 a lot. Actually you should never obtain its value. 01771 01772 The only two reasons for this thing being an Item is possibility to store it 01773 in List<Item> and desire to place this code somewhere near other functions 01774 working with user variables. 01775 */ 01776 class Item_user_var_as_out_param :public Item 01777 { 01778 Name_string name; 01779 user_var_entry *entry; 01780 public: 01781 Item_user_var_as_out_param(Name_string a) :name(a) 01782 { item_name.copy(a); } 01783 /* We should return something different from FIELD_ITEM here */ 01784 enum Type type() const { return STRING_ITEM;} 01785 double val_real(); 01786 longlong val_int(); 01787 String *val_str(String *str); 01788 my_decimal *val_decimal(my_decimal *decimal_buffer); 01789 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 01790 { 01791 DBUG_ASSERT(0); 01792 return true; 01793 } 01794 bool get_time(MYSQL_TIME *ltime) 01795 { 01796 DBUG_ASSERT(0); 01797 return true; 01798 } 01799 01800 /* fix_fields() binds variable name with its entry structure */ 01801 bool fix_fields(THD *thd, Item **ref); 01802 virtual void print(String *str, enum_query_type query_type); 01803 void set_null_value(const CHARSET_INFO* cs); 01804 void set_value(const char *str, uint length, const CHARSET_INFO* cs); 01805 }; 01806 01807 01808 /* A system variable */ 01809 01810 #define GET_SYS_VAR_CACHE_LONG 1 01811 #define GET_SYS_VAR_CACHE_DOUBLE 2 01812 #define GET_SYS_VAR_CACHE_STRING 4 01813 01814 class Item_func_get_system_var :public Item_var_func 01815 { 01816 sys_var *var; 01817 enum_var_type var_type, orig_var_type; 01818 LEX_STRING component; 01819 longlong cached_llval; 01820 double cached_dval; 01821 String cached_strval; 01822 my_bool cached_null_value; 01823 query_id_t used_query_id; 01824 uchar cache_present; 01825 01826 public: 01827 Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg, 01828 LEX_STRING *component_arg, const char *name_arg, 01829 size_t name_len_arg); 01830 enum Functype functype() const { return GSYSVAR_FUNC; } 01831 void update_null_value(); 01832 void fix_length_and_dec(); 01833 void print(String *str, enum_query_type query_type); 01834 bool const_item() const { return true; } 01835 table_map used_tables() const { return 0; } 01836 enum Item_result result_type() const; 01837 enum_field_types field_type() const; 01838 double val_real(); 01839 longlong val_int(); 01840 String* val_str(String*); 01841 my_decimal *val_decimal(my_decimal *dec_buf) 01842 { return val_decimal_from_real(dec_buf); } 01843 /* TODO: fix to support views */ 01844 const char *func_name() const { return "get_system_var"; } 01853 bool is_written_to_binlog(); 01854 bool eq(const Item *item, bool binary_cmp) const; 01855 01856 void cleanup(); 01857 }; 01858 01859 01860 /* for fulltext search */ 01861 #include <ft_global.h> 01862 01863 class Item_func_match :public Item_real_func 01864 { 01865 public: 01866 uint key, flags; 01867 bool join_key; 01868 DTCollation cmp_collation; 01869 FT_INFO *ft_handler; 01870 TABLE *table; 01871 Item_func_match *master; // for master-slave optimization 01872 Item *concat_ws; // Item_func_concat_ws 01873 String value; // value of concat_ws 01874 String search_value; // key_item()'s value converted to cmp_collation 01875 01876 Item_func_match(List<Item> &a, uint b): Item_real_func(a), key(0), flags(b), 01877 join_key(0), ft_handler(0), table(0), master(0), concat_ws(0) { } 01878 void cleanup() 01879 { 01880 DBUG_ENTER("Item_func_match::cleanup"); 01881 Item_real_func::cleanup(); 01882 if (!master && ft_handler) 01883 ft_handler->please->close_search(ft_handler); 01884 ft_handler= 0; 01885 concat_ws= 0; 01886 table= 0; // required by Item_func_match::eq() 01887 DBUG_VOID_RETURN; 01888 } 01889 enum Functype functype() const { return FT_FUNC; } 01890 const char *func_name() const { return "match"; } 01891 void update_used_tables() {} 01892 table_map not_null_tables() const { return 0; } 01893 bool fix_fields(THD *thd, Item **ref); 01894 bool eq(const Item *, bool binary_cmp) const; 01895 /* The following should be safe, even if we compare doubles */ 01896 longlong val_int() { DBUG_ASSERT(fixed == 1); return val_real() != 0.0; } 01897 double val_real(); 01898 virtual void print(String *str, enum_query_type query_type); 01899 01900 bool fix_index(); 01901 void init_search(bool no_order); 01902 01910 ulonglong get_count() 01911 { 01912 DBUG_ASSERT(ft_handler); 01913 DBUG_ASSERT(table->file->ha_table_flags() & HA_CAN_FULLTEXT_EXT); 01914 01915 return ((FT_INFO_EXT *)ft_handler)->could_you-> 01916 count_matches((FT_INFO_EXT *)ft_handler); 01917 } 01918 01925 bool ordered_result() 01926 { 01927 if (flags & FT_SORTED) 01928 return true; 01929 01930 if ((table->file->ha_table_flags() & HA_CAN_FULLTEXT_EXT) == 0) 01931 return false; 01932 01933 DBUG_ASSERT(ft_handler); 01934 return ((FT_INFO_EXT *)ft_handler)->could_you->get_flags() & 01935 FTS_ORDERED_RESULT; 01936 } 01937 01944 bool docid_in_result() 01945 { 01946 DBUG_ASSERT(ft_handler); 01947 01948 if ((table->file->ha_table_flags() & HA_CAN_FULLTEXT_EXT) == 0) 01949 return false; 01950 01951 return ((FT_INFO_EXT *)ft_handler)->could_you->get_flags() & 01952 FTS_DOCID_IN_RESULT; 01953 } 01954 01955 private: 01974 bool allows_search_on_non_indexed_columns(TABLE* table_arg) 01975 { 01976 // Only Boolean search may support non_indexed columns 01977 if (!(flags & FT_BOOL)) 01978 return false; 01979 01980 DBUG_ASSERT(table_arg && table_arg->file); 01981 01982 // Assume that if extended fulltext API is not supported, 01983 // non-indexed columns are allowed. This will be true for MyISAM. 01984 if ((table_arg->file->ha_table_flags() & HA_CAN_FULLTEXT_EXT) == 0) 01985 return true; 01986 01987 return false; 01988 } 01989 01990 }; 01991 01997 class Item_func_docid : public Item_int_func 01998 { 01999 FT_INFO_EXT *ft_handler; 02000 public: 02001 Item_func_docid(FT_INFO_EXT *handler) : ft_handler(handler) 02002 { 02003 max_length= 21; 02004 maybe_null= false; 02005 unsigned_flag= true; 02006 } 02007 02008 const char *func_name() const { return "docid"; } 02009 02010 void update_used_tables() 02011 { 02012 Item_int_func::update_used_tables(); 02013 used_tables_cache|= RAND_TABLE_BIT; 02014 const_item_cache= false; 02015 } 02016 02017 longlong val_int() 02018 { 02019 DBUG_ASSERT(ft_handler); 02020 return ft_handler->could_you->get_docid(ft_handler); 02021 } 02022 }; 02023 02024 class Item_func_bit_xor : public Item_func_bit 02025 { 02026 public: 02027 Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {} 02028 longlong val_int(); 02029 const char *func_name() const { return "^"; } 02030 }; 02031 02032 class Item_func_is_free_lock :public Item_int_func 02033 { 02034 String value; 02035 public: 02036 Item_func_is_free_lock(Item *a) :Item_int_func(a) {} 02037 longlong val_int(); 02038 const char *func_name() const { return "is_free_lock"; } 02039 void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} 02040 }; 02041 02042 class Item_func_is_used_lock :public Item_int_func 02043 { 02044 String value; 02045 public: 02046 Item_func_is_used_lock(Item *a) :Item_int_func(a) {} 02047 longlong val_int(); 02048 const char *func_name() const { return "is_used_lock"; } 02049 void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;} 02050 }; 02051 02052 /* For type casts */ 02053 02054 enum Cast_target 02055 { 02056 ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT, 02057 ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR, 02058 ITEM_CAST_DECIMAL 02059 }; 02060 02061 02062 class Item_func_row_count :public Item_int_func 02063 { 02064 public: 02065 Item_func_row_count() :Item_int_func() {} 02066 longlong val_int(); 02067 const char *func_name() const { return "row_count"; } 02068 void fix_length_and_dec() { decimals= 0; maybe_null=0; } 02069 }; 02070 02071 02072 /* 02073 * 02074 * Stored FUNCTIONs 02075 * 02076 */ 02077 02078 class sp_head; 02079 class sp_name; 02080 struct st_sp_security_context; 02081 02082 class Item_func_sp :public Item_func 02083 { 02084 private: 02085 Name_resolution_context *context; 02086 sp_name *m_name; 02087 mutable sp_head *m_sp; 02088 TABLE *dummy_table; 02089 uchar result_buf[64]; 02090 /* 02091 The result field of the concrete stored function. 02092 */ 02093 Field *sp_result_field; 02094 02095 bool execute(); 02096 bool execute_impl(THD *thd); 02097 bool init_result_field(THD *thd); 02098 02099 protected: 02100 bool is_expensive_processor(uchar *arg) { return TRUE; } 02101 02102 public: 02103 02104 Item_func_sp(Name_resolution_context *context_arg, sp_name *name); 02105 02106 Item_func_sp(Name_resolution_context *context_arg, 02107 sp_name *name, List<Item> &list); 02108 02109 virtual ~Item_func_sp() 02110 {} 02111 02116 table_map get_initial_pseudo_tables() const; 02117 void update_used_tables(); 02118 02119 void cleanup(); 02120 02121 const char *func_name() const; 02122 02123 enum enum_field_types field_type() const; 02124 02125 Field *tmp_table_field(TABLE *t_arg); 02126 02127 void make_field(Send_field *tmp_field); 02128 02129 Item_result result_type() const; 02130 02131 longlong val_int() 02132 { 02133 if (execute()) 02134 return (longlong) 0; 02135 return sp_result_field->val_int(); 02136 } 02137 02138 double val_real() 02139 { 02140 if (execute()) 02141 return 0.0; 02142 return sp_result_field->val_real(); 02143 } 02144 02145 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02146 { 02147 if (execute()) 02148 return true; 02149 return sp_result_field->get_date(ltime, fuzzydate); 02150 } 02151 02152 bool get_time(MYSQL_TIME *ltime) 02153 { 02154 if (execute()) 02155 return true; 02156 return sp_result_field->get_time(ltime); 02157 } 02158 02159 my_decimal *val_decimal(my_decimal *dec_buf) 02160 { 02161 if (execute()) 02162 return NULL; 02163 return sp_result_field->val_decimal(dec_buf); 02164 } 02165 02166 String *val_str(String *str) 02167 { 02168 String buf; 02169 char buff[20]; 02170 buf.set(buff, 20, str->charset()); 02171 buf.length(0); 02172 if (execute()) 02173 return NULL; 02174 /* 02175 result_field will set buf pointing to internal buffer 02176 of the resul_field. Due to this it will change any time 02177 when SP is executed. In order to prevent occasional 02178 corruption of returned value, we make here a copy. 02179 */ 02180 sp_result_field->val_str(&buf); 02181 str->copy(buf); 02182 return str; 02183 } 02184 02185 virtual bool change_context_processor(uchar *cntx) 02186 { context= (Name_resolution_context *)cntx; return FALSE; } 02187 02188 bool sp_check_access(THD * thd); 02189 virtual enum Functype functype() const { return FUNC_SP; } 02190 02191 bool fix_fields(THD *thd, Item **ref); 02192 void fix_length_and_dec(void); 02193 bool is_expensive() { return 1; } 02194 02195 inline Field *get_sp_result_field() 02196 { 02197 return sp_result_field; 02198 } 02199 02200 virtual void update_null_value(); 02201 }; 02202 02203 02204 class Item_func_found_rows :public Item_int_func 02205 { 02206 public: 02207 Item_func_found_rows() :Item_int_func() {} 02208 longlong val_int(); 02209 const char *func_name() const { return "found_rows"; } 02210 void fix_length_and_dec() { decimals= 0; maybe_null=0; } 02211 }; 02212 02213 02214 void uuid_short_init(); 02215 02216 class Item_func_uuid_short :public Item_int_func 02217 { 02218 public: 02219 Item_func_uuid_short() :Item_int_func() {} 02220 const char *func_name() const { return "uuid_short"; } 02221 longlong val_int(); 02222 void fix_length_and_dec() 02223 { max_length= 21; unsigned_flag=1; } 02224 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 02225 }; 02226 02227 Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, 02228 LEX_STRING component); 02229 extern bool check_reserved_words(LEX_STRING *name); 02230 extern enum_field_types agg_field_type(Item **items, uint nitems); 02231 double my_double_round(double value, longlong dec, bool dec_unsigned, 02232 bool truncate); 02233 bool eval_const_cond(Item *cond); 02234 02235 extern bool volatile mqh_used; 02236 02237 #endif /* ITEM_FUNC_INCLUDED */