My Project
|
00001 #ifndef ITEM_STRFUNC_INCLUDED 00002 #define ITEM_STRFUNC_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 /* This file defines all string functions */ 00021 #include "crypt_genhash_impl.h" 00022 00023 class MY_LOCALE; 00024 00025 class Item_str_func :public Item_func 00026 { 00027 protected: 00033 String *make_empty_result() { 00034 str_value.set("", 0, collation.collation); 00035 return &str_value; 00036 } 00037 public: 00038 Item_str_func() :Item_func() { decimals=NOT_FIXED_DEC; } 00039 Item_str_func(Item *a) :Item_func(a) {decimals=NOT_FIXED_DEC; } 00040 Item_str_func(Item *a,Item *b) :Item_func(a,b) { decimals=NOT_FIXED_DEC; } 00041 Item_str_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) { decimals=NOT_FIXED_DEC; } 00042 Item_str_func(Item *a,Item *b,Item *c,Item *d) :Item_func(a,b,c,d) {decimals=NOT_FIXED_DEC; } 00043 Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e) {decimals=NOT_FIXED_DEC; } 00044 Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; } 00045 longlong val_int(); 00046 double val_real(); 00047 my_decimal *val_decimal(my_decimal *); 00048 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00049 { 00050 return get_date_from_string(ltime, fuzzydate); 00051 } 00052 bool get_time(MYSQL_TIME *ltime) 00053 { 00054 return get_time_from_string(ltime); 00055 } 00056 enum Item_result result_type () const { return STRING_RESULT; } 00057 void left_right_max_length(); 00058 bool fix_fields(THD *thd, Item **ref); 00059 String *val_str_from_val_str_ascii(String *str, String *str2); 00060 }; 00061 00062 00063 00064 /* 00065 Functions that return values with ASCII repertoire 00066 */ 00067 class Item_str_ascii_func :public Item_str_func 00068 { 00069 String ascii_buf; 00070 public: 00071 Item_str_ascii_func() :Item_str_func() 00072 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 00073 Item_str_ascii_func(Item *a) :Item_str_func(a) 00074 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 00075 Item_str_ascii_func(Item *a,Item *b) :Item_str_func(a,b) 00076 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 00077 Item_str_ascii_func(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) 00078 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 00079 String *val_str(String *str) 00080 { 00081 return val_str_from_val_str_ascii(str, &ascii_buf); 00082 } 00083 virtual String *val_str_ascii(String *)= 0; 00084 }; 00085 00086 00087 class Item_func_md5 :public Item_str_ascii_func 00088 { 00089 String tmp_value; 00090 public: 00091 Item_func_md5(Item *a) :Item_str_ascii_func(a) {} 00092 String *val_str_ascii(String *); 00093 void fix_length_and_dec(); 00094 const char *func_name() const { return "md5"; } 00095 }; 00096 00097 00098 class Item_func_sha :public Item_str_ascii_func 00099 { 00100 public: 00101 Item_func_sha(Item *a) :Item_str_ascii_func(a) {} 00102 String *val_str_ascii(String *); 00103 void fix_length_and_dec(); 00104 const char *func_name() const { return "sha"; } 00105 }; 00106 00107 class Item_func_sha2 :public Item_str_ascii_func 00108 { 00109 public: 00110 Item_func_sha2(Item *a, Item *b) :Item_str_ascii_func(a, b) {} 00111 String *val_str_ascii(String *); 00112 void fix_length_and_dec(); 00113 const char *func_name() const { return "sha2"; } 00114 }; 00115 00116 class Item_func_to_base64 :public Item_str_ascii_func 00117 { 00118 String tmp_value; 00119 public: 00120 Item_func_to_base64(Item *a) :Item_str_ascii_func(a) {} 00121 String *val_str_ascii(String *); 00122 void fix_length_and_dec(); 00123 const char *func_name() const { return "to_base64"; } 00124 }; 00125 00126 class Item_func_from_base64 :public Item_str_func 00127 { 00128 String tmp_value; 00129 public: 00130 Item_func_from_base64(Item *a) :Item_str_func(a) {} 00131 String *val_str(String *); 00132 void fix_length_and_dec(); 00133 const char *func_name() const { return "from_base64"; } 00134 }; 00135 00136 00137 class Item_func_aes_encrypt :public Item_str_func 00138 { 00139 public: 00140 Item_func_aes_encrypt(Item *a, Item *b) :Item_str_func(a,b) {} 00141 Item_func_aes_encrypt(Item *a, Item *b, Item *c) :Item_str_func(a, b, c) {} 00142 String *val_str(String *); 00143 void fix_length_and_dec(); 00144 const char *func_name() const { return "aes_encrypt"; } 00145 }; 00146 00147 class Item_func_aes_decrypt :public Item_str_func 00148 { 00149 public: 00150 Item_func_aes_decrypt(Item *a, Item *b) :Item_str_func(a,b) {} 00151 Item_func_aes_decrypt(Item *a, Item *b, Item *c) :Item_str_func(a, b, c) {} 00152 String *val_str(String *); 00153 void fix_length_and_dec(); 00154 const char *func_name() const { return "aes_decrypt"; } 00155 }; 00156 00157 00158 class Item_func_random_bytes : public Item_str_func 00159 { 00161 static const longlong MAX_RANDOM_BYTES_BUFFER; 00162 public: 00163 Item_func_random_bytes(Item *a) : Item_str_func(a) 00164 {} 00165 00166 void fix_length_and_dec(); 00167 String *val_str(String *a); 00168 00169 const char *func_name() const 00170 { 00171 return "random_bytes"; 00172 } 00173 00174 }; 00175 00176 class Item_func_concat :public Item_str_func 00177 { 00178 String tmp_value; 00179 public: 00180 Item_func_concat(List<Item> &list) :Item_str_func(list) {} 00181 Item_func_concat(Item *a,Item *b) :Item_str_func(a,b) {} 00182 String *val_str(String *); 00183 void fix_length_and_dec(); 00184 const char *func_name() const { return "concat"; } 00185 }; 00186 00187 class Item_func_concat_ws :public Item_str_func 00188 { 00189 String tmp_value; 00190 public: 00191 Item_func_concat_ws(List<Item> &list) :Item_str_func(list) {} 00192 String *val_str(String *); 00193 void fix_length_and_dec(); 00194 const char *func_name() const { return "concat_ws"; } 00195 table_map not_null_tables() const { return 0; } 00196 }; 00197 00198 class Item_func_reverse :public Item_str_func 00199 { 00200 String tmp_value; 00201 public: 00202 Item_func_reverse(Item *a) :Item_str_func(a) {} 00203 String *val_str(String *); 00204 void fix_length_and_dec(); 00205 const char *func_name() const { return "reverse"; } 00206 }; 00207 00208 00209 class Item_func_replace :public Item_str_func 00210 { 00211 String tmp_value,tmp_value2; 00212 public: 00213 Item_func_replace(Item *org,Item *find,Item *replace) 00214 :Item_str_func(org,find,replace) {} 00215 String *val_str(String *); 00216 void fix_length_and_dec(); 00217 const char *func_name() const { return "replace"; } 00218 }; 00219 00220 00221 class Item_func_insert :public Item_str_func 00222 { 00223 String tmp_value; 00224 public: 00225 Item_func_insert(Item *org,Item *start,Item *length,Item *new_str) 00226 :Item_str_func(org,start,length,new_str) {} 00227 String *val_str(String *); 00228 void fix_length_and_dec(); 00229 const char *func_name() const { return "insert"; } 00230 }; 00231 00232 00233 class Item_str_conv :public Item_str_func 00234 { 00235 protected: 00236 uint multiply; 00237 my_charset_conv_case converter; 00238 String tmp_value; 00239 public: 00240 Item_str_conv(Item *item) :Item_str_func(item) {} 00241 String *val_str(String *); 00242 }; 00243 00244 00245 class Item_func_lcase :public Item_str_conv 00246 { 00247 public: 00248 Item_func_lcase(Item *item) :Item_str_conv(item) {} 00249 const char *func_name() const { return "lcase"; } 00250 void fix_length_and_dec(); 00251 }; 00252 00253 class Item_func_ucase :public Item_str_conv 00254 { 00255 public: 00256 Item_func_ucase(Item *item) :Item_str_conv(item) {} 00257 const char *func_name() const { return "ucase"; } 00258 void fix_length_and_dec(); 00259 }; 00260 00261 00262 class Item_func_left :public Item_str_func 00263 { 00264 String tmp_value; 00265 public: 00266 Item_func_left(Item *a,Item *b) :Item_str_func(a,b) {} 00267 String *val_str(String *); 00268 void fix_length_and_dec(); 00269 const char *func_name() const { return "left"; } 00270 }; 00271 00272 00273 class Item_func_right :public Item_str_func 00274 { 00275 String tmp_value; 00276 public: 00277 Item_func_right(Item *a,Item *b) :Item_str_func(a,b) {} 00278 String *val_str(String *); 00279 void fix_length_and_dec(); 00280 const char *func_name() const { return "right"; } 00281 }; 00282 00283 00284 class Item_func_substr :public Item_str_func 00285 { 00286 String tmp_value; 00287 public: 00288 Item_func_substr(Item *a,Item *b) :Item_str_func(a,b) {} 00289 Item_func_substr(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} 00290 String *val_str(String *); 00291 void fix_length_and_dec(); 00292 const char *func_name() const { return "substr"; } 00293 }; 00294 00295 00296 class Item_func_substr_index :public Item_str_func 00297 { 00298 String tmp_value; 00299 public: 00300 Item_func_substr_index(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} 00301 String *val_str(String *); 00302 void fix_length_and_dec(); 00303 const char *func_name() const { return "substring_index"; } 00304 }; 00305 00306 00307 class Item_func_trim :public Item_str_func 00308 { 00309 protected: 00310 String tmp_value; 00311 String remove; 00312 public: 00313 Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {} 00314 Item_func_trim(Item *a) :Item_str_func(a) {} 00315 String *val_str(String *); 00316 void fix_length_and_dec(); 00317 const char *func_name() const { return "trim"; } 00318 virtual void print(String *str, enum_query_type query_type); 00319 virtual const char *mode_name() const { return "both"; } 00320 }; 00321 00322 00323 class Item_func_ltrim :public Item_func_trim 00324 { 00325 public: 00326 Item_func_ltrim(Item *a,Item *b) :Item_func_trim(a,b) {} 00327 Item_func_ltrim(Item *a) :Item_func_trim(a) {} 00328 String *val_str(String *); 00329 const char *func_name() const { return "ltrim"; } 00330 const char *mode_name() const { return "leading"; } 00331 }; 00332 00333 00334 class Item_func_rtrim :public Item_func_trim 00335 { 00336 public: 00337 Item_func_rtrim(Item *a,Item *b) :Item_func_trim(a,b) {} 00338 Item_func_rtrim(Item *a) :Item_func_trim(a) {} 00339 String *val_str(String *); 00340 const char *func_name() const { return "rtrim"; } 00341 const char *mode_name() const { return "trailing"; } 00342 }; 00343 00344 00345 /* 00346 Item_func_password -- new (4.1.1) PASSWORD() function implementation. 00347 Returns strcat('*', octet2hex(sha1(sha1(password)))). '*' stands for new 00348 password format, sha1(sha1(password) is so-called hash_stage2 value. 00349 Length of returned string is always 41 byte. To find out how entire 00350 authentication procedure works, see comments in password.c. 00351 */ 00352 00353 class Item_func_password :public Item_str_ascii_func 00354 { 00355 char m_hashed_password_buffer[CRYPT_MAX_PASSWORD_SIZE + 1]; 00356 unsigned int m_hashed_password_buffer_len; 00357 bool m_recalculate_password; 00358 public: 00359 Item_func_password(Item *a) : Item_str_ascii_func(a) 00360 { 00361 m_hashed_password_buffer_len= 0; 00362 m_recalculate_password= false; 00363 } 00364 String *val_str_ascii(String *str); 00365 void fix_length_and_dec(); 00366 const char *func_name() const { return "password"; } 00367 static char *create_password_hash_buffer(THD *thd, const char *password, 00368 size_t pass_len); 00369 }; 00370 00371 00372 /* 00373 Item_func_old_password -- PASSWORD() implementation used in MySQL 3.21 - 4.0 00374 compatibility mode. This item is created in sql_yacc.yy when 00375 'old_passwords' session variable is set, and to handle OLD_PASSWORD() 00376 function. 00377 */ 00378 00379 class Item_func_old_password :public Item_str_ascii_func 00380 { 00381 char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1]; 00382 public: 00383 Item_func_old_password(Item *a) :Item_str_ascii_func(a) {} 00384 String *val_str_ascii(String *str); 00385 void fix_length_and_dec() 00386 { 00387 fix_length_and_charset(SCRAMBLED_PASSWORD_CHAR_LENGTH_323, default_charset()); 00388 } 00389 const char *func_name() const { return "old_password"; } 00390 static char *alloc(THD *thd, const char *password, size_t pass_len); 00391 }; 00392 00393 00394 class Item_func_des_encrypt :public Item_str_func 00395 { 00396 String tmp_value,tmp_arg; 00397 public: 00398 Item_func_des_encrypt(Item *a) :Item_str_func(a) {} 00399 Item_func_des_encrypt(Item *a, Item *b): Item_str_func(a,b) {} 00400 String *val_str(String *); 00401 void fix_length_and_dec() 00402 { 00403 maybe_null=1; 00404 /* 9 = MAX ((8- (arg_len % 8)) + 1) */ 00405 max_length = args[0]->max_length + 9; 00406 } 00407 const char *func_name() const { return "des_encrypt"; } 00408 }; 00409 00410 class Item_func_des_decrypt :public Item_str_func 00411 { 00412 String tmp_value; 00413 public: 00414 Item_func_des_decrypt(Item *a) :Item_str_func(a) {} 00415 Item_func_des_decrypt(Item *a, Item *b): Item_str_func(a,b) {} 00416 String *val_str(String *); 00417 void fix_length_and_dec() 00418 { 00419 maybe_null=1; 00420 /* 9 = MAX ((8- (arg_len % 8)) + 1) */ 00421 max_length= args[0]->max_length; 00422 if (max_length >= 9U) 00423 max_length-= 9U; 00424 } 00425 const char *func_name() const { return "des_decrypt"; } 00426 }; 00427 00428 class Item_func_encrypt :public Item_str_func 00429 { 00430 String tmp_value; 00431 00432 /* Encapsulate common constructor actions */ 00433 void constructor_helper() 00434 { 00435 collation.set(&my_charset_bin); 00436 } 00437 public: 00438 Item_func_encrypt(Item *a) :Item_str_func(a) 00439 { 00440 constructor_helper(); 00441 } 00442 Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) 00443 { 00444 constructor_helper(); 00445 } 00446 String *val_str(String *); 00447 void fix_length_and_dec() { maybe_null=1; max_length = 13; } 00448 const char *func_name() const { return "encrypt"; } 00449 }; 00450 00451 #include "sql_crypt.h" 00452 00453 00454 class Item_func_encode :public Item_str_func 00455 { 00456 private: 00458 bool seeded; 00459 protected: 00460 SQL_CRYPT sql_crypt; 00461 public: 00462 Item_func_encode(Item *a, Item *seed): 00463 Item_str_func(a, seed) {} 00464 String *val_str(String *); 00465 void fix_length_and_dec(); 00466 const char *func_name() const { return "encode"; } 00467 protected: 00468 virtual void crypto_transform(String *); 00469 private: 00471 bool seed(); 00472 }; 00473 00474 00475 class Item_func_decode :public Item_func_encode 00476 { 00477 public: 00478 Item_func_decode(Item *a, Item *seed): Item_func_encode(a, seed) {} 00479 const char *func_name() const { return "decode"; } 00480 protected: 00481 void crypto_transform(String *); 00482 }; 00483 00484 00485 class Item_func_sysconst :public Item_str_func 00486 { 00487 public: 00488 Item_func_sysconst() 00489 { collation.set(system_charset_info,DERIVATION_SYSCONST); } 00490 Item *safe_charset_converter(const CHARSET_INFO *tocs); 00491 /* 00492 Used to create correct Item name in new converted item in 00493 safe_charset_converter, return string representation of this function 00494 call 00495 */ 00496 virtual const Name_string fully_qualified_func_name() const = 0; 00497 }; 00498 00499 00500 class Item_func_database :public Item_func_sysconst 00501 { 00502 public: 00503 Item_func_database() :Item_func_sysconst() {} 00504 String *val_str(String *); 00505 void fix_length_and_dec() 00506 { 00507 max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; 00508 maybe_null=1; 00509 } 00510 const char *func_name() const { return "database"; } 00511 const Name_string fully_qualified_func_name() const 00512 { return NAME_STRING("database()"); } 00513 }; 00514 00515 00516 class Item_func_user :public Item_func_sysconst 00517 { 00518 protected: 00519 bool init (const char *user, const char *host); 00520 00521 public: 00522 Item_func_user() 00523 { 00524 str_value.set("", 0, system_charset_info); 00525 } 00526 String *val_str(String *) 00527 { 00528 DBUG_ASSERT(fixed == 1); 00529 return (null_value ? 0 : &str_value); 00530 } 00531 bool fix_fields(THD *thd, Item **ref); 00532 void fix_length_and_dec() 00533 { 00534 max_length= (USERNAME_LENGTH + 00535 (HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN); 00536 } 00537 const char *func_name() const { return "user"; } 00538 const Name_string fully_qualified_func_name() const 00539 { return NAME_STRING("user()"); } 00540 type_conversion_status save_in_field(Field *field, bool no_conversions) 00541 { 00542 return save_str_value_in_field(field, &str_value); 00543 } 00544 }; 00545 00546 00547 class Item_func_current_user :public Item_func_user 00548 { 00549 Name_resolution_context *context; 00550 00551 public: 00552 Item_func_current_user(Name_resolution_context *context_arg) 00553 : context(context_arg) {} 00554 bool fix_fields(THD *thd, Item **ref); 00555 const char *func_name() const { return "current_user"; } 00556 const Name_string fully_qualified_func_name() const 00557 { return NAME_STRING("current_user()"); } 00558 }; 00559 00560 00561 class Item_func_soundex :public Item_str_func 00562 { 00563 String tmp_value; 00564 public: 00565 Item_func_soundex(Item *a) :Item_str_func(a) {} 00566 String *val_str(String *); 00567 void fix_length_and_dec(); 00568 const char *func_name() const { return "soundex"; } 00569 }; 00570 00571 00572 class Item_func_elt :public Item_str_func 00573 { 00574 public: 00575 Item_func_elt(List<Item> &list) :Item_str_func(list) {} 00576 double val_real(); 00577 longlong val_int(); 00578 String *val_str(String *str); 00579 void fix_length_and_dec(); 00580 const char *func_name() const { return "elt"; } 00581 }; 00582 00583 00584 class Item_func_make_set :public Item_str_func 00585 { 00586 Item *item; 00587 String tmp_str; 00588 00589 public: 00590 Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {} 00591 String *val_str(String *str); 00592 bool fix_fields(THD *thd, Item **ref) 00593 { 00594 DBUG_ASSERT(fixed == 0); 00595 bool res= ((!item->fixed && item->fix_fields(thd, &item)) || 00596 item->check_cols(1) || 00597 Item_func::fix_fields(thd, ref)); 00598 maybe_null|= item->maybe_null; 00599 return res; 00600 } 00601 void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, 00602 List<Item> &fields); 00603 void fix_length_and_dec(); 00604 void update_used_tables(); 00605 const char *func_name() const { return "make_set"; } 00606 00607 bool walk(Item_processor processor, bool walk_subquery, uchar *arg) 00608 { 00609 return item->walk(processor, walk_subquery, arg) || 00610 Item_str_func::walk(processor, walk_subquery, arg); 00611 } 00612 Item *transform(Item_transformer transformer, uchar *arg); 00613 virtual void print(String *str, enum_query_type query_type); 00614 }; 00615 00616 00617 class Item_func_format :public Item_str_ascii_func 00618 { 00619 String tmp_str; 00620 MY_LOCALE *locale; 00621 public: 00622 Item_func_format(Item *org, Item *dec): Item_str_ascii_func(org, dec) {} 00623 Item_func_format(Item *org, Item *dec, Item *lang): 00624 Item_str_ascii_func(org, dec, lang) {} 00625 00626 MY_LOCALE *get_locale(Item *item); 00627 String *val_str_ascii(String *); 00628 void fix_length_and_dec(); 00629 const char *func_name() const { return "format"; } 00630 virtual void print(String *str, enum_query_type query_type); 00631 }; 00632 00633 00634 class Item_func_char :public Item_str_func 00635 { 00636 public: 00637 Item_func_char(List<Item> &list) :Item_str_func(list) 00638 { collation.set(&my_charset_bin); } 00639 Item_func_char(List<Item> &list, const CHARSET_INFO *cs) : 00640 Item_str_func(list) 00641 { collation.set(cs); } 00642 String *val_str(String *); 00643 void fix_length_and_dec() 00644 { 00645 max_length= arg_count * 4; 00646 } 00647 const char *func_name() const { return "char"; } 00648 }; 00649 00650 00651 class Item_func_repeat :public Item_str_func 00652 { 00653 String tmp_value; 00654 public: 00655 Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {} 00656 String *val_str(String *); 00657 void fix_length_and_dec(); 00658 const char *func_name() const { return "repeat"; } 00659 }; 00660 00661 00662 class Item_func_space :public Item_str_func 00663 { 00664 public: 00665 Item_func_space(Item *arg1):Item_str_func(arg1) {} 00666 String *val_str(String *); 00667 void fix_length_and_dec(); 00668 const char *func_name() const { return "space"; } 00669 }; 00670 00671 00672 class Item_func_rpad :public Item_str_func 00673 { 00674 String tmp_value, rpad_str; 00675 public: 00676 Item_func_rpad(Item *arg1,Item *arg2,Item *arg3) 00677 :Item_str_func(arg1,arg2,arg3) {} 00678 String *val_str(String *); 00679 void fix_length_and_dec(); 00680 const char *func_name() const { return "rpad"; } 00681 }; 00682 00683 00684 class Item_func_lpad :public Item_str_func 00685 { 00686 String tmp_value, lpad_str; 00687 public: 00688 Item_func_lpad(Item *arg1,Item *arg2,Item *arg3) 00689 :Item_str_func(arg1,arg2,arg3) {} 00690 String *val_str(String *); 00691 void fix_length_and_dec(); 00692 const char *func_name() const { return "lpad"; } 00693 }; 00694 00695 00696 class Item_func_conv :public Item_str_func 00697 { 00698 public: 00699 Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} 00700 const char *func_name() const { return "conv"; } 00701 String *val_str(String *); 00702 void fix_length_and_dec() 00703 { 00704 collation.set(default_charset()); 00705 max_length=64; 00706 maybe_null= 1; 00707 } 00708 }; 00709 00710 00711 class Item_func_hex :public Item_str_ascii_func 00712 { 00713 String tmp_value; 00714 public: 00715 Item_func_hex(Item *a) :Item_str_ascii_func(a) {} 00716 const char *func_name() const { return "hex"; } 00717 String *val_str_ascii(String *); 00718 void fix_length_and_dec() 00719 { 00720 collation.set(default_charset()); 00721 decimals=0; 00722 fix_char_length(args[0]->max_length * 2); 00723 } 00724 }; 00725 00726 class Item_func_unhex :public Item_str_func 00727 { 00728 String tmp_value; 00729 public: 00730 Item_func_unhex(Item *a) :Item_str_func(a) 00731 { 00732 /* there can be bad hex strings */ 00733 maybe_null= 1; 00734 } 00735 const char *func_name() const { return "unhex"; } 00736 String *val_str(String *); 00737 void fix_length_and_dec() 00738 { 00739 collation.set(&my_charset_bin); 00740 decimals=0; 00741 max_length=(1+args[0]->max_length)/2; 00742 } 00743 }; 00744 00745 00746 #ifndef DBUG_OFF 00747 class Item_func_like_range :public Item_str_func 00748 { 00749 protected: 00750 String min_str; 00751 String max_str; 00752 const bool is_min; 00753 public: 00754 Item_func_like_range(Item *a, Item *b, bool is_min_arg) 00755 :Item_str_func(a, b), is_min(is_min_arg) 00756 { maybe_null= 1; } 00757 String *val_str(String *); 00758 void fix_length_and_dec() 00759 { 00760 collation.set(args[0]->collation); 00761 decimals=0; 00762 max_length= MAX_BLOB_WIDTH; 00763 } 00764 }; 00765 00766 00767 class Item_func_like_range_min :public Item_func_like_range 00768 { 00769 public: 00770 Item_func_like_range_min(Item *a, Item *b) 00771 :Item_func_like_range(a, b, true) { } 00772 const char *func_name() const { return "like_range_min"; } 00773 }; 00774 00775 00776 class Item_func_like_range_max :public Item_func_like_range 00777 { 00778 public: 00779 Item_func_like_range_max(Item *a, Item *b) 00780 :Item_func_like_range(a, b, false) { } 00781 const char *func_name() const { return "like_range_max"; } 00782 }; 00783 #endif 00784 00785 00786 class Item_char_typecast :public Item_str_func 00787 { 00788 int cast_length; 00789 const CHARSET_INFO *cast_cs, *from_cs; 00790 bool charset_conversion; 00791 String tmp_value; 00792 public: 00793 Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO *cs_arg) 00794 :Item_str_func(a), cast_length(length_arg), cast_cs(cs_arg) {} 00795 enum Functype functype() const { return CHAR_TYPECAST_FUNC; } 00796 bool eq(const Item *item, bool binary_cmp) const; 00797 const char *func_name() const { return "cast_as_char"; } 00798 String *val_str(String *a); 00799 void fix_length_and_dec(); 00800 virtual void print(String *str, enum_query_type query_type); 00801 }; 00802 00803 00804 class Item_func_binary :public Item_str_func 00805 { 00806 public: 00807 Item_func_binary(Item *a) :Item_str_func(a) {} 00808 String *val_str(String *a) 00809 { 00810 DBUG_ASSERT(fixed == 1); 00811 String *tmp=args[0]->val_str(a); 00812 null_value=args[0]->null_value; 00813 if (tmp) 00814 tmp->set_charset(&my_charset_bin); 00815 return tmp; 00816 } 00817 void fix_length_and_dec() 00818 { 00819 collation.set(&my_charset_bin); 00820 max_length=args[0]->max_length; 00821 } 00822 virtual void print(String *str, enum_query_type query_type); 00823 const char *func_name() const { return "cast_as_binary"; } 00824 }; 00825 00826 00827 class Item_load_file :public Item_str_func 00828 { 00829 String tmp_value; 00830 public: 00831 Item_load_file(Item *a) :Item_str_func(a) {} 00832 String *val_str(String *); 00833 const char *func_name() const { return "load_file"; } 00834 void fix_length_and_dec() 00835 { 00836 collation.set(&my_charset_bin, DERIVATION_COERCIBLE); 00837 maybe_null=1; 00838 max_length=MAX_BLOB_WIDTH; 00839 } 00840 }; 00841 00842 00843 class Item_func_export_set: public Item_str_func 00844 { 00845 public: 00846 Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {} 00847 Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {} 00848 Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {} 00849 String *val_str(String *str); 00850 void fix_length_and_dec(); 00851 const char *func_name() const { return "export_set"; } 00852 }; 00853 00854 class Item_func_quote :public Item_str_func 00855 { 00856 String tmp_value; 00857 public: 00858 Item_func_quote(Item *a) :Item_str_func(a) {} 00859 const char *func_name() const { return "quote"; } 00860 String *val_str(String *); 00861 void fix_length_and_dec() 00862 { 00863 collation.set(args[0]->collation); 00864 ulong max_result_length= (ulong) args[0]->max_length * 2 + 00865 2 * collation.collation->mbmaxlen; 00866 max_length= std::min<ulong>(max_result_length, MAX_BLOB_WIDTH); 00867 } 00868 }; 00869 00870 class Item_func_conv_charset :public Item_str_func 00871 { 00872 bool use_cached_value; 00873 String tmp_value; 00874 public: 00875 bool safe; 00876 const CHARSET_INFO *conv_charset; // keep it public 00877 Item_func_conv_charset(Item *a, const CHARSET_INFO *cs) :Item_str_func(a) 00878 { conv_charset= cs; use_cached_value= 0; safe= 0; } 00879 Item_func_conv_charset(Item *a, const CHARSET_INFO *cs, 00880 bool cache_if_const) :Item_str_func(a) 00881 { 00882 DBUG_ASSERT(args[0]->fixed); 00883 conv_charset= cs; 00884 if (cache_if_const && args[0]->const_item()) 00885 { 00886 uint errors= 0; 00887 String tmp, *str= args[0]->val_str(&tmp); 00888 if (!str || str_value.copy(str->ptr(), str->length(), 00889 str->charset(), conv_charset, &errors)) 00890 null_value= 1; 00891 use_cached_value= 1; 00892 str_value.mark_as_const(); 00893 safe= (errors == 0); 00894 } 00895 else 00896 { 00897 use_cached_value= 0; 00898 /* 00899 Conversion from and to "binary" is safe. 00900 Conversion to Unicode is safe. 00901 Other kind of conversions are potentially lossy. 00902 */ 00903 safe= (args[0]->collation.collation == &my_charset_bin || 00904 cs == &my_charset_bin || 00905 (cs->state & MY_CS_UNICODE)); 00906 } 00907 } 00908 String *val_str(String *); 00909 void fix_length_and_dec(); 00910 const char *func_name() const { return "convert"; } 00911 virtual void print(String *str, enum_query_type query_type); 00912 }; 00913 00914 class Item_func_set_collation :public Item_str_func 00915 { 00916 public: 00917 Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {}; 00918 String *val_str(String *); 00919 void fix_length_and_dec(); 00920 bool eq(const Item *item, bool binary_cmp) const; 00921 const char *func_name() const { return "collate"; } 00922 enum Functype functype() const { return COLLATE_FUNC; } 00923 virtual void print(String *str, enum_query_type query_type); 00924 Item_field *field_for_view_update() 00925 { 00926 /* this function is transparent for view updating */ 00927 return args[0]->field_for_view_update(); 00928 } 00929 }; 00930 00931 class Item_func_charset :public Item_str_func 00932 { 00933 public: 00934 Item_func_charset(Item *a) :Item_str_func(a) {} 00935 String *val_str(String *); 00936 const char *func_name() const { return "charset"; } 00937 void fix_length_and_dec() 00938 { 00939 collation.set(system_charset_info); 00940 max_length= 64 * collation.collation->mbmaxlen; // should be enough 00941 maybe_null= 0; 00942 }; 00943 table_map not_null_tables() const { return 0; } 00944 }; 00945 00946 class Item_func_collation :public Item_str_func 00947 { 00948 public: 00949 Item_func_collation(Item *a) :Item_str_func(a) {} 00950 String *val_str(String *); 00951 const char *func_name() const { return "collation"; } 00952 void fix_length_and_dec() 00953 { 00954 collation.set(system_charset_info); 00955 max_length= 64 * collation.collation->mbmaxlen; // should be enough 00956 maybe_null= 0; 00957 }; 00958 table_map not_null_tables() const { return 0; } 00959 }; 00960 00961 class Item_func_weight_string :public Item_str_func 00962 { 00963 String tmp_value; 00964 uint flags; 00965 uint nweights; 00966 uint result_length; 00967 Field *field; 00968 public: 00969 Item_func_weight_string(Item *a, uint result_length_arg, 00970 uint nweights_arg, uint flags_arg) 00971 :Item_str_func(a), field(NULL) 00972 { 00973 nweights= nweights_arg; 00974 flags= flags_arg; 00975 result_length= result_length_arg; 00976 } 00977 const char *func_name() const { return "weight_string"; } 00978 String *val_str(String *); 00979 void fix_length_and_dec(); 00980 }; 00981 00982 class Item_func_crc32 :public Item_int_func 00983 { 00984 String value; 00985 public: 00986 Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; } 00987 const char *func_name() const { return "crc32"; } 00988 void fix_length_and_dec() { max_length=10; } 00989 longlong val_int(); 00990 }; 00991 00992 class Item_func_uncompressed_length : public Item_int_func 00993 { 00994 String value; 00995 public: 00996 Item_func_uncompressed_length(Item *a):Item_int_func(a){} 00997 const char *func_name() const{return "uncompressed_length";} 00998 void fix_length_and_dec() { max_length=10; } 00999 longlong val_int(); 01000 }; 01001 01002 #ifdef HAVE_COMPRESS 01003 #define ZLIB_DEPENDED_FUNCTION ; 01004 #else 01005 #define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; } 01006 #endif 01007 01008 class Item_func_compress: public Item_str_func 01009 { 01010 String buffer; 01011 public: 01012 Item_func_compress(Item *a):Item_str_func(a){} 01013 void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} 01014 const char *func_name() const{return "compress";} 01015 String *val_str(String *) ZLIB_DEPENDED_FUNCTION 01016 }; 01017 01018 class Item_func_uncompress: public Item_str_func 01019 { 01020 String buffer; 01021 public: 01022 Item_func_uncompress(Item *a): Item_str_func(a){} 01023 void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; } 01024 const char *func_name() const{return "uncompress";} 01025 String *val_str(String *) ZLIB_DEPENDED_FUNCTION 01026 }; 01027 01028 class Item_func_uuid: public Item_str_func 01029 { 01030 public: 01031 Item_func_uuid(): Item_str_func() {} 01032 void fix_length_and_dec() 01033 { 01034 collation.set(system_charset_info, 01035 DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); 01036 fix_char_length(UUID_LENGTH); 01037 } 01038 const char *func_name() const{ return "uuid"; } 01039 String *val_str(String *); 01040 }; 01041 01042 class Item_func_gtid_subtract: public Item_str_ascii_func 01043 { 01044 String buf1, buf2; 01045 public: 01046 Item_func_gtid_subtract(Item *a, Item *b) :Item_str_ascii_func(a, b) {} 01047 void fix_length_and_dec(); 01048 const char *func_name() const{ return "gtid_subtract"; } 01049 String *val_str_ascii(String *); 01050 }; 01051 01052 #endif /* ITEM_STRFUNC_INCLUDED */