00001 /* Copyright (C) 2000-2003 MySQL 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 /* This file defines all string functions */ 00019 00020 #ifdef USE_PRAGMA_INTERFACE 00021 #pragma interface /* gcc class implementation */ 00022 #endif 00023 00024 class Item_str_func :public Item_func 00025 { 00026 public: 00027 Item_str_func() :Item_func() { decimals=NOT_FIXED_DEC; } 00028 Item_str_func(Item *a) :Item_func(a) {decimals=NOT_FIXED_DEC; } 00029 Item_str_func(Item *a,Item *b) :Item_func(a,b) { decimals=NOT_FIXED_DEC; } 00030 Item_str_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) { decimals=NOT_FIXED_DEC; } 00031 Item_str_func(Item *a,Item *b,Item *c,Item *d) :Item_func(a,b,c,d) {decimals=NOT_FIXED_DEC; } 00032 Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e) {decimals=NOT_FIXED_DEC; } 00033 Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; } 00034 longlong val_int(); 00035 double val_real(); 00036 my_decimal *val_decimal(my_decimal *); 00037 enum Item_result result_type () const { return STRING_RESULT; } 00038 void left_right_max_length(); 00039 String *check_well_formed_result(String *str); 00040 }; 00041 00042 class Item_func_md5 :public Item_str_func 00043 { 00044 String tmp_value; 00045 public: 00046 Item_func_md5(Item *a) :Item_str_func(a) {} 00047 String *val_str(String *); 00048 void fix_length_and_dec(); 00049 const char *func_name() const { return "md5"; } 00050 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00051 }; 00052 00053 00054 class Item_func_sha :public Item_str_func 00055 { 00056 public: 00057 Item_func_sha(Item *a) :Item_str_func(a) {} 00058 String *val_str(String *); 00059 void fix_length_and_dec(); 00060 const char *func_name() const { return "sha"; } 00061 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00062 }; 00063 00064 class Item_func_aes_encrypt :public Item_str_func 00065 { 00066 public: 00067 Item_func_aes_encrypt(Item *a, Item *b) :Item_str_func(a,b) {} 00068 String *val_str(String *); 00069 void fix_length_and_dec(); 00070 const char *func_name() const { return "aes_encrypt"; } 00071 }; 00072 00073 class Item_func_aes_decrypt :public Item_str_func 00074 { 00075 public: 00076 Item_func_aes_decrypt(Item *a, Item *b) :Item_str_func(a,b) {} 00077 String *val_str(String *); 00078 void fix_length_and_dec(); 00079 const char *func_name() const { return "aes_decrypt"; } 00080 }; 00081 00082 00083 class Item_func_concat :public Item_str_func 00084 { 00085 String tmp_value; 00086 public: 00087 Item_func_concat(List<Item> &list) :Item_str_func(list) {} 00088 Item_func_concat(Item *a,Item *b) :Item_str_func(a,b) {} 00089 String *val_str(String *); 00090 void fix_length_and_dec(); 00091 const char *func_name() const { return "concat"; } 00092 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00093 }; 00094 00095 class Item_func_concat_ws :public Item_str_func 00096 { 00097 String tmp_value; 00098 public: 00099 Item_func_concat_ws(List<Item> &list) :Item_str_func(list) {} 00100 String *val_str(String *); 00101 void fix_length_and_dec(); 00102 const char *func_name() const { return "concat_ws"; } 00103 table_map not_null_tables() const { return 0; } 00104 }; 00105 00106 class Item_func_reverse :public Item_str_func 00107 { 00108 String tmp_value; 00109 public: 00110 Item_func_reverse(Item *a) :Item_str_func(a) {} 00111 String *val_str(String *); 00112 void fix_length_and_dec(); 00113 const char *func_name() const { return "reverse"; } 00114 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00115 }; 00116 00117 00118 class Item_func_replace :public Item_str_func 00119 { 00120 String tmp_value,tmp_value2; 00121 public: 00122 Item_func_replace(Item *org,Item *find,Item *replace) 00123 :Item_str_func(org,find,replace) {} 00124 String *val_str(String *); 00125 void fix_length_and_dec(); 00126 const char *func_name() const { return "replace"; } 00127 }; 00128 00129 00130 class Item_func_insert :public Item_str_func 00131 { 00132 String tmp_value; 00133 public: 00134 Item_func_insert(Item *org,Item *start,Item *length,Item *new_str) 00135 :Item_str_func(org,start,length,new_str) {} 00136 String *val_str(String *); 00137 void fix_length_and_dec(); 00138 const char *func_name() const { return "insert"; } 00139 }; 00140 00141 00142 class Item_str_conv :public Item_str_func 00143 { 00144 protected: 00145 uint multiply; 00146 uint (*converter)(CHARSET_INFO *cs, char *src, uint srclen, 00147 char *dst, uint dstlen); 00148 String tmp_value; 00149 public: 00150 Item_str_conv(Item *item) :Item_str_func(item) {} 00151 String *val_str(String *); 00152 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00153 }; 00154 00155 00156 class Item_func_lcase :public Item_str_conv 00157 { 00158 public: 00159 Item_func_lcase(Item *item) :Item_str_conv(item) {} 00160 const char *func_name() const { return "lcase"; } 00161 void fix_length_and_dec() 00162 { 00163 collation.set(args[0]->collation); 00164 multiply= collation.collation->casedn_multiply; 00165 converter= collation.collation->cset->casedn; 00166 max_length= args[0]->max_length * multiply; 00167 } 00168 }; 00169 00170 class Item_func_ucase :public Item_str_conv 00171 { 00172 public: 00173 Item_func_ucase(Item *item) :Item_str_conv(item) {} 00174 const char *func_name() const { return "ucase"; } 00175 void fix_length_and_dec() 00176 { 00177 collation.set(args[0]->collation); 00178 multiply= collation.collation->caseup_multiply; 00179 converter= collation.collation->cset->caseup; 00180 max_length= args[0]->max_length * multiply; 00181 } 00182 }; 00183 00184 00185 class Item_func_left :public Item_str_func 00186 { 00187 String tmp_value; 00188 public: 00189 Item_func_left(Item *a,Item *b) :Item_str_func(a,b) {} 00190 String *val_str(String *); 00191 void fix_length_and_dec(); 00192 const char *func_name() const { return "left"; } 00193 }; 00194 00195 00196 class Item_func_right :public Item_str_func 00197 { 00198 String tmp_value; 00199 public: 00200 Item_func_right(Item *a,Item *b) :Item_str_func(a,b) {} 00201 String *val_str(String *); 00202 void fix_length_and_dec(); 00203 const char *func_name() const { return "right"; } 00204 }; 00205 00206 00207 class Item_func_substr :public Item_str_func 00208 { 00209 String tmp_value; 00210 public: 00211 Item_func_substr(Item *a,Item *b) :Item_str_func(a,b) {} 00212 Item_func_substr(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} 00213 String *val_str(String *); 00214 void fix_length_and_dec(); 00215 const char *func_name() const { return "substr"; } 00216 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00217 }; 00218 00219 00220 class Item_func_substr_index :public Item_str_func 00221 { 00222 String tmp_value; 00223 public: 00224 Item_func_substr_index(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} 00225 String *val_str(String *); 00226 void fix_length_and_dec(); 00227 const char *func_name() const { return "substring_index"; } 00228 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00229 }; 00230 00231 00232 class Item_func_trim :public Item_str_func 00233 { 00234 protected: 00235 String tmp_value; 00236 String remove; 00237 public: 00238 Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {} 00239 Item_func_trim(Item *a) :Item_str_func(a) {} 00240 String *val_str(String *); 00241 void fix_length_and_dec(); 00242 const char *func_name() const { return "trim"; } 00243 void print(String *str); 00244 virtual const char *mode_name() const { return "both"; } 00245 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00246 }; 00247 00248 00249 class Item_func_ltrim :public Item_func_trim 00250 { 00251 public: 00252 Item_func_ltrim(Item *a,Item *b) :Item_func_trim(a,b) {} 00253 Item_func_ltrim(Item *a) :Item_func_trim(a) {} 00254 String *val_str(String *); 00255 const char *func_name() const { return "ltrim"; } 00256 const char *mode_name() const { return "leading"; } 00257 }; 00258 00259 00260 class Item_func_rtrim :public Item_func_trim 00261 { 00262 public: 00263 Item_func_rtrim(Item *a,Item *b) :Item_func_trim(a,b) {} 00264 Item_func_rtrim(Item *a) :Item_func_trim(a) {} 00265 String *val_str(String *); 00266 const char *func_name() const { return "rtrim"; } 00267 const char *mode_name() const { return "trailing"; } 00268 }; 00269 00270 00271 /* 00272 Item_func_password -- new (4.1.1) PASSWORD() function implementation. 00273 Returns strcat('*', octet2hex(sha1(sha1(password)))). '*' stands for new 00274 password format, sha1(sha1(password) is so-called hash_stage2 value. 00275 Length of returned string is always 41 byte. To find out how entire 00276 authentication procedure works, see comments in password.c. 00277 */ 00278 00279 class Item_func_password :public Item_str_func 00280 { 00281 char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH+1]; 00282 public: 00283 Item_func_password(Item *a) :Item_str_func(a) {} 00284 String *val_str(String *str); 00285 void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH; } 00286 const char *func_name() const { return "password"; } 00287 static char *alloc(THD *thd, const char *password); 00288 }; 00289 00290 00291 /* 00292 Item_func_old_password -- PASSWORD() implementation used in MySQL 3.21 - 4.0 00293 compatibility mode. This item is created in sql_yacc.yy when 00294 'old_passwords' session variable is set, and to handle OLD_PASSWORD() 00295 function. 00296 */ 00297 00298 class Item_func_old_password :public Item_str_func 00299 { 00300 char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1]; 00301 public: 00302 Item_func_old_password(Item *a) :Item_str_func(a) {} 00303 String *val_str(String *str); 00304 void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; } 00305 const char *func_name() const { return "old_password"; } 00306 static char *alloc(THD *thd, const char *password); 00307 }; 00308 00309 00310 class Item_func_des_encrypt :public Item_str_func 00311 { 00312 String tmp_value; 00313 public: 00314 Item_func_des_encrypt(Item *a) :Item_str_func(a) {} 00315 Item_func_des_encrypt(Item *a, Item *b): Item_str_func(a,b) {} 00316 String *val_str(String *); 00317 void fix_length_and_dec() 00318 { maybe_null=1; max_length = args[0]->max_length+8; } 00319 const char *func_name() const { return "des_encrypt"; } 00320 }; 00321 00322 class Item_func_des_decrypt :public Item_str_func 00323 { 00324 String tmp_value; 00325 public: 00326 Item_func_des_decrypt(Item *a) :Item_str_func(a) {} 00327 Item_func_des_decrypt(Item *a, Item *b): Item_str_func(a,b) {} 00328 String *val_str(String *); 00329 void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; } 00330 const char *func_name() const { return "des_decrypt"; } 00331 }; 00332 00333 class Item_func_encrypt :public Item_str_func 00334 { 00335 String tmp_value; 00336 public: 00337 Item_func_encrypt(Item *a) :Item_str_func(a) {} 00338 Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) {} 00339 String *val_str(String *); 00340 void fix_length_and_dec() { maybe_null=1; max_length = 13; } 00341 const char *func_name() const { return "encrypt"; } 00342 }; 00343 00344 #include "sql_crypt.h" 00345 00346 00347 class Item_func_encode :public Item_str_func 00348 { 00349 protected: 00350 SQL_CRYPT sql_crypt; 00351 public: 00352 Item_func_encode(Item *a, char *seed): 00353 Item_str_func(a),sql_crypt(seed) {} 00354 String *val_str(String *); 00355 void fix_length_and_dec(); 00356 const char *func_name() const { return "encode"; } 00357 }; 00358 00359 00360 class Item_func_decode :public Item_func_encode 00361 { 00362 public: 00363 Item_func_decode(Item *a, char *seed): Item_func_encode(a,seed) {} 00364 String *val_str(String *); 00365 const char *func_name() const { return "decode"; } 00366 }; 00367 00368 00369 class Item_func_sysconst :public Item_str_func 00370 { 00371 public: 00372 Item_func_sysconst() 00373 { collation.set(system_charset_info,DERIVATION_SYSCONST); } 00374 Item *safe_charset_converter(CHARSET_INFO *tocs); 00375 /* 00376 Used to create correct Item name in new converted item in 00377 safe_charset_converter, return string representation of this function 00378 call 00379 */ 00380 virtual const char *fully_qualified_func_name() const = 0; 00381 }; 00382 00383 00384 class Item_func_database :public Item_func_sysconst 00385 { 00386 public: 00387 Item_func_database() :Item_func_sysconst() {} 00388 String *val_str(String *); 00389 void fix_length_and_dec() 00390 { 00391 max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; 00392 maybe_null=1; 00393 } 00394 const char *func_name() const { return "database"; } 00395 const char *fully_qualified_func_name() const { return "database()"; } 00396 }; 00397 00398 00399 class Item_func_user :public Item_func_sysconst 00400 { 00401 protected: 00402 bool init (const char *user, const char *host); 00403 00404 public: 00405 Item_func_user() 00406 { 00407 str_value.set("", 0, system_charset_info); 00408 } 00409 String *val_str(String *) 00410 { 00411 DBUG_ASSERT(fixed == 1); 00412 return (null_value ? 0 : &str_value); 00413 } 00414 bool fix_fields(THD *thd, Item **ref); 00415 void fix_length_and_dec() 00416 { 00417 max_length= ((USERNAME_LENGTH + HOSTNAME_LENGTH + 1) * 00418 system_charset_info->mbmaxlen); 00419 } 00420 const char *func_name() const { return "user"; } 00421 const char *fully_qualified_func_name() const { return "user()"; } 00422 }; 00423 00424 00425 class Item_func_current_user :public Item_func_user 00426 { 00427 Name_resolution_context *context; 00428 00429 public: 00430 Item_func_current_user(Name_resolution_context *context_arg) 00431 : context(context_arg) {} 00432 bool fix_fields(THD *thd, Item **ref); 00433 const char *func_name() const { return "current_user"; } 00434 const char *fully_qualified_func_name() const { return "current_user()"; } 00435 }; 00436 00437 00438 class Item_func_soundex :public Item_str_func 00439 { 00440 String tmp_value; 00441 public: 00442 Item_func_soundex(Item *a) :Item_str_func(a) {} 00443 String *val_str(String *); 00444 void fix_length_and_dec(); 00445 const char *func_name() const { return "soundex"; } 00446 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00447 }; 00448 00449 00450 class Item_func_elt :public Item_str_func 00451 { 00452 public: 00453 Item_func_elt(List<Item> &list) :Item_str_func(list) {} 00454 double val_real(); 00455 longlong val_int(); 00456 String *val_str(String *str); 00457 void fix_length_and_dec(); 00458 const char *func_name() const { return "elt"; } 00459 }; 00460 00461 00462 class Item_func_make_set :public Item_str_func 00463 { 00464 Item *item; 00465 String tmp_str; 00466 00467 public: 00468 Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {} 00469 String *val_str(String *str); 00470 bool fix_fields(THD *thd, Item **ref) 00471 { 00472 DBUG_ASSERT(fixed == 0); 00473 return ((!item->fixed && item->fix_fields(thd, &item)) || 00474 item->check_cols(1) || 00475 Item_func::fix_fields(thd, ref)); 00476 } 00477 void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields); 00478 void fix_length_and_dec(); 00479 void update_used_tables(); 00480 const char *func_name() const { return "make_set"; } 00481 00482 bool walk(Item_processor processor, bool walk_subquery, byte *arg) 00483 { 00484 return item->walk(processor, walk_subquery, arg) || 00485 Item_str_func::walk(processor, walk_subquery, arg); 00486 } 00487 Item *transform(Item_transformer transformer, byte *arg) 00488 { 00489 Item *new_item= item->transform(transformer, arg); 00490 if (!new_item) 00491 return 0; 00492 item= new_item; 00493 return Item_str_func::transform(transformer, arg); 00494 } 00495 void print(String *str); 00496 }; 00497 00498 00499 class Item_func_format :public Item_str_func 00500 { 00501 String tmp_str; 00502 public: 00503 Item_func_format(Item *org,int dec); 00504 String *val_str(String *); 00505 void fix_length_and_dec() 00506 { 00507 collation.set(default_charset()); 00508 uint char_length= args[0]->max_length/args[0]->collation.collation->mbmaxlen; 00509 max_length= ((char_length + (char_length-args[0]->decimals)/3) * 00510 collation.collation->mbmaxlen); 00511 } 00512 const char *func_name() const { return "format"; } 00513 void print(String *); 00514 }; 00515 00516 00517 class Item_func_char :public Item_str_func 00518 { 00519 public: 00520 Item_func_char(List<Item> &list) :Item_str_func(list) 00521 { collation.set(&my_charset_bin); } 00522 Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list) 00523 { collation.set(cs); } 00524 String *val_str(String *); 00525 void fix_length_and_dec() 00526 { 00527 maybe_null=0; 00528 max_length=arg_count * collation.collation->mbmaxlen; 00529 } 00530 const char *func_name() const { return "char"; } 00531 }; 00532 00533 00534 class Item_func_repeat :public Item_str_func 00535 { 00536 String tmp_value; 00537 public: 00538 Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {} 00539 String *val_str(String *); 00540 void fix_length_and_dec(); 00541 const char *func_name() const { return "repeat"; } 00542 }; 00543 00544 00545 class Item_func_rpad :public Item_str_func 00546 { 00547 String tmp_value, rpad_str; 00548 public: 00549 Item_func_rpad(Item *arg1,Item *arg2,Item *arg3) 00550 :Item_str_func(arg1,arg2,arg3) {} 00551 String *val_str(String *); 00552 void fix_length_and_dec(); 00553 const char *func_name() const { return "rpad"; } 00554 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00555 }; 00556 00557 00558 class Item_func_lpad :public Item_str_func 00559 { 00560 String tmp_value, lpad_str; 00561 public: 00562 Item_func_lpad(Item *arg1,Item *arg2,Item *arg3) 00563 :Item_str_func(arg1,arg2,arg3) {} 00564 String *val_str(String *); 00565 void fix_length_and_dec(); 00566 const char *func_name() const { return "lpad"; } 00567 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00568 }; 00569 00570 00571 class Item_func_conv :public Item_str_func 00572 { 00573 public: 00574 Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} 00575 const char *func_name() const { return "conv"; } 00576 String *val_str(String *); 00577 void fix_length_and_dec() 00578 { 00579 collation.set(default_charset()); 00580 max_length= 64; 00581 } 00582 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00583 }; 00584 00585 00586 class Item_func_hex :public Item_str_func 00587 { 00588 String tmp_value; 00589 public: 00590 Item_func_hex(Item *a) :Item_str_func(a) {} 00591 const char *func_name() const { return "hex"; } 00592 String *val_str(String *); 00593 void fix_length_and_dec() 00594 { 00595 collation.set(default_charset()); 00596 decimals=0; 00597 max_length=args[0]->max_length*2*collation.collation->mbmaxlen; 00598 } 00599 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00600 }; 00601 00602 class Item_func_unhex :public Item_str_func 00603 { 00604 String tmp_value; 00605 public: 00606 Item_func_unhex(Item *a) :Item_str_func(a) {} 00607 const char *func_name() const { return "unhex"; } 00608 String *val_str(String *); 00609 void fix_length_and_dec() 00610 { 00611 collation.set(&my_charset_bin); 00612 decimals=0; 00613 max_length=(1+args[0]->max_length)/2; 00614 } 00615 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00616 }; 00617 00618 00619 class Item_func_binary :public Item_str_func 00620 { 00621 public: 00622 Item_func_binary(Item *a) :Item_str_func(a) {} 00623 String *val_str(String *a) 00624 { 00625 DBUG_ASSERT(fixed == 1); 00626 String *tmp=args[0]->val_str(a); 00627 null_value=args[0]->null_value; 00628 if (tmp) 00629 tmp->set_charset(&my_charset_bin); 00630 return tmp; 00631 } 00632 void fix_length_and_dec() 00633 { 00634 collation.set(&my_charset_bin); 00635 max_length=args[0]->max_length; 00636 } 00637 void print(String *str); 00638 const char *func_name() const { return "cast_as_binary"; } 00639 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00640 }; 00641 00642 00643 class Item_load_file :public Item_str_func 00644 { 00645 String tmp_value; 00646 public: 00647 Item_load_file(Item *a) :Item_str_func(a) {} 00648 String *val_str(String *); 00649 const char *func_name() const { return "load_file"; } 00650 void fix_length_and_dec() 00651 { 00652 collation.set(&my_charset_bin, DERIVATION_COERCIBLE); 00653 maybe_null=1; 00654 max_length=MAX_BLOB_WIDTH; 00655 } 00656 }; 00657 00658 00659 class Item_func_export_set: public Item_str_func 00660 { 00661 public: 00662 Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {} 00663 Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {} 00664 Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {} 00665 String *val_str(String *str); 00666 void fix_length_and_dec(); 00667 const char *func_name() const { return "export_set"; } 00668 }; 00669 00670 class Item_func_inet_ntoa : public Item_str_func 00671 { 00672 public: 00673 Item_func_inet_ntoa(Item *a) :Item_str_func(a) 00674 { 00675 } 00676 String* val_str(String* str); 00677 const char *func_name() const { return "inet_ntoa"; } 00678 void fix_length_and_dec() { decimals = 0; max_length=3*8+7; } 00679 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00680 }; 00681 00682 class Item_func_quote :public Item_str_func 00683 { 00684 String tmp_value; 00685 public: 00686 Item_func_quote(Item *a) :Item_str_func(a) {} 00687 const char *func_name() const { return "quote"; } 00688 String *val_str(String *); 00689 void fix_length_and_dec() 00690 { 00691 collation.set(args[0]->collation); 00692 max_length= args[0]->max_length * 2 + 2; 00693 } 00694 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00695 }; 00696 00697 class Item_func_conv_charset :public Item_str_func 00698 { 00699 bool use_cached_value; 00700 public: 00701 bool safe; 00702 CHARSET_INFO *conv_charset; // keep it public 00703 Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 00704 { conv_charset= cs; use_cached_value= 0; safe= 0; } 00705 Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 00706 :Item_str_func(a) 00707 { 00708 DBUG_ASSERT(args[0]->fixed); 00709 conv_charset= cs; 00710 if (cache_if_const && args[0]->const_item()) 00711 { 00712 uint errors= 0; 00713 String tmp, *str= args[0]->val_str(&tmp); 00714 if (!str || str_value.copy(str->ptr(), str->length(), 00715 str->charset(), conv_charset, &errors)) 00716 null_value= 1; 00717 use_cached_value= 1; 00718 str_value.mark_as_const(); 00719 safe= (errors == 0); 00720 } 00721 else 00722 { 00723 use_cached_value= 0; 00724 /* 00725 Conversion from and to "binary" is safe. 00726 Conversion to Unicode is safe. 00727 Other kind of conversions are potentially lossy. 00728 */ 00729 safe= (args[0]->collation.collation == &my_charset_bin || 00730 cs == &my_charset_bin || 00731 (cs->state & MY_CS_UNICODE)); 00732 } 00733 } 00734 String *val_str(String *); 00735 void fix_length_and_dec(); 00736 const char *func_name() const { return "convert"; } 00737 void print(String *str); 00738 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00739 }; 00740 00741 class Item_func_set_collation :public Item_str_func 00742 { 00743 public: 00744 Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {}; 00745 String *val_str(String *); 00746 void fix_length_and_dec(); 00747 bool eq(const Item *item, bool binary_cmp) const; 00748 const char *func_name() const { return "collate"; } 00749 enum Functype functype() const { return COLLATE_FUNC; } 00750 void print(String *str); 00751 Item_field *filed_for_view_update() 00752 { 00753 /* this function is transparent for view updating */ 00754 return args[0]->filed_for_view_update(); 00755 } 00756 }; 00757 00758 class Item_func_charset :public Item_str_func 00759 { 00760 public: 00761 Item_func_charset(Item *a) :Item_str_func(a) {} 00762 String *val_str(String *); 00763 const char *func_name() const { return "charset"; } 00764 void fix_length_and_dec() 00765 { 00766 collation.set(system_charset_info); 00767 max_length= 64 * collation.collation->mbmaxlen; // should be enough 00768 maybe_null= 0; 00769 }; 00770 table_map not_null_tables() const { return 0; } 00771 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00772 }; 00773 00774 class Item_func_collation :public Item_str_func 00775 { 00776 public: 00777 Item_func_collation(Item *a) :Item_str_func(a) {} 00778 String *val_str(String *); 00779 const char *func_name() const { return "collation"; } 00780 void fix_length_and_dec() 00781 { 00782 collation.set(system_charset_info); 00783 max_length= 64 * collation.collation->mbmaxlen; // should be enough 00784 maybe_null= 0; 00785 }; 00786 table_map not_null_tables() const { return 0; } 00787 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00788 }; 00789 00790 class Item_func_crc32 :public Item_int_func 00791 { 00792 String value; 00793 public: 00794 Item_func_crc32(Item *a) :Item_int_func(a) {} 00795 const char *func_name() const { return "crc32"; } 00796 void fix_length_and_dec() { max_length=10; } 00797 longlong val_int(); 00798 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00799 }; 00800 00801 class Item_func_uncompressed_length : public Item_int_func 00802 { 00803 String value; 00804 public: 00805 Item_func_uncompressed_length(Item *a):Item_int_func(a){} 00806 const char *func_name() const{return "uncompressed_length";} 00807 void fix_length_and_dec() { max_length=10; } 00808 longlong val_int(); 00809 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00810 }; 00811 00812 #ifdef HAVE_COMPRESS 00813 #define ZLIB_DEPENDED_FUNCTION ; 00814 #else 00815 #define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; } 00816 #endif 00817 00818 class Item_func_compress: public Item_str_func 00819 { 00820 String buffer; 00821 public: 00822 Item_func_compress(Item *a):Item_str_func(a){} 00823 void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} 00824 const char *func_name() const{return "compress";} 00825 String *val_str(String *) ZLIB_DEPENDED_FUNCTION 00826 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00827 }; 00828 00829 class Item_func_uncompress: public Item_str_func 00830 { 00831 String buffer; 00832 public: 00833 Item_func_uncompress(Item *a): Item_str_func(a){} 00834 void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; } 00835 const char *func_name() const{return "uncompress";} 00836 String *val_str(String *) ZLIB_DEPENDED_FUNCTION 00837 bool check_partition_func_processor(byte *bool_arg) { return 0;} 00838 }; 00839 00840 #define UUID_LENGTH (8+1+4+1+4+1+4+1+12) 00841 class Item_func_uuid: public Item_str_func 00842 { 00843 public: 00844 Item_func_uuid(): Item_str_func() {} 00845 void fix_length_and_dec() { 00846 collation.set(system_charset_info); 00847 /* 00848 NOTE! uuid() should be changed to use 'ascii' 00849 charset when hex(), format(), md5(), etc, and implicit 00850 number-to-string conversion will use 'ascii' 00851 */ 00852 max_length= UUID_LENGTH * system_charset_info->mbmaxlen; 00853 } 00854 const char *func_name() const{ return "uuid"; } 00855 String *val_str(String *); 00856 }; 00857
1.4.7

