00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 00018 /* Function items used by mysql */ 00019 00020 #ifdef USE_PRAGMA_INTERFACE 00021 #pragma interface /* gcc class implementation */ 00022 #endif 00023 00024 #ifdef HAVE_IEEEFP_H 00025 extern "C" /* Bug in BSDI include file */ 00026 { 00027 #include <ieeefp.h> 00028 } 00029 #endif 00030 00031 class Item_func :public Item_result_field 00032 { 00033 protected: 00034 Item **args, *tmp_arg[2]; 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; 00040 public: 00041 uint arg_count; 00042 table_map used_tables_cache, not_null_tables_cache; 00043 bool const_item_cache; 00044 enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC, 00045 GE_FUNC,GT_FUNC,FT_FUNC, 00046 LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC, 00047 COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC, 00048 BETWEEN, IN_FUNC, MULT_EQUAL_FUNC, 00049 INTERVAL_FUNC, ISNOTNULLTEST_FUNC, 00050 SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC, 00051 SP_TOUCHES_FUNC,SP_CROSSES_FUNC,SP_WITHIN_FUNC, 00052 SP_CONTAINS_FUNC,SP_OVERLAPS_FUNC, 00053 SP_STARTPOINT,SP_ENDPOINT,SP_EXTERIORRING, 00054 SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN, 00055 NOT_FUNC, NOT_ALL_FUNC, 00056 NOW_FUNC, TRIG_COND_FUNC, 00057 GUSERVAR_FUNC, COLLATE_FUNC, 00058 EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC }; 00059 enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL, 00060 OPTIMIZE_EQUAL }; 00061 enum Type type() const { return FUNC_ITEM; } 00062 virtual enum Functype functype() const { return UNKNOWN_FUNC; } 00063 Item_func(void): 00064 allowed_arg_cols(1), arg_count(0) 00065 { 00066 with_sum_func= 0; 00067 } 00068 Item_func(Item *a): 00069 allowed_arg_cols(1), arg_count(1) 00070 { 00071 args= tmp_arg; 00072 args[0]= a; 00073 with_sum_func= a->with_sum_func; 00074 } 00075 Item_func(Item *a,Item *b): 00076 allowed_arg_cols(1), arg_count(2) 00077 { 00078 args= tmp_arg; 00079 args[0]= a; args[1]= b; 00080 with_sum_func= a->with_sum_func || b->with_sum_func; 00081 } 00082 Item_func(Item *a,Item *b,Item *c): 00083 allowed_arg_cols(1) 00084 { 00085 arg_count= 0; 00086 if ((args= (Item**) sql_alloc(sizeof(Item*)*3))) 00087 { 00088 arg_count= 3; 00089 args[0]= a; args[1]= b; args[2]= c; 00090 with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func; 00091 } 00092 } 00093 Item_func(Item *a,Item *b,Item *c,Item *d): 00094 allowed_arg_cols(1) 00095 { 00096 arg_count= 0; 00097 if ((args= (Item**) sql_alloc(sizeof(Item*)*4))) 00098 { 00099 arg_count= 4; 00100 args[0]= a; args[1]= b; args[2]= c; args[3]= d; 00101 with_sum_func= a->with_sum_func || b->with_sum_func || 00102 c->with_sum_func || d->with_sum_func; 00103 } 00104 } 00105 Item_func(Item *a,Item *b,Item *c,Item *d,Item* e): 00106 allowed_arg_cols(1) 00107 { 00108 arg_count= 5; 00109 if ((args= (Item**) sql_alloc(sizeof(Item*)*5))) 00110 { 00111 args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e; 00112 with_sum_func= a->with_sum_func || b->with_sum_func || 00113 c->with_sum_func || d->with_sum_func || e->with_sum_func ; 00114 } 00115 } 00116 Item_func(List<Item> &list); 00117 // Constructor used for Item_cond_and/or (see Item comment) 00118 Item_func(THD *thd, Item_func *item); 00119 bool fix_fields(THD *, Item **ref); 00120 table_map used_tables() const; 00121 table_map not_null_tables() const; 00122 void update_used_tables(); 00123 bool eq(const Item *item, bool binary_cmp) const; 00124 virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; } 00125 virtual bool have_rev_func() const { return 0; } 00126 virtual Item *key_item() const { return args[0]; } 00127 /* 00128 This method is used for debug purposes to print the name of an 00129 item to the debug log. The second use of this method is as 00130 a helper function of print(), where it is applicable. 00131 To suit both goals it should return a meaningful, 00132 distinguishable and sintactically correct string. This method 00133 should not be used for runtime type identification, use enum 00134 {Sum}Functype and Item_func::functype()/Item_sum::sum_func() 00135 instead. 00136 */ 00137 virtual const char *func_name() const= 0; 00138 virtual bool const_item() const { return const_item_cache; } 00139 inline Item **arguments() const { return args; } 00140 void set_arguments(List<Item> &list); 00141 inline uint argument_count() const { return arg_count; } 00142 inline void remove_arguments() { arg_count=0; } 00143 void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields); 00144 void print(String *str); 00145 void print_op(String *str); 00146 void print_args(String *str, uint from); 00147 virtual void fix_num_length_and_dec(); 00148 void count_only_length(); 00149 void count_real_length(); 00150 void count_decimal_length(); 00151 inline bool get_arg0_date(TIME *ltime, uint fuzzy_date) 00152 { 00153 return (null_value=args[0]->get_date(ltime, fuzzy_date)); 00154 } 00155 inline bool get_arg0_time(TIME *ltime) 00156 { 00157 return (null_value=args[0]->get_time(ltime)); 00158 } 00159 bool is_null() { 00160 (void) val_int(); /* Discard result. It sets null_value as side-effect. */ 00161 return null_value; 00162 } 00163 void signal_divide_by_null(); 00164 friend class udf_handler; 00165 Field *tmp_table_field() { return result_field; } 00166 Field *tmp_table_field(TABLE *t_arg); 00167 Item *get_tmp_table_item(THD *thd); 00168 00169 my_decimal *val_decimal(my_decimal *); 00170 00171 bool agg_arg_collations(DTCollation &c, Item **items, uint nitems, 00172 uint flags) 00173 { 00174 return agg_item_collations(c, func_name(), items, nitems, flags, 1); 00175 } 00176 bool agg_arg_collations_for_comparison(DTCollation &c, 00177 Item **items, uint nitems, 00178 uint flags) 00179 { 00180 return agg_item_collations_for_comparison(c, func_name(), 00181 items, nitems, flags); 00182 } 00183 bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems, 00184 uint flags, int item_sep) 00185 { 00186 return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep); 00187 } 00188 bool walk(Item_processor processor, bool walk_subquery, byte *arg); 00189 Item *transform(Item_transformer transformer, byte *arg); 00190 void traverse_cond(Cond_traverser traverser, 00191 void * arg, traverse_order order); 00192 bool is_expensive_processor(byte *arg); 00193 virtual bool is_expensive() { return 0; } 00194 }; 00195 00196 00197 class Item_real_func :public Item_func 00198 { 00199 public: 00200 Item_real_func() :Item_func() {} 00201 Item_real_func(Item *a) :Item_func(a) {} 00202 Item_real_func(Item *a,Item *b) :Item_func(a,b) {} 00203 Item_real_func(List<Item> &list) :Item_func(list) {} 00204 String *val_str(String*str); 00205 my_decimal *val_decimal(my_decimal *decimal_value); 00206 longlong val_int() 00207 { DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); } 00208 enum Item_result result_type () const { return REAL_RESULT; } 00209 void fix_length_and_dec() 00210 { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); } 00211 }; 00212 00213 00214 class Item_func_numhybrid: public Item_func 00215 { 00216 protected: 00217 Item_result hybrid_type; 00218 public: 00219 Item_func_numhybrid(Item *a) :Item_func(a), hybrid_type(REAL_RESULT) 00220 {} 00221 Item_func_numhybrid(Item *a,Item *b) 00222 :Item_func(a,b), hybrid_type(REAL_RESULT) 00223 {} 00224 Item_func_numhybrid(List<Item> &list) 00225 :Item_func(list), hybrid_type(REAL_RESULT) 00226 {} 00227 00228 enum Item_result result_type () const { return hybrid_type; } 00229 void fix_length_and_dec(); 00230 void fix_num_length_and_dec(); 00231 virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */ 00232 00233 double val_real(); 00234 longlong val_int(); 00235 my_decimal *val_decimal(my_decimal *); 00236 String *val_str(String*str); 00237 00238 virtual longlong int_op()= 0; 00239 virtual double real_op()= 0; 00240 virtual my_decimal *decimal_op(my_decimal *)= 0; 00241 virtual String *str_op(String *)= 0; 00242 bool is_null() { (void) val_real(); return null_value; } 00243 }; 00244 00245 /* function where type of result detected by first argument */ 00246 class Item_func_num1: public Item_func_numhybrid 00247 { 00248 public: 00249 Item_func_num1(Item *a) :Item_func_numhybrid(a) {} 00250 Item_func_num1(Item *a, Item *b) :Item_func_numhybrid(a, b) {} 00251 00252 void fix_num_length_and_dec(); 00253 void find_num_type(); 00254 String *str_op(String *str) { DBUG_ASSERT(0); return 0; } 00255 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00256 }; 00257 00258 00259 /* Base class for operations like '+', '-', '*' */ 00260 class Item_num_op :public Item_func_numhybrid 00261 { 00262 public: 00263 Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {} 00264 virtual void result_precision()= 0; 00265 void print(String *str) { print_op(str); } 00266 void find_num_type(); 00267 String *str_op(String *str) { DBUG_ASSERT(0); return 0; } 00268 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00269 }; 00270 00271 00272 class Item_int_func :public Item_func 00273 { 00274 public: 00275 Item_int_func() :Item_func() { max_length= 21; } 00276 Item_int_func(Item *a) :Item_func(a) { max_length= 21; } 00277 Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; } 00278 Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) 00279 { max_length= 21; } 00280 Item_int_func(List<Item> &list) :Item_func(list) { max_length= 21; } 00281 Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {} 00282 double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); } 00283 String *val_str(String*str); 00284 enum Item_result result_type () const { return INT_RESULT; } 00285 void fix_length_and_dec() {} 00286 }; 00287 00288 00289 class Item_func_connection_id :public Item_int_func 00290 { 00291 longlong value; 00292 00293 public: 00294 Item_func_connection_id() {} 00295 const char *func_name() const { return "connection_id"; } 00296 void fix_length_and_dec(); 00297 bool fix_fields(THD *thd, Item **ref); 00298 longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } 00299 }; 00300 00301 00302 class Item_func_signed :public Item_int_func 00303 { 00304 public: 00305 Item_func_signed(Item *a) :Item_int_func(a) {} 00306 const char *func_name() const { return "cast_as_signed"; } 00307 double val_real() 00308 { 00309 double tmp= args[0]->val_real(); 00310 null_value= args[0]->null_value; 00311 return tmp; 00312 } 00313 longlong val_int(); 00314 longlong val_int_from_str(int *error); 00315 void fix_length_and_dec() 00316 { max_length=args[0]->max_length; unsigned_flag=0; } 00317 void print(String *str); 00318 uint decimal_precision() const { return args[0]->decimal_precision(); } 00319 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00320 }; 00321 00322 00323 class Item_func_unsigned :public Item_func_signed 00324 { 00325 public: 00326 Item_func_unsigned(Item *a) :Item_func_signed(a) {} 00327 const char *func_name() const { return "cast_as_unsigned"; } 00328 void fix_length_and_dec() 00329 { max_length=args[0]->max_length; unsigned_flag=1; } 00330 longlong val_int(); 00331 void print(String *str); 00332 }; 00333 00334 00335 class Item_decimal_typecast :public Item_func 00336 { 00337 my_decimal decimal_value; 00338 public: 00339 Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a) 00340 { 00341 max_length= len + 2; 00342 decimals= dec; 00343 } 00344 String *val_str(String *str); 00345 double val_real(); 00346 longlong val_int(); 00347 my_decimal *val_decimal(my_decimal*); 00348 enum Item_result result_type () const { return DECIMAL_RESULT; } 00349 enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } 00350 void fix_length_and_dec() {}; 00351 const char *func_name() const { return "decimal_typecast"; } 00352 void print(String *); 00353 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00354 }; 00355 00356 00357 class Item_func_additive_op :public Item_num_op 00358 { 00359 public: 00360 Item_func_additive_op(Item *a,Item *b) :Item_num_op(a,b) {} 00361 void result_precision(); 00362 }; 00363 00364 00365 class Item_func_plus :public Item_func_additive_op 00366 { 00367 public: 00368 Item_func_plus(Item *a,Item *b) :Item_func_additive_op(a,b) {} 00369 const char *func_name() const { return "+"; } 00370 longlong int_op(); 00371 double real_op(); 00372 my_decimal *decimal_op(my_decimal *); 00373 }; 00374 00375 class Item_func_minus :public Item_func_additive_op 00376 { 00377 public: 00378 Item_func_minus(Item *a,Item *b) :Item_func_additive_op(a,b) {} 00379 const char *func_name() const { return "-"; } 00380 longlong int_op(); 00381 double real_op(); 00382 my_decimal *decimal_op(my_decimal *); 00383 void fix_length_and_dec(); 00384 }; 00385 00386 00387 class Item_func_mul :public Item_num_op 00388 { 00389 public: 00390 Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {} 00391 const char *func_name() const { return "*"; } 00392 longlong int_op(); 00393 double real_op(); 00394 my_decimal *decimal_op(my_decimal *); 00395 void result_precision(); 00396 }; 00397 00398 00399 class Item_func_div :public Item_num_op 00400 { 00401 public: 00402 uint prec_increment; 00403 Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {} 00404 longlong int_op() { DBUG_ASSERT(0); return 0; } 00405 double real_op(); 00406 my_decimal *decimal_op(my_decimal *); 00407 const char *func_name() const { return "/"; } 00408 void fix_length_and_dec(); 00409 void result_precision(); 00410 }; 00411 00412 00413 class Item_func_int_div :public Item_int_func 00414 { 00415 public: 00416 Item_func_int_div(Item *a,Item *b) :Item_int_func(a,b) 00417 {} 00418 longlong val_int(); 00419 const char *func_name() const { return "DIV"; } 00420 void fix_length_and_dec(); 00421 void print(String *str) { print_op(str); } 00422 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00423 }; 00424 00425 00426 class Item_func_mod :public Item_num_op 00427 { 00428 public: 00429 Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {} 00430 longlong int_op(); 00431 double real_op(); 00432 my_decimal *decimal_op(my_decimal *); 00433 const char *func_name() const { return "%"; } 00434 void result_precision(); 00435 }; 00436 00437 00438 class Item_func_neg :public Item_func_num1 00439 { 00440 public: 00441 Item_func_neg(Item *a) :Item_func_num1(a) {} 00442 double real_op(); 00443 longlong int_op(); 00444 my_decimal *decimal_op(my_decimal *); 00445 const char *func_name() const { return "-"; } 00446 void fix_length_and_dec(); 00447 void fix_num_length_and_dec(); 00448 uint decimal_precision() const { return args[0]->decimal_precision(); } 00449 }; 00450 00451 00452 class Item_func_abs :public Item_func_num1 00453 { 00454 public: 00455 Item_func_abs(Item *a) :Item_func_num1(a) {} 00456 double real_op(); 00457 longlong int_op(); 00458 my_decimal *decimal_op(my_decimal *); 00459 const char *func_name() const { return "abs"; } 00460 void fix_length_and_dec(); 00461 }; 00462 00463 // A class to handle logarithmic and trigonometric functions 00464 00465 class Item_dec_func :public Item_real_func 00466 { 00467 public: 00468 Item_dec_func(Item *a) :Item_real_func(a) {} 00469 Item_dec_func(Item *a,Item *b) :Item_real_func(a,b) {} 00470 void fix_length_and_dec() 00471 { 00472 decimals=NOT_FIXED_DEC; max_length=float_length(decimals); 00473 maybe_null=1; 00474 } 00475 inline double fix_result(double value) 00476 { 00477 #ifndef HAVE_FINITE 00478 return value; 00479 #else 00480 /* The following should be safe, even if we compare doubles */ 00481 if (finite(value) && value != POSTFIX_ERROR) 00482 return value; 00483 null_value=1; 00484 return 0.0; 00485 #endif 00486 } 00487 }; 00488 00489 class Item_func_exp :public Item_dec_func 00490 { 00491 public: 00492 Item_func_exp(Item *a) :Item_dec_func(a) {} 00493 double val_real(); 00494 const char *func_name() const { return "exp"; } 00495 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00496 }; 00497 00498 00499 class Item_func_ln :public Item_dec_func 00500 { 00501 public: 00502 Item_func_ln(Item *a) :Item_dec_func(a) {} 00503 double val_real(); 00504 const char *func_name() const { return "ln"; } 00505 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00506 }; 00507 00508 00509 class Item_func_log :public Item_dec_func 00510 { 00511 public: 00512 Item_func_log(Item *a) :Item_dec_func(a) {} 00513 Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {} 00514 double val_real(); 00515 const char *func_name() const { return "log"; } 00516 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00517 }; 00518 00519 00520 class Item_func_log2 :public Item_dec_func 00521 { 00522 public: 00523 Item_func_log2(Item *a) :Item_dec_func(a) {} 00524 double val_real(); 00525 const char *func_name() const { return "log2"; } 00526 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00527 }; 00528 00529 00530 class Item_func_log10 :public Item_dec_func 00531 { 00532 public: 00533 Item_func_log10(Item *a) :Item_dec_func(a) {} 00534 double val_real(); 00535 const char *func_name() const { return "log10"; } 00536 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00537 }; 00538 00539 00540 class Item_func_sqrt :public Item_dec_func 00541 { 00542 public: 00543 Item_func_sqrt(Item *a) :Item_dec_func(a) {} 00544 double val_real(); 00545 const char *func_name() const { return "sqrt"; } 00546 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00547 }; 00548 00549 00550 class Item_func_pow :public Item_dec_func 00551 { 00552 public: 00553 Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {} 00554 double val_real(); 00555 const char *func_name() const { return "pow"; } 00556 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00557 }; 00558 00559 00560 class Item_func_acos :public Item_dec_func 00561 { 00562 public: 00563 Item_func_acos(Item *a) :Item_dec_func(a) {} 00564 double val_real(); 00565 const char *func_name() const { return "acos"; } 00566 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00567 }; 00568 00569 class Item_func_asin :public Item_dec_func 00570 { 00571 public: 00572 Item_func_asin(Item *a) :Item_dec_func(a) {} 00573 double val_real(); 00574 const char *func_name() const { return "asin"; } 00575 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00576 }; 00577 00578 class Item_func_atan :public Item_dec_func 00579 { 00580 public: 00581 Item_func_atan(Item *a) :Item_dec_func(a) {} 00582 Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {} 00583 double val_real(); 00584 const char *func_name() const { return "atan"; } 00585 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00586 }; 00587 00588 class Item_func_cos :public Item_dec_func 00589 { 00590 public: 00591 Item_func_cos(Item *a) :Item_dec_func(a) {} 00592 double val_real(); 00593 const char *func_name() const { return "cos"; } 00594 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00595 }; 00596 00597 class Item_func_sin :public Item_dec_func 00598 { 00599 public: 00600 Item_func_sin(Item *a) :Item_dec_func(a) {} 00601 double val_real(); 00602 const char *func_name() const { return "sin"; } 00603 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00604 }; 00605 00606 class Item_func_tan :public Item_dec_func 00607 { 00608 public: 00609 Item_func_tan(Item *a) :Item_dec_func(a) {} 00610 double val_real(); 00611 const char *func_name() const { return "tan"; } 00612 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00613 }; 00614 00615 class Item_func_integer :public Item_int_func 00616 { 00617 public: 00618 inline Item_func_integer(Item *a) :Item_int_func(a) {} 00619 void fix_length_and_dec(); 00620 }; 00621 00622 00623 class Item_func_int_val :public Item_func_num1 00624 { 00625 public: 00626 Item_func_int_val(Item *a) :Item_func_num1(a) {} 00627 void fix_num_length_and_dec(); 00628 void find_num_type(); 00629 }; 00630 00631 00632 class Item_func_ceiling :public Item_func_int_val 00633 { 00634 public: 00635 Item_func_ceiling(Item *a) :Item_func_int_val(a) {} 00636 const char *func_name() const { return "ceiling"; } 00637 longlong int_op(); 00638 double real_op(); 00639 my_decimal *decimal_op(my_decimal *); 00640 }; 00641 00642 00643 class Item_func_floor :public Item_func_int_val 00644 { 00645 public: 00646 Item_func_floor(Item *a) :Item_func_int_val(a) {} 00647 const char *func_name() const { return "floor"; } 00648 longlong int_op(); 00649 double real_op(); 00650 my_decimal *decimal_op(my_decimal *); 00651 }; 00652 00653 /* This handles round and truncate */ 00654 00655 class Item_func_round :public Item_func_num1 00656 { 00657 bool truncate; 00658 public: 00659 Item_func_round(Item *a, Item *b, bool trunc_arg) 00660 :Item_func_num1(a,b), truncate(trunc_arg) {} 00661 const char *func_name() const { return truncate ? "truncate" : "round"; } 00662 double real_op(); 00663 longlong int_op(); 00664 my_decimal *decimal_op(my_decimal *); 00665 void fix_length_and_dec(); 00666 }; 00667 00668 00669 class Item_func_rand :public Item_real_func 00670 { 00671 struct rand_struct *rand; 00672 public: 00673 Item_func_rand(Item *a) :Item_real_func(a), rand(0) {} 00674 Item_func_rand() :Item_real_func() {} 00675 double val_real(); 00676 const char *func_name() const { return "rand"; } 00677 bool const_item() const { return 0; } 00678 void update_used_tables(); 00679 bool fix_fields(THD *thd, Item **ref); 00680 }; 00681 00682 00683 class Item_func_sign :public Item_int_func 00684 { 00685 public: 00686 Item_func_sign(Item *a) :Item_int_func(a) {} 00687 const char *func_name() const { return "sign"; } 00688 longlong val_int(); 00689 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00690 }; 00691 00692 00693 class Item_func_units :public Item_real_func 00694 { 00695 char *name; 00696 double mul,add; 00697 public: 00698 Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg) 00699 :Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {} 00700 double val_real(); 00701 const char *func_name() const { return name; } 00702 void fix_length_and_dec() 00703 { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); } 00704 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00705 }; 00706 00707 00708 class Item_func_min_max :public Item_func 00709 { 00710 Item_result cmp_type; 00711 String tmp_value; 00712 int cmp_sign; 00713 public: 00714 Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list), 00715 cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg) {} 00716 double val_real(); 00717 longlong val_int(); 00718 String *val_str(String *); 00719 my_decimal *val_decimal(my_decimal *); 00720 void fix_length_and_dec(); 00721 enum Item_result result_type () const { return cmp_type; } 00722 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00723 }; 00724 00725 class Item_func_min :public Item_func_min_max 00726 { 00727 public: 00728 Item_func_min(List<Item> &list) :Item_func_min_max(list,1) {} 00729 const char *func_name() const { return "least"; } 00730 }; 00731 00732 class Item_func_max :public Item_func_min_max 00733 { 00734 public: 00735 Item_func_max(List<Item> &list) :Item_func_min_max(list,-1) {} 00736 const char *func_name() const { return "greatest"; } 00737 }; 00738 00739 00740 class Item_func_length :public Item_int_func 00741 { 00742 String value; 00743 public: 00744 Item_func_length(Item *a) :Item_int_func(a) {} 00745 longlong val_int(); 00746 const char *func_name() const { return "length"; } 00747 void fix_length_and_dec() { max_length=10; } 00748 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00749 }; 00750 00751 class Item_func_bit_length :public Item_func_length 00752 { 00753 public: 00754 Item_func_bit_length(Item *a) :Item_func_length(a) {} 00755 longlong val_int() 00756 { DBUG_ASSERT(fixed == 1); return Item_func_length::val_int()*8; } 00757 const char *func_name() const { return "bit_length"; } 00758 }; 00759 00760 class Item_func_char_length :public Item_int_func 00761 { 00762 String value; 00763 public: 00764 Item_func_char_length(Item *a) :Item_int_func(a) {} 00765 longlong val_int(); 00766 const char *func_name() const { return "char_length"; } 00767 void fix_length_and_dec() { max_length=10; } 00768 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00769 }; 00770 00771 class Item_func_coercibility :public Item_int_func 00772 { 00773 public: 00774 Item_func_coercibility(Item *a) :Item_int_func(a) {} 00775 longlong val_int(); 00776 const char *func_name() const { return "coercibility"; } 00777 void fix_length_and_dec() { max_length=10; maybe_null= 0; } 00778 table_map not_null_tables() const { return 0; } 00779 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00780 }; 00781 00782 class Item_func_locate :public Item_int_func 00783 { 00784 String value1,value2; 00785 DTCollation cmp_collation; 00786 public: 00787 Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {} 00788 Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {} 00789 const char *func_name() const { return "locate"; } 00790 longlong val_int(); 00791 void fix_length_and_dec(); 00792 void print(String *str); 00793 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00794 }; 00795 00796 00797 class Item_func_field :public Item_int_func 00798 { 00799 String value,tmp; 00800 Item_result cmp_type; 00801 DTCollation cmp_collation; 00802 public: 00803 Item_func_field(List<Item> &list) :Item_int_func(list) {} 00804 longlong val_int(); 00805 const char *func_name() const { return "field"; } 00806 void fix_length_and_dec(); 00807 }; 00808 00809 00810 class Item_func_ascii :public Item_int_func 00811 { 00812 String value; 00813 public: 00814 Item_func_ascii(Item *a) :Item_int_func(a) {} 00815 longlong val_int(); 00816 const char *func_name() const { return "ascii"; } 00817 void fix_length_and_dec() { max_length=3; } 00818 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00819 }; 00820 00821 class Item_func_ord :public Item_int_func 00822 { 00823 String value; 00824 public: 00825 Item_func_ord(Item *a) :Item_int_func(a) {} 00826 longlong val_int(); 00827 const char *func_name() const { return "ord"; } 00828 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00829 }; 00830 00831 class Item_func_find_in_set :public Item_int_func 00832 { 00833 String value,value2; 00834 uint enum_value; 00835 ulonglong enum_bit; 00836 DTCollation cmp_collation; 00837 public: 00838 Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {} 00839 longlong val_int(); 00840 const char *func_name() const { return "find_in_set"; } 00841 void fix_length_and_dec(); 00842 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00843 }; 00844 00845 /* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */ 00846 00847 class Item_func_bit: public Item_int_func 00848 { 00849 public: 00850 Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {} 00851 Item_func_bit(Item *a) :Item_int_func(a) {} 00852 void fix_length_and_dec() { unsigned_flag= 1; } 00853 void print(String *str) { print_op(str); } 00854 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00855 }; 00856 00857 class Item_func_bit_or :public Item_func_bit 00858 { 00859 public: 00860 Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {} 00861 longlong val_int(); 00862 const char *func_name() const { return "|"; } 00863 }; 00864 00865 class Item_func_bit_and :public Item_func_bit 00866 { 00867 public: 00868 Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {} 00869 longlong val_int(); 00870 const char *func_name() const { return "&"; } 00871 }; 00872 00873 class Item_func_bit_count :public Item_int_func 00874 { 00875 public: 00876 Item_func_bit_count(Item *a) :Item_int_func(a) {} 00877 longlong val_int(); 00878 const char *func_name() const { return "bit_count"; } 00879 void fix_length_and_dec() { max_length=2; } 00880 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00881 }; 00882 00883 class Item_func_shift_left :public Item_func_bit 00884 { 00885 public: 00886 Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {} 00887 longlong val_int(); 00888 const char *func_name() const { return "<<"; } 00889 }; 00890 00891 class Item_func_shift_right :public Item_func_bit 00892 { 00893 public: 00894 Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {} 00895 longlong val_int(); 00896 const char *func_name() const { return ">>"; } 00897 }; 00898 00899 class Item_func_bit_neg :public Item_func_bit 00900 { 00901 public: 00902 Item_func_bit_neg(Item *a) :Item_func_bit(a) {} 00903 longlong val_int(); 00904 const char *func_name() const { return "~"; } 00905 void print(String *str) { Item_func::print(str); } 00906 }; 00907 00908 00909 class Item_func_last_insert_id :public Item_int_func 00910 { 00911 public: 00912 Item_func_last_insert_id() :Item_int_func() {} 00913 Item_func_last_insert_id(Item *a) :Item_int_func(a) {} 00914 longlong val_int(); 00915 const char *func_name() const { return "last_insert_id"; } 00916 void fix_length_and_dec() 00917 { 00918 if (arg_count) 00919 max_length= args[0]->max_length; 00920 } 00921 }; 00922 00923 00924 class Item_func_benchmark :public Item_int_func 00925 { 00926 ulong loop_count; 00927 public: 00928 Item_func_benchmark(ulong loop_count_arg,Item *expr) 00929 :Item_int_func(expr), loop_count(loop_count_arg) 00930 {} 00931 longlong val_int(); 00932 const char *func_name() const { return "benchmark"; } 00933 void fix_length_and_dec() { max_length=1; maybe_null=0; } 00934 void print(String *str); 00935 }; 00936 00937 00938 class Item_func_sleep :public Item_int_func 00939 { 00940 public: 00941 Item_func_sleep(Item *a) :Item_int_func(a) {} 00942 bool const_item() const { return 0; } 00943 const char *func_name() const { return "sleep"; } 00944 void update_used_tables() 00945 { 00946 Item_int_func::update_used_tables(); 00947 used_tables_cache|= RAND_TABLE_BIT; 00948 } 00949 longlong val_int(); 00950 }; 00951 00952 00953 00954 #ifdef HAVE_DLOPEN 00955 00956 class Item_udf_func :public Item_func 00957 { 00958 protected: 00959 udf_handler udf; 00960 00961 public: 00962 Item_udf_func(udf_func *udf_arg) 00963 :Item_func(), udf(udf_arg) {} 00964 Item_udf_func(udf_func *udf_arg, List<Item> &list) 00965 :Item_func(list), udf(udf_arg) {} 00966 const char *func_name() const { return udf.name(); } 00967 enum Functype functype() const { return UDF_FUNC; } 00968 bool fix_fields(THD *thd, Item **ref) 00969 { 00970 DBUG_ASSERT(fixed == 0); 00971 bool res= udf.fix_fields(thd, this, arg_count, args); 00972 used_tables_cache= udf.used_tables_cache; 00973 const_item_cache= udf.const_item_cache; 00974 fixed= 1; 00975 return res; 00976 } 00977 void cleanup(); 00978 Item_result result_type () const { return udf.result_type(); } 00979 table_map not_null_tables() const { return 0; } 00980 bool is_expensive() { return 1; } 00981 }; 00982 00983 00984 class Item_func_udf_float :public Item_udf_func 00985 { 00986 public: 00987 Item_func_udf_float(udf_func *udf_arg) 00988 :Item_udf_func(udf_arg) {} 00989 Item_func_udf_float(udf_func *udf_arg, 00990 List<Item> &list) 00991 :Item_udf_func(udf_arg, list) {} 00992 longlong val_int() 00993 { 00994 DBUG_ASSERT(fixed == 1); 00995 return (longlong) rint(Item_func_udf_float::val_real()); 00996 } 00997 my_decimal *val_decimal(my_decimal *dec_buf) 00998 { 00999 double res=val_real(); 01000 if (null_value) 01001 return NULL; 01002 double2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf); 01003 return dec_buf; 01004 } 01005 double val_real(); 01006 String *val_str(String *str); 01007 void fix_length_and_dec() { fix_num_length_and_dec(); } 01008 }; 01009 01010 01011 class Item_func_udf_int :public Item_udf_func 01012 { 01013 public: 01014 Item_func_udf_int(udf_func *udf_arg) 01015 :Item_udf_func(udf_arg) {} 01016 Item_func_udf_int(udf_func *udf_arg, 01017 List<Item> &list) 01018 :Item_udf_func(udf_arg, list) {} 01019 longlong val_int(); 01020 double val_real() { return (double) Item_func_udf_int::val_int(); } 01021 String *val_str(String *str); 01022 enum Item_result result_type () const { return INT_RESULT; } 01023 void fix_length_and_dec() { decimals= 0; max_length= 21; } 01024 }; 01025 01026 01027 class Item_func_udf_decimal :public Item_udf_func 01028 { 01029 public: 01030 Item_func_udf_decimal(udf_func *udf_arg) 01031 :Item_udf_func(udf_arg) {} 01032 Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list) 01033 :Item_udf_func(udf_arg, list) {} 01034 longlong val_int(); 01035 double val_real(); 01036 my_decimal *val_decimal(my_decimal *); 01037 String *val_str(String *str); 01038 enum Item_result result_type () const { return DECIMAL_RESULT; } 01039 void fix_length_and_dec(); 01040 }; 01041 01042 01043 class Item_func_udf_str :public Item_udf_func 01044 { 01045 public: 01046 Item_func_udf_str(udf_func *udf_arg) 01047 :Item_udf_func(udf_arg) {} 01048 Item_func_udf_str(udf_func *udf_arg, List<Item> &list) 01049 :Item_udf_func(udf_arg, list) {} 01050 String *val_str(String *); 01051 double val_real() 01052 { 01053 int err_not_used; 01054 char *end_not_used; 01055 String *res; 01056 res= val_str(&str_value); 01057 return res ? my_strntod(res->charset(),(char*) res->ptr(), 01058 res->length(), &end_not_used, &err_not_used) : 0.0; 01059 } 01060 longlong val_int() 01061 { 01062 int err_not_used; 01063 String *res; res=val_str(&str_value); 01064 return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10, 01065 (char**) 0, &err_not_used) : (longlong) 0; 01066 } 01067 my_decimal *val_decimal(my_decimal *dec_buf) 01068 { 01069 String *res=val_str(&str_value); 01070 if (!res) 01071 return NULL; 01072 string2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf); 01073 return dec_buf; 01074 } 01075 enum Item_result result_type () const { return STRING_RESULT; } 01076 void fix_length_and_dec(); 01077 }; 01078 01079 #else /* Dummy functions to get sql_yacc.cc compiled */ 01080 01081 class Item_func_udf_float :public Item_real_func 01082 { 01083 public: 01084 Item_func_udf_float(udf_func *udf_arg) 01085 :Item_real_func() {} 01086 Item_func_udf_float(udf_func *udf_arg, List<Item> &list) 01087 :Item_real_func(list) {} 01088 double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; } 01089 }; 01090 01091 01092 class Item_func_udf_int :public Item_int_func 01093 { 01094 public: 01095 Item_func_udf_int(udf_func *udf_arg) 01096 :Item_int_func() {} 01097 Item_func_udf_int(udf_func *udf_arg, List<Item> &list) 01098 :Item_int_func(list) {} 01099 longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; } 01100 }; 01101 01102 01103 class Item_func_udf_decimal :public Item_int_func 01104 { 01105 public: 01106 Item_func_udf_decimal(udf_func *udf_arg) 01107 :Item_int_func() {} 01108 Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list) 01109 :Item_int_func(list) {} 01110 my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; } 01111 }; 01112 01113 01114 class Item_func_udf_str :public Item_func 01115 { 01116 public: 01117 Item_func_udf_str(udf_func *udf_arg) 01118 :Item_func() {} 01119 Item_func_udf_str(udf_func *udf_arg, List<Item> &list) 01120 :Item_func(list) {} 01121 String *val_str(String *) 01122 { DBUG_ASSERT(fixed == 1); null_value=1; return 0; } 01123 double val_real() { DBUG_ASSERT(fixed == 1); null_value= 1; return 0.0; } 01124 longlong val_int() { DBUG_ASSERT(fixed == 1); null_value=1; return 0; } 01125 enum Item_result result_type () const { return STRING_RESULT; } 01126 void fix_length_and_dec() { maybe_null=1; max_length=0; } 01127 }; 01128 01129 #endif /* HAVE_DLOPEN */ 01130 01131 /* 01132 ** User level locks 01133 */ 01134 01135 class User_level_lock; 01136 void item_user_lock_init(void); 01137 void item_user_lock_release(User_level_lock *ull); 01138 void item_user_lock_free(void); 01139 01140 class Item_func_get_lock :public Item_int_func 01141 { 01142 String value; 01143 public: 01144 Item_func_get_lock(Item *a,Item *b) :Item_int_func(a,b) {} 01145 longlong val_int(); 01146 const char *func_name() const { return "get_lock"; } 01147 void fix_length_and_dec() { max_length=1; maybe_null=1;} 01148 }; 01149 01150 class Item_func_release_lock :public Item_int_func 01151 { 01152 String value; 01153 public: 01154 Item_func_release_lock(Item *a) :Item_int_func(a) {} 01155 longlong val_int(); 01156 const char *func_name() const { return "release_lock"; } 01157 void fix_length_and_dec() { max_length=1; maybe_null=1;} 01158 }; 01159 01160 /* replication functions */ 01161 01162 class Item_master_pos_wait :public Item_int_func 01163 { 01164 String value; 01165 public: 01166 Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {} 01167 Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {} 01168 longlong val_int(); 01169 const char *func_name() const { return "master_pos_wait"; } 01170 void fix_length_and_dec() { max_length=21; maybe_null=1;} 01171 }; 01172 01173 01174 /* Handling of user definable variables */ 01175 01176 class user_var_entry; 01177 01178 class Item_func_set_user_var :public Item_func 01179 { 01180 enum Item_result cached_result_type; 01181 user_var_entry *entry; 01182 char buffer[MAX_FIELD_WIDTH]; 01183 String value; 01184 my_decimal decimal_buff; 01185 bool null_item; 01186 union 01187 { 01188 longlong vint; 01189 double vreal; 01190 String *vstr; 01191 my_decimal *vdec; 01192 } save_result; 01193 01194 public: 01195 LEX_STRING name; // keep it public 01196 Item_func_set_user_var(LEX_STRING a,Item *b) 01197 :Item_func(b), cached_result_type(INT_RESULT), name(a) 01198 {} 01199 double val_real(); 01200 longlong val_int(); 01201 String *val_str(String *str); 01202 my_decimal *val_decimal(my_decimal *); 01203 bool update_hash(void *ptr, uint length, enum Item_result type, 01204 CHARSET_INFO *cs, Derivation dv, bool unsigned_arg= 0); 01205 bool check(); 01206 bool update(); 01207 enum Item_result result_type () const { return cached_result_type; } 01208 bool fix_fields(THD *thd, Item **ref); 01209 void fix_length_and_dec(); 01210 void print(String *str); 01211 void print_as_stmt(String *str); 01212 const char *func_name() const { return "set_user_var"; } 01213 }; 01214 01215 01216 class Item_func_get_user_var :public Item_func, 01217 private Settable_routine_parameter 01218 { 01219 user_var_entry *var_entry; 01220 01221 public: 01222 LEX_STRING name; // keep it public 01223 Item_func_get_user_var(LEX_STRING a): 01224 Item_func(), name(a) {} 01225 enum Functype functype() const { return GUSERVAR_FUNC; } 01226 LEX_STRING get_name() { return name; } 01227 double val_real(); 01228 longlong val_int(); 01229 my_decimal *val_decimal(my_decimal*); 01230 String *val_str(String* str); 01231 void fix_length_and_dec(); 01232 void print(String *str); 01233 enum Item_result result_type() const; 01234 /* 01235 We must always return variables as strings to guard against selects of type 01236 select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b) 01237 */ 01238 enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } 01239 const char *func_name() const { return "get_user_var"; } 01240 bool const_item() const; 01241 table_map used_tables() const 01242 { return const_item() ? 0 : RAND_TABLE_BIT; } 01243 bool eq(const Item *item, bool binary_cmp) const; 01244 01245 private: 01246 bool set_value(THD *thd, sp_rcontext *ctx, Item **it); 01247 01248 public: 01249 Settable_routine_parameter *get_settable_routine_parameter() 01250 { 01251 return this; 01252 } 01253 }; 01254 01255 01256 /* 01257 This item represents user variable used as out parameter (e.g in LOAD DATA), 01258 and it is supposed to be used only for this purprose. So it is simplified 01259 a lot. Actually you should never obtain its value. 01260 01261 The only two reasons for this thing being an Item is possibility to store it 01262 in List<Item> and desire to place this code somewhere near other functions 01263 working with user variables. 01264 */ 01265 class Item_user_var_as_out_param :public Item 01266 { 01267 LEX_STRING name; 01268 user_var_entry *entry; 01269 public: 01270 Item_user_var_as_out_param(LEX_STRING a) : name(a) {} 01271 /* We should return something different from FIELD_ITEM here */ 01272 enum Type type() const { return STRING_ITEM;} 01273 double val_real(); 01274 longlong val_int(); 01275 String *val_str(String *str); 01276 my_decimal *val_decimal(my_decimal *decimal_buffer); 01277 /* fix_fields() binds variable name with its entry structure */ 01278 bool fix_fields(THD *thd, Item **ref); 01279 void print(String *str); 01280 void set_null_value(CHARSET_INFO* cs); 01281 void set_value(const char *str, uint length, CHARSET_INFO* cs); 01282 }; 01283 01284 01285 /* A system variable */ 01286 01287 class Item_func_get_system_var :public Item_func 01288 { 01289 sys_var *var; 01290 enum_var_type var_type; 01291 LEX_STRING component; 01292 public: 01293 Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg, 01294 LEX_STRING *component_arg, const char *name_arg, 01295 size_t name_len_arg); 01296 bool fix_fields(THD *thd, Item **ref); 01297 /* 01298 Stubs for pure virtual methods. Should never be called: this 01299 item is always substituted with a constant in fix_fields(). 01300 */ 01301 double val_real() { DBUG_ASSERT(0); return 0.0; } 01302 longlong val_int() { DBUG_ASSERT(0); return 0; } 01303 String* val_str(String*) { DBUG_ASSERT(0); return 0; } 01304 void fix_length_and_dec() { DBUG_ASSERT(0); } 01305 /* TODO: fix to support views */ 01306 const char *func_name() const { return "get_system_var"; } 01307 }; 01308 01309 01310 class Item_func_inet_aton : public Item_int_func 01311 { 01312 public: 01313 Item_func_inet_aton(Item *a) :Item_int_func(a) {} 01314 longlong val_int(); 01315 const char *func_name() const { return "inet_aton"; } 01316 void fix_length_and_dec() { decimals = 0; max_length = 21; maybe_null=1;} 01317 bool check_partition_func_processor(byte *bool_arg) { return 0;} 01318 }; 01319 01320 01321 /* for fulltext search */ 01322 #include <ft_global.h> 01323 01324 class Item_func_match :public Item_real_func 01325 { 01326 public: 01327 uint key, flags; 01328 bool join_key; 01329 DTCollation cmp_collation; 01330 FT_INFO *ft_handler; 01331 TABLE *table; 01332 Item_func_match *master; // for master-slave optimization 01333 Item *concat; // Item_func_concat_ws 01334 String value; // value of concat 01335 String search_value; // key_item()'s value converted to cmp_collation 01336 01337 Item_func_match(List<Item> &a, uint b): Item_real_func(a), key(0), flags(b), 01338 join_key(0), ft_handler(0), table(0), master(0), concat(0) { } 01339 void cleanup() 01340 { 01341 DBUG_ENTER("Item_func_match"); 01342 Item_real_func::cleanup(); 01343 if (!master && ft_handler) 01344 ft_handler->please->close_search(ft_handler); 01345 ft_handler= 0; 01346 concat= 0; 01347 DBUG_VOID_RETURN; 01348 } 01349 enum Functype functype() const { return FT_FUNC; } 01350 const char *func_name() const { return "match"; } 01351 void update_used_tables() {} 01352 table_map not_null_tables() const { return 0; } 01353 bool fix_fields(THD *thd, Item **ref); 01354 bool eq(const Item *, bool binary_cmp) const; 01355 /* The following should be safe, even if we compare doubles */ 01356 longlong val_int() { DBUG_ASSERT(fixed == 1); return val_real() != 0.0; } 01357 double val_real(); 01358 void print(String *str); 01359 01360 bool fix_index(); 01361 void init_search(bool no_order); 01362 }; 01363 01364 01365 class Item_func_bit_xor : public Item_func_bit 01366 { 01367 public: 01368 Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {} 01369 longlong val_int(); 01370 const char *func_name() const { return "^"; } 01371 }; 01372 01373 class Item_func_is_free_lock :public Item_int_func 01374 { 01375 String value; 01376 public: 01377 Item_func_is_free_lock(Item *a) :Item_int_func(a) {} 01378 longlong val_int(); 01379 const char *func_name() const { return "is_free_lock"; } 01380 void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} 01381 }; 01382 01383 class Item_func_is_used_lock :public Item_int_func 01384 { 01385 String value; 01386 public: 01387 Item_func_is_used_lock(Item *a) :Item_int_func(a) {} 01388 longlong val_int(); 01389 const char *func_name() const { return "is_used_lock"; } 01390 void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;} 01391 }; 01392 01393 /* For type casts */ 01394 01395 enum Cast_target 01396 { 01397 ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT, 01398 ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR, 01399 ITEM_CAST_DECIMAL 01400 }; 01401 01402 01403 class Item_func_row_count :public Item_int_func 01404 { 01405 public: 01406 Item_func_row_count() :Item_int_func() {} 01407 longlong val_int(); 01408 const char *func_name() const { return "row_count"; } 01409 void fix_length_and_dec() { decimals= 0; maybe_null=0; } 01410 }; 01411 01412 01413 /* 01414 * 01415 * Stored FUNCTIONs 01416 * 01417 */ 01418 01419 class sp_head; 01420 class sp_name; 01421 struct st_sp_security_context; 01422 01423 class Item_func_sp :public Item_func 01424 { 01425 private: 01426 Name_resolution_context *context; 01427 sp_name *m_name; 01428 mutable sp_head *m_sp; 01429 TABLE *dummy_table; 01430 Field *result_field; 01431 char result_buf[64]; 01432 01433 bool execute(Field **flp); 01434 bool execute_impl(THD *thd, Field *return_value_fld); 01435 Field *sp_result_field(void) const; 01436 01437 public: 01438 01439 Item_func_sp(Name_resolution_context *context_arg, sp_name *name); 01440 01441 Item_func_sp(Name_resolution_context *context_arg, 01442 sp_name *name, List<Item> &list); 01443 01444 virtual ~Item_func_sp() 01445 {} 01446 01447 void cleanup(); 01448 01449 const char *func_name() const; 01450 01451 enum enum_field_types field_type() const; 01452 01453 Field *tmp_table_field(TABLE *t_arg); 01454 01455 void make_field(Send_field *tmp_field); 01456 01457 Item_result result_type() const; 01458 01459 longlong val_int() 01460 { 01461 if (execute(&result_field)) 01462 return (longlong) 0; 01463 return result_field->val_int(); 01464 } 01465 01466 double val_real() 01467 { 01468 if (execute(&result_field)) 01469 return 0.0; 01470 return result_field->val_real(); 01471 } 01472 01473 my_decimal *val_decimal(my_decimal *dec_buf) 01474 { 01475 if (execute(&result_field)) 01476 return NULL; 01477 return result_field->val_decimal(dec_buf); 01478 } 01479 01480 String *val_str(String *str) 01481 { 01482 String buf; 01483 char buff[20]; 01484 buf.set(buff, 20, str->charset()); 01485 buf.length(0); 01486 if (execute(&result_field)) 01487 return NULL; 01488 /* 01489 result_field will set buf pointing to internal buffer 01490 of the resul_field. Due to this it will change any time 01491 when SP is executed. In order to prevent occasional 01492 corruption of returned value, we make here a copy. 01493 */ 01494 result_field->val_str(&buf); 01495 str->copy(buf); 01496 return str; 01497 } 01498 01499 virtual bool change_context_processor(byte *cntx) 01500 { context= (Name_resolution_context *)cntx; return FALSE; } 01501 01502 void fix_length_and_dec(); 01503 bool find_and_check_access(THD * thd); 01504 virtual enum Functype functype() const { return FUNC_SP; } 01505 01506 bool fix_fields(THD *thd, Item **ref); 01507 bool is_expensive() { return 1; } 01508 }; 01509 01510 01511 class Item_func_found_rows :public Item_int_func 01512 { 01513 public: 01514 Item_func_found_rows() :Item_int_func() {} 01515 longlong val_int(); 01516 const char *func_name() const { return "found_rows"; } 01517 void fix_length_and_dec() { decimals= 0; maybe_null=0; } 01518 };
1.4.7

