1 #ifndef ITEM_STRFUNC_INCLUDED 2 #define ITEM_STRFUNC_INCLUDED 3 4 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License, version 2.0, 8 as published by the Free Software Foundation. 9 10 This program is also distributed with certain software (including 11 but not limited to OpenSSL) that is licensed under separate terms, 12 as designated in a particular file or component or in included license 13 documentation. The authors of MySQL hereby grant you an additional 14 permission to link the program and your derivative works with the 15 separately licensed software that they have included with MySQL. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License, version 2.0, for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 25 26 27 /* This file defines all string functions */ 28 #include "crypt_genhash_impl.h" // CRYPT_MAX_PASSWORD_SIZE 29 #include "item_func.h" // Item_func 30 31 class MY_LOCALE; 32 33 class Item_str_func :public Item_func 34 { 35 typedef Item_func super; 36 37 public: Item_str_func()38 Item_str_func() :Item_func() { decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos)39 explicit Item_str_func(const POS &pos) :super(pos) { decimals=NOT_FIXED_DEC; } 40 Item_str_func(Item * a)41 Item_str_func(Item *a) :Item_func(a) {decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos,Item * a)42 Item_str_func(const POS &pos, Item *a) :Item_func(pos, a) 43 {decimals=NOT_FIXED_DEC; } 44 Item_str_func(Item * a,Item * b)45 Item_str_func(Item *a,Item *b) :Item_func(a,b) { decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos,Item * a,Item * b)46 Item_str_func(const POS &pos, Item *a,Item *b) :Item_func(pos, a,b) 47 { decimals=NOT_FIXED_DEC; } 48 Item_str_func(Item * a,Item * b,Item * c)49 Item_str_func(Item *a, Item *b, Item *c) :Item_func(a, b, c) 50 { decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos,Item * a,Item * b,Item * c)51 Item_str_func(const POS &pos, Item *a, Item *b, Item *c) 52 :Item_func(pos, a,b,c) 53 { decimals=NOT_FIXED_DEC; } 54 Item_str_func(Item * a,Item * b,Item * c,Item * d)55 Item_str_func(Item *a, Item *b, Item *c, Item *d) :Item_func(a, b, c, d) 56 {decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos,Item * a,Item * b,Item * c,Item * d)57 Item_str_func(const POS &pos, Item *a, Item *b, Item *c, Item *d) 58 :Item_func(pos, a,b,c,d) 59 {decimals=NOT_FIXED_DEC; } 60 Item_str_func(Item * a,Item * b,Item * c,Item * d,Item * e)61 Item_str_func(Item *a, Item *b, Item *c, Item *d, Item* e) 62 :Item_func(a, b, c, d, e) 63 {decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos,Item * a,Item * b,Item * c,Item * d,Item * e)64 Item_str_func(const POS &pos, Item *a, Item *b, Item *c, Item *d, Item* e) 65 :Item_func(pos, a, b, c, d, e) 66 {decimals=NOT_FIXED_DEC; } 67 Item_str_func(List<Item> & list)68 Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; } Item_str_func(const POS & pos,PT_item_list * opt_list)69 Item_str_func(const POS &pos, PT_item_list *opt_list) 70 :Item_func(pos, opt_list) 71 {decimals=NOT_FIXED_DEC; } 72 73 longlong val_int(); 74 double val_real(); 75 my_decimal *val_decimal(my_decimal *); get_date(MYSQL_TIME * ltime,my_time_flags_t fuzzydate)76 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) 77 { 78 return get_date_from_string(ltime, fuzzydate); 79 } get_time(MYSQL_TIME * ltime)80 bool get_time(MYSQL_TIME *ltime) 81 { 82 return get_time_from_string(ltime); 83 } result_type()84 enum Item_result result_type () const { return STRING_RESULT; } 85 void left_right_max_length(); 86 bool fix_fields(THD *thd, Item **ref); 87 String *val_str_from_val_str_ascii(String *str, String *str2); 88 }; 89 90 91 92 /* 93 Functions that return values with ASCII repertoire 94 */ 95 class Item_str_ascii_func :public Item_str_func 96 { 97 String ascii_buf; 98 public: Item_str_ascii_func()99 Item_str_ascii_func() :Item_str_func() 100 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 101 Item_str_ascii_func(Item * a)102 Item_str_ascii_func(Item *a) :Item_str_func(a) 103 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } Item_str_ascii_func(const POS & pos,Item * a)104 Item_str_ascii_func(const POS &pos, Item *a) :Item_str_func(pos, a) 105 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 106 Item_str_ascii_func(Item * a,Item * b)107 Item_str_ascii_func(Item *a,Item *b) :Item_str_func(a,b) 108 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } Item_str_ascii_func(const POS & pos,Item * a,Item * b)109 Item_str_ascii_func(const POS &pos, Item *a,Item *b) :Item_str_func(pos, a,b) 110 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 111 Item_str_ascii_func(Item * a,Item * b,Item * c)112 Item_str_ascii_func(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) 113 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } Item_str_ascii_func(const POS & pos,Item * a,Item * b,Item * c)114 Item_str_ascii_func(const POS &pos, Item *a,Item *b,Item *c) 115 :Item_str_func(pos, a,b,c) 116 { collation.set_repertoire(MY_REPERTOIRE_ASCII); } 117 val_str(String * str)118 String *val_str(String *str) 119 { 120 return val_str_from_val_str_ascii(str, &ascii_buf); 121 } 122 virtual String *val_str_ascii(String *)= 0; 123 }; 124 125 126 class Item_func_md5 :public Item_str_ascii_func 127 { 128 String tmp_value; 129 public: Item_func_md5(const POS & pos,Item * a)130 Item_func_md5(const POS &pos, Item *a) :Item_str_ascii_func(pos, a) {} 131 String *val_str_ascii(String *); 132 void fix_length_and_dec(); func_name()133 const char *func_name() const { return "md5"; } 134 }; 135 136 137 class Item_func_sha :public Item_str_ascii_func 138 { 139 public: Item_func_sha(const POS & pos,Item * a)140 Item_func_sha(const POS &pos, Item *a) :Item_str_ascii_func(pos, a) {} 141 String *val_str_ascii(String *); 142 void fix_length_and_dec(); func_name()143 const char *func_name() const { return "sha"; } 144 }; 145 146 class Item_func_sha2 :public Item_str_ascii_func 147 { 148 public: Item_func_sha2(const POS & pos,Item * a,Item * b)149 Item_func_sha2(const POS &pos, Item *a, Item *b) 150 :Item_str_ascii_func(pos, a, b) 151 {} 152 String *val_str_ascii(String *); 153 void fix_length_and_dec(); func_name()154 const char *func_name() const { return "sha2"; } 155 }; 156 157 class Item_func_to_base64 :public Item_str_ascii_func 158 { 159 String tmp_value; 160 public: Item_func_to_base64(const POS & pos,Item * a)161 Item_func_to_base64(const POS &pos, Item *a) :Item_str_ascii_func(pos, a) {} 162 String *val_str_ascii(String *); 163 void fix_length_and_dec(); func_name()164 const char *func_name() const { return "to_base64"; } 165 }; 166 167 class Item_func_from_base64 :public Item_str_func 168 { 169 String tmp_value; 170 public: Item_func_from_base64(const POS & pos,Item * a)171 Item_func_from_base64(const POS &pos, Item *a) :Item_str_func(pos, a) {} 172 String *val_str(String *); 173 void fix_length_and_dec(); func_name()174 const char *func_name() const { return "from_base64"; } 175 }; 176 177 178 class Item_func_aes_encrypt :public Item_str_func 179 { 180 typedef Item_str_func super; 181 public: Item_func_aes_encrypt(const POS & pos,Item * a,Item * b)182 Item_func_aes_encrypt(const POS &pos, Item *a, Item *b) 183 :Item_str_func(pos, a, b) 184 {} Item_func_aes_encrypt(const POS & pos,Item * a,Item * b,Item * c)185 Item_func_aes_encrypt(const POS &pos, Item *a, Item *b, Item *c) 186 :Item_str_func(pos, a, b, c) 187 {} 188 189 virtual bool itemize(Parse_context *pc, Item **res); 190 String *val_str(String *); 191 void fix_length_and_dec(); func_name()192 const char *func_name() const { return "aes_encrypt"; } 193 }; 194 195 class Item_func_aes_decrypt :public Item_str_func 196 { 197 typedef Item_str_func super; 198 public: Item_func_aes_decrypt(const POS & pos,Item * a,Item * b)199 Item_func_aes_decrypt(const POS &pos, Item *a, Item *b) 200 :Item_str_func(pos, a, b) 201 {} Item_func_aes_decrypt(const POS & pos,Item * a,Item * b,Item * c)202 Item_func_aes_decrypt(const POS &pos, Item *a, Item *b, Item *c) 203 :Item_str_func(pos, a, b, c) 204 {} 205 206 virtual bool itemize(Parse_context *pc, Item **res); 207 String *val_str(String *); 208 void fix_length_and_dec(); func_name()209 const char *func_name() const { return "aes_decrypt"; } 210 }; 211 212 213 class Item_func_random_bytes : public Item_str_func 214 { 215 typedef Item_str_func super; 216 217 /** limitation from the SSL library */ 218 static const longlong MAX_RANDOM_BYTES_BUFFER; 219 public: Item_func_random_bytes(const POS & pos,Item * a)220 Item_func_random_bytes(const POS &pos, Item *a) : Item_str_func(pos, a) 221 {} 222 223 virtual bool itemize(Parse_context *pc, Item **res); 224 void fix_length_and_dec(); 225 String *val_str(String *a); 226 func_name()227 const char *func_name() const 228 { 229 return "random_bytes"; 230 } 231 232 }; 233 234 class Item_func_concat :public Item_str_func 235 { 236 String tmp_value; 237 public: Item_func_concat(const POS & pos,PT_item_list * opt_list)238 Item_func_concat(const POS &pos, PT_item_list *opt_list) 239 : Item_str_func(pos, opt_list), tmp_value("", 0, collation.collation) {} Item_func_concat(Item * a,Item * b)240 Item_func_concat(Item *a, Item *b) 241 : Item_str_func(a, b), tmp_value("", 0, collation.collation) {} Item_func_concat(const POS & pos,Item * a,Item * b)242 Item_func_concat(const POS &pos, Item *a, Item *b) 243 : Item_str_func(pos, a, b), tmp_value("", 0, collation.collation) {} 244 245 String *val_str(String *); 246 void fix_length_and_dec(); func_name()247 const char *func_name() const { return "concat"; } 248 }; 249 250 class Item_func_concat_ws :public Item_str_func 251 { 252 String tmp_value; 253 public: Item_func_concat_ws(List<Item> & list)254 Item_func_concat_ws(List<Item> &list) 255 : Item_str_func(list), tmp_value("", 0, collation.collation) {} Item_func_concat_ws(const POS & pos,PT_item_list * opt_list)256 Item_func_concat_ws(const POS &pos, PT_item_list *opt_list) 257 : Item_str_func(pos, opt_list), tmp_value("", 0, collation.collation) {} 258 259 String *val_str(String *); 260 void fix_length_and_dec(); func_name()261 const char *func_name() const { return "concat_ws"; } not_null_tables()262 table_map not_null_tables() const { return 0; } 263 }; 264 265 class Item_func_reverse :public Item_str_func 266 { 267 String tmp_value; 268 public: Item_func_reverse(Item * a)269 Item_func_reverse(Item *a) :Item_str_func(a) {} Item_func_reverse(const POS & pos,Item * a)270 Item_func_reverse(const POS &pos, Item *a) :Item_str_func(pos, a) {} 271 272 String *val_str(String *); 273 void fix_length_and_dec(); func_name()274 const char *func_name() const { return "reverse"; } 275 }; 276 277 278 class Item_func_replace :public Item_str_func 279 { 280 String tmp_value,tmp_value2; 281 /// Holds result in case we need to allocate our own result buffer. 282 String tmp_value_res; 283 public: Item_func_replace(const POS & pos,Item * org,Item * find,Item * replace)284 Item_func_replace(const POS &pos, Item *org,Item *find,Item *replace) 285 :Item_str_func(pos, org,find,replace) 286 {} 287 String *val_str(String *); 288 void fix_length_and_dec(); func_name()289 const char *func_name() const { return "replace"; } 290 }; 291 292 293 class Item_func_insert :public Item_str_func 294 { 295 String tmp_value; 296 /// Holds result in case we need to allocate our own result buffer. 297 String tmp_value_res; 298 public: Item_func_insert(const POS & pos,Item * org,Item * start,Item * length,Item * new_str)299 Item_func_insert(const POS &pos, 300 Item *org, Item *start, Item *length, Item *new_str) 301 :Item_str_func(pos, org,start,length,new_str) 302 {} 303 String *val_str(String *); 304 void fix_length_and_dec(); func_name()305 const char *func_name() const { return "insert"; } 306 }; 307 308 309 class Item_str_conv :public Item_str_func 310 { 311 protected: 312 uint multiply; 313 my_charset_conv_case converter; 314 String tmp_value; 315 public: Item_str_conv(const POS & pos,Item * item)316 Item_str_conv(const POS &pos, Item *item) :Item_str_func(pos, item) {} 317 String *val_str(String *); 318 }; 319 320 321 class Item_func_lower :public Item_str_conv 322 { 323 public: Item_func_lower(const POS & pos,Item * item)324 Item_func_lower(const POS &pos, Item *item) :Item_str_conv(pos, item) {} func_name()325 const char *func_name() const { return "lower"; } 326 void fix_length_and_dec(); 327 }; 328 329 class Item_func_upper :public Item_str_conv 330 { 331 public: Item_func_upper(const POS & pos,Item * item)332 Item_func_upper(const POS &pos, Item *item) :Item_str_conv(pos, item) {} func_name()333 const char *func_name() const { return "upper"; } 334 void fix_length_and_dec(); 335 }; 336 337 338 class Item_func_left :public Item_str_func 339 { 340 String tmp_value; 341 public: Item_func_left(const POS & pos,Item * a,Item * b)342 Item_func_left(const POS &pos, Item *a,Item *b) :Item_str_func(pos, a,b) {} 343 String *val_str(String *); 344 void fix_length_and_dec(); func_name()345 const char *func_name() const { return "left"; } 346 }; 347 348 349 class Item_func_right :public Item_str_func 350 { 351 String tmp_value; 352 public: Item_func_right(const POS & pos,Item * a,Item * b)353 Item_func_right(const POS &pos, Item *a,Item *b) :Item_str_func(pos, a,b) {} 354 String *val_str(String *); 355 void fix_length_and_dec(); func_name()356 const char *func_name() const { return "right"; } 357 }; 358 359 360 class Item_func_substr :public Item_str_func 361 { 362 typedef Item_str_func super; 363 364 String tmp_value; 365 public: Item_func_substr(Item * a,Item * b)366 Item_func_substr(Item *a,Item *b) :Item_str_func(a,b) {} Item_func_substr(const POS & pos,Item * a,Item * b)367 Item_func_substr(const POS &pos, Item *a,Item *b) :super(pos, a,b) {} 368 Item_func_substr(Item * a,Item * b,Item * c)369 Item_func_substr(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} Item_func_substr(const POS & pos,Item * a,Item * b,Item * c)370 Item_func_substr(const POS &pos, Item *a,Item *b,Item *c) :super(pos, a, b, c) 371 {} 372 373 String *val_str(String *); 374 void fix_length_and_dec(); func_name()375 const char *func_name() const { return "substr"; } 376 }; 377 378 379 class Item_func_substr_index :public Item_str_func 380 { 381 String tmp_value; 382 public: Item_func_substr_index(const POS & pos,Item * a,Item * b,Item * c)383 Item_func_substr_index(const POS &pos, Item *a,Item *b, Item *c) 384 :Item_str_func(pos, a, b, c) 385 {} 386 String *val_str(String *); 387 void fix_length_and_dec(); func_name()388 const char *func_name() const { return "substring_index"; } 389 }; 390 391 392 class Item_func_trim :public Item_str_func 393 { 394 public: 395 /** 396 Why all the trim modes in this enum? 397 We need to maintain parsing information, so that our print() function 398 can reproduce correct messages and view definitions. 399 */ 400 enum TRIM_MODE 401 { 402 TRIM_BOTH_DEFAULT, 403 TRIM_BOTH, 404 TRIM_LEADING, 405 TRIM_TRAILING, 406 TRIM_LTRIM, 407 TRIM_RTRIM 408 }; 409 410 private: 411 String tmp_value; 412 String remove; 413 const TRIM_MODE m_trim_mode; 414 const bool m_trim_leading; 415 const bool m_trim_trailing; 416 417 public: Item_func_trim(Item * a,Item * b,TRIM_MODE tm)418 Item_func_trim(Item *a, Item *b, TRIM_MODE tm) 419 : Item_str_func(a,b), m_trim_mode(tm), 420 m_trim_leading(trim_leading()), m_trim_trailing(trim_trailing()) 421 {} 422 Item_func_trim(const POS & pos,Item * a,Item * b,TRIM_MODE tm)423 Item_func_trim(const POS &pos, Item *a, Item *b, TRIM_MODE tm) 424 : Item_str_func(pos, a,b), m_trim_mode(tm), 425 m_trim_leading(trim_leading()), m_trim_trailing(trim_trailing()) 426 {} 427 Item_func_trim(Item * a,TRIM_MODE tm)428 Item_func_trim(Item *a, TRIM_MODE tm) 429 : Item_str_func(a), m_trim_mode(tm), 430 m_trim_leading(trim_leading()), m_trim_trailing(trim_trailing()) 431 {} 432 Item_func_trim(const POS & pos,Item * a,TRIM_MODE tm)433 Item_func_trim(const POS &pos, Item *a, TRIM_MODE tm) 434 : Item_str_func(pos, a), m_trim_mode(tm), 435 m_trim_leading(trim_leading()), m_trim_trailing(trim_trailing()) 436 {} 437 trim_leading()438 bool trim_leading() const 439 { 440 return 441 m_trim_mode == TRIM_BOTH_DEFAULT || 442 m_trim_mode == TRIM_BOTH || 443 m_trim_mode == TRIM_LEADING || 444 m_trim_mode == TRIM_LTRIM; 445 } 446 trim_trailing()447 bool trim_trailing() const 448 { 449 return 450 m_trim_mode == TRIM_BOTH_DEFAULT || 451 m_trim_mode == TRIM_BOTH || 452 m_trim_mode == TRIM_TRAILING || 453 m_trim_mode == TRIM_RTRIM; 454 } 455 456 String *val_str(String *); 457 void fix_length_and_dec(); func_name()458 const char *func_name() const 459 { 460 switch(m_trim_mode) { 461 case TRIM_BOTH_DEFAULT: return "trim"; 462 case TRIM_BOTH: return "trim"; 463 case TRIM_LEADING: return "ltrim"; 464 case TRIM_TRAILING: return "rtrim"; 465 case TRIM_LTRIM: return "ltrim"; 466 case TRIM_RTRIM: return "rtrim"; 467 } 468 return NULL; 469 } 470 virtual void print(String *str, enum_query_type query_type); 471 }; 472 473 474 /* 475 Item_func_password -- new (4.1.1) PASSWORD() function implementation. 476 Returns strcat('*', octet2hex(sha1(sha1(password)))). '*' stands for new 477 password format, sha1(sha1(password) is so-called hash_stage2 value. 478 Length of returned string is always 41 byte. To find out how entire 479 authentication procedure works, see comments in password.c. 480 */ 481 482 class Item_func_password :public Item_str_ascii_func 483 { 484 char m_hashed_password_buffer[CRYPT_MAX_PASSWORD_SIZE + 1]; 485 unsigned int m_hashed_password_buffer_len; 486 bool m_recalculate_password; 487 public: Item_func_password(Item * a)488 Item_func_password(Item *a) : Item_str_ascii_func(a) 489 { 490 m_hashed_password_buffer_len= 0; 491 m_recalculate_password= false; 492 } 493 String *val_str_ascii(String *str); 494 void fix_length_and_dec(); func_name()495 const char *func_name() const { return "password"; } 496 }; 497 498 499 class Item_func_des_encrypt :public Item_str_func 500 { 501 String tmp_value,tmp_arg; 502 public: Item_func_des_encrypt(const POS & pos,Item * a)503 Item_func_des_encrypt(const POS &pos, Item *a) :Item_str_func(pos, a) {} Item_func_des_encrypt(const POS & pos,Item * a,Item * b)504 Item_func_des_encrypt(const POS &pos, Item *a, Item *b) 505 : Item_str_func(pos, a, b) 506 {} 507 String *val_str(String *); fix_length_and_dec()508 void fix_length_and_dec() 509 { 510 maybe_null=1; 511 /* 9 = MAX ((8- (arg_len % 8)) + 1) */ 512 max_length = args[0]->max_length + 9; 513 } func_name()514 const char *func_name() const { return "des_encrypt"; } 515 }; 516 517 class Item_func_des_decrypt :public Item_str_func 518 { 519 String tmp_value; 520 public: Item_func_des_decrypt(const POS & pos,Item * a)521 Item_func_des_decrypt(const POS &pos, Item *a) :Item_str_func(pos, a) {} Item_func_des_decrypt(const POS & pos,Item * a,Item * b)522 Item_func_des_decrypt(const POS &pos, Item *a, Item *b) 523 : Item_str_func(pos, a, b) 524 {} 525 String *val_str(String *); fix_length_and_dec()526 void fix_length_and_dec() 527 { 528 maybe_null=1; 529 /* 9 = MAX ((8- (arg_len % 8)) + 1) */ 530 max_length= args[0]->max_length; 531 if (max_length >= 9U) 532 max_length-= 9U; 533 } func_name()534 const char *func_name() const { return "des_decrypt"; } 535 }; 536 537 class Item_func_encrypt :public Item_str_func 538 { 539 typedef Item_str_func super; 540 541 String tmp_value; 542 543 /* Encapsulate common constructor actions */ constructor_helper()544 void constructor_helper() 545 { 546 collation.set(&my_charset_bin); 547 } 548 public: Item_func_encrypt(const POS & pos,Item * a)549 Item_func_encrypt(const POS &pos, Item *a) :Item_str_func(pos, a) 550 { 551 constructor_helper(); 552 } Item_func_encrypt(const POS & pos,Item * a,Item * b)553 Item_func_encrypt(const POS &pos, Item *a, Item *b): Item_str_func(pos, a, b) 554 { 555 constructor_helper(); 556 } 557 558 virtual bool itemize(Parse_context *pc, Item **res); 559 String *val_str(String *); fix_length_and_dec()560 void fix_length_and_dec() { maybe_null=1; max_length = 13; } func_name()561 const char *func_name() const { return "encrypt"; } check_gcol_func_processor(uchar * int_arg)562 bool check_gcol_func_processor(uchar *int_arg) 563 { return true; } 564 }; 565 566 #include "sql_crypt.h" 567 568 569 class Item_func_encode :public Item_str_func 570 { 571 private: 572 /** Whether the PRNG has already been seeded. */ 573 bool seeded; 574 /// Holds result in case we need to allocate our own result buffer. 575 String tmp_value_res; 576 protected: 577 SQL_CRYPT sql_crypt; 578 public: Item_func_encode(const POS & pos,Item * a,Item * seed)579 Item_func_encode(const POS &pos, Item *a, Item *seed) 580 :Item_str_func(pos, a, seed) 581 {} 582 String *val_str(String *); 583 void fix_length_and_dec(); func_name()584 const char *func_name() const { return "encode"; } 585 protected: 586 virtual void crypto_transform(String *); 587 private: 588 /** Provide a seed for the PRNG sequence. */ 589 bool seed(); 590 }; 591 592 593 class Item_func_decode :public Item_func_encode 594 { 595 public: Item_func_decode(const POS & pos,Item * a,Item * seed)596 Item_func_decode(const POS &pos, Item *a, Item *seed) 597 :Item_func_encode(pos, a, seed) 598 {} func_name()599 const char *func_name() const { return "decode"; } 600 protected: 601 void crypto_transform(String *); 602 }; 603 604 605 class Item_func_sysconst :public Item_str_func 606 { 607 typedef Item_str_func super; 608 609 public: Item_func_sysconst()610 Item_func_sysconst() 611 { collation.set(system_charset_info,DERIVATION_SYSCONST); } Item_func_sysconst(const POS & pos)612 explicit Item_func_sysconst(const POS &pos) : super(pos) 613 { collation.set(system_charset_info,DERIVATION_SYSCONST); } 614 615 Item *safe_charset_converter(const CHARSET_INFO *tocs); 616 /* 617 Used to create correct Item name in new converted item in 618 safe_charset_converter, return string representation of this function 619 call 620 */ 621 virtual const Name_string fully_qualified_func_name() const = 0; check_gcol_func_processor(uchar * int_arg)622 bool check_gcol_func_processor(uchar *int_arg) 623 { return true; } 624 }; 625 626 627 class Item_func_database :public Item_func_sysconst 628 { 629 typedef Item_func_sysconst super; 630 631 public: Item_func_database(const POS & pos)632 explicit Item_func_database(const POS &pos) :Item_func_sysconst(pos) {} 633 634 virtual bool itemize(Parse_context *pc, Item **res); 635 636 String *val_str(String *); fix_length_and_dec()637 void fix_length_and_dec() 638 { 639 max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; 640 maybe_null=1; 641 } func_name()642 const char *func_name() const { return "database"; } fully_qualified_func_name()643 const Name_string fully_qualified_func_name() const 644 { return NAME_STRING("database()"); } 645 }; 646 647 648 class Item_func_user :public Item_func_sysconst 649 { 650 typedef Item_func_sysconst super; 651 652 protected: 653 bool init (const char *user, const char *host); save_in_field_inner(Field * field,bool no_conversions)654 type_conversion_status save_in_field_inner(Field *field, bool no_conversions) 655 { 656 return save_str_value_in_field(field, &str_value); 657 } 658 659 public: Item_func_user()660 Item_func_user() 661 { 662 str_value.set("", 0, system_charset_info); 663 } Item_func_user(const POS & pos)664 explicit Item_func_user(const POS &pos) : super(pos) 665 { 666 str_value.set("", 0, system_charset_info); 667 } 668 669 virtual bool itemize(Parse_context *pc, Item **res); 670 val_str(String *)671 String *val_str(String *) 672 { 673 assert(fixed == 1); 674 return (null_value ? 0 : &str_value); 675 } 676 bool fix_fields(THD *thd, Item **ref); fix_length_and_dec()677 void fix_length_and_dec() 678 { 679 max_length= (USERNAME_LENGTH + 680 (HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN); 681 } func_name()682 const char *func_name() const { return "user"; } fully_qualified_func_name()683 const Name_string fully_qualified_func_name() const 684 { return NAME_STRING("user()"); } 685 }; 686 687 688 class Item_func_current_user :public Item_func_user 689 { 690 typedef Item_func_user super; 691 692 Name_resolution_context *context; 693 694 public: Item_func_current_user(const POS & pos)695 explicit Item_func_current_user(const POS &pos) : super(pos) {} 696 697 virtual bool itemize(Parse_context *pc, Item **res); 698 699 bool fix_fields(THD *thd, Item **ref); func_name()700 const char *func_name() const { return "current_user"; } fully_qualified_func_name()701 const Name_string fully_qualified_func_name() const 702 { return NAME_STRING("current_user()"); } 703 }; 704 705 706 class Item_func_soundex :public Item_str_func 707 { 708 String tmp_value; 709 public: Item_func_soundex(Item * a)710 Item_func_soundex(Item *a) :Item_str_func(a) {} Item_func_soundex(const POS & pos,Item * a)711 Item_func_soundex(const POS &pos, Item *a) :Item_str_func(pos, a) {} 712 String *val_str(String *); 713 void fix_length_and_dec(); func_name()714 const char *func_name() const { return "soundex"; } 715 }; 716 717 718 /** 719 This class handles two forms of the same function: 720 721 <string> = ST_GEOHASH(<point>, <maxlength>); 722 <string> = ST_GEOHASH(<longitude>, <latitude>, <maxlength>) 723 724 It returns an encoded geohash string, no longer than <maxlength> characters 725 long. Note that it might be shorter than <maxlength>. 726 */ 727 class Item_func_geohash :public Item_str_ascii_func 728 { 729 private: 730 /// The latitude argument supplied by the user (directly or by a POINT). 731 double latitude; 732 /// The longitude argument supplied by the user (directly or by a POINT). 733 double longitude; 734 /// The maximum output length of the geohash, supplied by the user. 735 uint geohash_max_output_length; 736 737 /** 738 The maximum input latitude. For now, this is set to 90.0. It can be 739 changed to support a different range than the normal [90, -90]. 740 */ 741 const double max_latitude; 742 743 /** 744 The minimum input latitude. For now, this is set to -90.0. It can be 745 changed to support a different range than the normal [90, -90]. 746 */ 747 const double min_latitude; 748 749 /** 750 The maximum input longitude. For now, this is set to 180.0. It can be 751 changed to support a different range than the normal [180, -180]. 752 */ 753 const double max_longitude; 754 755 /** 756 The minimum input longitude. For now, this is set to -180.0. It can be 757 changed to support a different range than the normal [180, -180]. 758 */ 759 const double min_longitude; 760 761 /** 762 The absolute upper limit of geohash output length. User will get an error 763 if they supply a max geohash length argument greater than this. 764 */ 765 const uint upper_limit_output_length; 766 public: Item_func_geohash(const POS & pos,Item * point,Item * length)767 Item_func_geohash(const POS &pos, Item *point, Item *length) 768 :Item_str_ascii_func(pos, point, length), max_latitude(90.0), 769 min_latitude(-90.0), max_longitude(180.0), min_longitude(-180.0), 770 upper_limit_output_length(100) 771 {} Item_func_geohash(const POS & pos,Item * longitude,Item * latitude,Item * length)772 Item_func_geohash(const POS &pos, Item *longitude, Item *latitude, 773 Item *length) 774 :Item_str_ascii_func(pos, longitude, latitude, length), max_latitude(90.0), 775 min_latitude(-90.0), max_longitude(180.0), min_longitude(-180.0), 776 upper_limit_output_length(100) 777 {} 778 String *val_str_ascii(String *); 779 void fix_length_and_dec(); 780 bool fix_fields(THD *thd, Item **ref); func_name()781 const char *func_name() const { return "st_geohash"; } 782 char char_to_base32(char char_input); 783 void encode_bit(double *upper_value, double *lower_value, 784 double target_value, char *char_value, int bit_number); 785 bool fill_and_check_fields(); 786 bool check_valid_latlong_type(Item *ref); 787 static bool is_item_null(Item *item); 788 }; 789 790 791 class Item_func_elt :public Item_str_func 792 { 793 public: Item_func_elt(const POS & pos,PT_item_list * opt_list)794 Item_func_elt(const POS &pos, PT_item_list *opt_list) 795 :Item_str_func(pos, opt_list) 796 {} 797 double val_real(); 798 longlong val_int(); 799 String *val_str(String *str); 800 void fix_length_and_dec(); func_name()801 const char *func_name() const { return "elt"; } 802 }; 803 804 805 class Item_func_make_set :public Item_str_func 806 { 807 typedef Item_str_func super; 808 809 Item *item; 810 String tmp_str; 811 812 public: Item_func_make_set(const POS & pos,Item * a,PT_item_list * opt_list)813 Item_func_make_set(const POS &pos, Item *a, PT_item_list *opt_list) 814 :Item_str_func(pos, opt_list), item(a) 815 {} 816 817 virtual bool itemize(Parse_context *pc, Item **res); 818 String *val_str(String *str); fix_fields(THD * thd,Item ** ref)819 bool fix_fields(THD *thd, Item **ref) 820 { 821 assert(fixed == 0); 822 bool res= ((!item->fixed && item->fix_fields(thd, &item)) || 823 item->check_cols(1) || 824 Item_func::fix_fields(thd, ref)); 825 maybe_null|= item->maybe_null; 826 return res; 827 } 828 void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, 829 List<Item> &fields); 830 void fix_length_and_dec(); 831 void update_used_tables(); func_name()832 const char *func_name() const { return "make_set"; } 833 walk(Item_processor processor,enum_walk walk,uchar * arg)834 bool walk(Item_processor processor, enum_walk walk, uchar *arg) 835 { 836 if ((walk & WALK_PREFIX) && (this->*processor)(arg)) 837 return true; 838 if (item->walk(processor, walk, arg)) 839 return true; 840 for (uint i= 0; i < arg_count; i++) 841 { 842 if (args[i]->walk(processor, walk, arg)) 843 return true; 844 } 845 return ((walk & WALK_POSTFIX) && (this->*processor)(arg)); 846 } 847 848 Item *transform(Item_transformer transformer, uchar *arg); 849 virtual void print(String *str, enum_query_type query_type); 850 }; 851 852 853 class Item_func_format :public Item_str_ascii_func 854 { 855 String tmp_str; 856 MY_LOCALE *locale; 857 public: Item_func_format(const POS & pos,Item * org,Item * dec)858 Item_func_format(const POS &pos, Item *org, Item *dec) 859 : Item_str_ascii_func(pos, org, dec) 860 {} Item_func_format(const POS & pos,Item * org,Item * dec,Item * lang)861 Item_func_format(const POS &pos, Item *org, Item *dec, Item *lang) 862 : Item_str_ascii_func(pos, org, dec, lang) 863 {} 864 865 MY_LOCALE *get_locale(Item *item); 866 String *val_str_ascii(String *); 867 void fix_length_and_dec(); func_name()868 const char *func_name() const { return "format"; } 869 virtual void print(String *str, enum_query_type query_type); 870 }; 871 872 873 class Item_func_char :public Item_str_func 874 { 875 public: Item_func_char(const POS & pos,PT_item_list * list)876 Item_func_char(const POS &pos, PT_item_list *list) :Item_str_func(pos, list) 877 { collation.set(&my_charset_bin); } Item_func_char(const POS & pos,PT_item_list * list,const CHARSET_INFO * cs)878 Item_func_char(const POS &pos, PT_item_list *list, const CHARSET_INFO *cs) 879 : Item_str_func(pos, list) 880 { collation.set(cs); } 881 String *val_str(String *); fix_length_and_dec()882 void fix_length_and_dec() 883 { 884 max_length= arg_count * 4; 885 } func_name()886 const char *func_name() const { return "char"; } 887 }; 888 889 890 class Item_func_repeat :public Item_str_func 891 { 892 String tmp_value; 893 public: Item_func_repeat(const POS & pos,Item * arg1,Item * arg2)894 Item_func_repeat(const POS &pos, Item *arg1,Item *arg2) 895 :Item_str_func(pos, arg1,arg2) 896 {} 897 String *val_str(String *); 898 void fix_length_and_dec(); func_name()899 const char *func_name() const { return "repeat"; } 900 }; 901 902 903 class Item_func_space :public Item_str_func 904 { 905 public: Item_func_space(const POS & pos,Item * arg1)906 Item_func_space(const POS &pos, Item *arg1) :Item_str_func(pos, arg1) {} 907 String *val_str(String *); 908 void fix_length_and_dec(); func_name()909 const char *func_name() const { return "space"; } 910 }; 911 912 913 class Item_func_rpad :public Item_str_func 914 { 915 String tmp_value, rpad_str; 916 public: Item_func_rpad(const POS & pos,Item * arg1,Item * arg2,Item * arg3)917 Item_func_rpad(const POS &pos, Item *arg1, Item *arg2, Item *arg3) 918 :Item_str_func(pos, arg1, arg2, arg3) 919 {} 920 String *val_str(String *); 921 void fix_length_and_dec(); func_name()922 const char *func_name() const { return "rpad"; } 923 }; 924 925 926 class Item_func_lpad :public Item_str_func 927 { 928 String tmp_value, lpad_str; 929 public: Item_func_lpad(const POS & pos,Item * arg1,Item * arg2,Item * arg3)930 Item_func_lpad(const POS &pos, Item *arg1, Item *arg2, Item *arg3) 931 :Item_str_func(pos , arg1, arg2, arg3) 932 {} 933 String *val_str(String *); 934 void fix_length_and_dec(); func_name()935 const char *func_name() const { return "lpad"; } 936 }; 937 938 939 class Item_func_conv :public Item_str_func 940 { 941 public: Item_func_conv(const POS & pos,Item * a,Item * b,Item * c)942 Item_func_conv(const POS &pos, Item *a,Item *b,Item *c) 943 :Item_str_func(pos, a,b,c) 944 {} func_name()945 const char *func_name() const { return "conv"; } 946 String *val_str(String *); 947 void fix_length_and_dec(); 948 }; 949 950 951 class Item_func_hex :public Item_str_ascii_func 952 { 953 String tmp_value; 954 public: Item_func_hex(const POS & pos,Item * a)955 Item_func_hex(const POS &pos, Item *a) :Item_str_ascii_func(pos, a) {} func_name()956 const char *func_name() const { return "hex"; } 957 String *val_str_ascii(String *); fix_length_and_dec()958 void fix_length_and_dec() 959 { 960 collation.set(default_charset()); 961 decimals=0; 962 fix_char_length(args[0]->max_length * 2); 963 } 964 }; 965 966 class Item_func_unhex :public Item_str_func 967 { 968 String tmp_value; 969 public: Item_func_unhex(const POS & pos,Item * a)970 Item_func_unhex(const POS &pos, Item *a) :Item_str_func(pos, a) 971 { 972 /* there can be bad hex strings */ 973 maybe_null= 1; 974 } func_name()975 const char *func_name() const { return "unhex"; } 976 String *val_str(String *); fix_length_and_dec()977 void fix_length_and_dec() 978 { 979 collation.set(&my_charset_bin); 980 decimals=0; 981 max_length=(1+args[0]->max_length)/2; 982 } 983 }; 984 985 986 #ifndef NDEBUG 987 class Item_func_like_range :public Item_str_func 988 { 989 protected: 990 String min_str; 991 String max_str; 992 const bool is_min; 993 public: Item_func_like_range(const POS & pos,Item * a,Item * b,bool is_min_arg)994 Item_func_like_range(const POS &pos, Item *a, Item *b, bool is_min_arg) 995 :Item_str_func(pos, a, b), is_min(is_min_arg) 996 { maybe_null= 1; } 997 String *val_str(String *); fix_length_and_dec()998 void fix_length_and_dec() 999 { 1000 collation.set(args[0]->collation); 1001 decimals=0; 1002 max_length= MAX_BLOB_WIDTH; 1003 } 1004 }; 1005 1006 1007 class Item_func_like_range_min :public Item_func_like_range 1008 { 1009 public: Item_func_like_range_min(const POS & pos,Item * a,Item * b)1010 Item_func_like_range_min(const POS &pos, Item *a, Item *b) 1011 :Item_func_like_range(pos, a, b, true) 1012 { } func_name()1013 const char *func_name() const { return "like_range_min"; } 1014 }; 1015 1016 1017 class Item_func_like_range_max :public Item_func_like_range 1018 { 1019 public: Item_func_like_range_max(const POS & pos,Item * a,Item * b)1020 Item_func_like_range_max(const POS &pos, Item *a, Item *b) 1021 :Item_func_like_range(pos, a, b, false) 1022 { } func_name()1023 const char *func_name() const { return "like_range_max"; } 1024 }; 1025 #endif 1026 1027 1028 class Item_char_typecast :public Item_str_func 1029 { 1030 int cast_length; 1031 const CHARSET_INFO *cast_cs, *from_cs; 1032 bool charset_conversion; 1033 String tmp_value; 1034 public: Item_char_typecast(Item * a,int length_arg,const CHARSET_INFO * cs_arg)1035 Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO *cs_arg) 1036 :Item_str_func(a), cast_length(length_arg), cast_cs(cs_arg) {} Item_char_typecast(const POS & pos,Item * a,int length_arg,const CHARSET_INFO * cs_arg)1037 Item_char_typecast(const POS &pos, Item *a, int length_arg, 1038 const CHARSET_INFO *cs_arg) 1039 :Item_str_func(pos, a), cast_length(length_arg), cast_cs(cs_arg) 1040 {} functype()1041 enum Functype functype() const { return TYPECAST_FUNC; } 1042 bool eq(const Item *item, bool binary_cmp) const; func_name()1043 const char *func_name() const { return "cast_as_char"; } 1044 String *val_str(String *a); 1045 void fix_length_and_dec(); 1046 virtual void print(String *str, enum_query_type query_type); 1047 }; 1048 1049 1050 class Item_func_binary :public Item_str_func 1051 { 1052 public: Item_func_binary(const POS & pos,Item * a)1053 Item_func_binary(const POS &pos, Item *a) :Item_str_func(pos, a) {} val_str(String * a)1054 String *val_str(String *a) 1055 { 1056 assert(fixed == 1); 1057 String *tmp=args[0]->val_str(a); 1058 null_value=args[0]->null_value; 1059 if (tmp) 1060 tmp->set_charset(&my_charset_bin); 1061 return tmp; 1062 } fix_length_and_dec()1063 void fix_length_and_dec() 1064 { 1065 collation.set(&my_charset_bin); 1066 max_length=args[0]->max_length; 1067 } 1068 virtual void print(String *str, enum_query_type query_type); func_name()1069 const char *func_name() const { return "cast_as_binary"; } functype()1070 enum Functype functype() const { return TYPECAST_FUNC; } 1071 }; 1072 1073 1074 class Item_load_file :public Item_str_func 1075 { 1076 typedef Item_str_func super; 1077 1078 String tmp_value; 1079 public: Item_load_file(const POS & pos,Item * a)1080 Item_load_file(const POS &pos, Item *a) :Item_str_func(pos, a) {} 1081 1082 virtual bool itemize(Parse_context *pc, Item **res); 1083 String *val_str(String *); func_name()1084 const char *func_name() const { return "load_file"; } fix_length_and_dec()1085 void fix_length_and_dec() 1086 { 1087 collation.set(&my_charset_bin, DERIVATION_COERCIBLE); 1088 maybe_null=1; 1089 max_length=MAX_BLOB_WIDTH; 1090 } check_gcol_func_processor(uchar * int_arg)1091 bool check_gcol_func_processor(uchar *int_arg) 1092 { return true; } 1093 }; 1094 1095 1096 class Item_func_export_set: public Item_str_func 1097 { 1098 public: Item_func_export_set(const POS & pos,Item * a,Item * b,Item * c)1099 Item_func_export_set(const POS &pos, Item *a, Item *b, Item* c) 1100 :Item_str_func(pos, a, b, c) 1101 {} Item_func_export_set(const POS & pos,Item * a,Item * b,Item * c,Item * d)1102 Item_func_export_set(const POS &pos, Item *a, Item *b, Item* c, Item* d) 1103 :Item_str_func(pos, a, b, c, d) 1104 {} Item_func_export_set(const POS & pos,Item * a,Item * b,Item * c,Item * d,Item * e)1105 Item_func_export_set(const POS &pos, 1106 Item *a, Item *b, Item* c, Item* d, Item* e) 1107 :Item_str_func(pos, a, b, c, d, e) 1108 {} 1109 String *val_str(String *str); 1110 void fix_length_and_dec(); func_name()1111 const char *func_name() const { return "export_set"; } 1112 }; 1113 1114 class Item_func_quote :public Item_str_func 1115 { 1116 String tmp_value; 1117 public: Item_func_quote(const POS & pos,Item * a)1118 Item_func_quote(const POS &pos, Item *a) :Item_str_func(pos, a) {} func_name()1119 const char *func_name() const { return "quote"; } 1120 String *val_str(String *); fix_length_and_dec()1121 void fix_length_and_dec() 1122 { 1123 collation.set(args[0]->collation); 1124 ulong max_result_length= (ulong) args[0]->max_length * 2 + 1125 2 * collation.collation->mbmaxlen; 1126 max_length= std::min<ulong>(max_result_length, MAX_BLOB_WIDTH); 1127 } 1128 }; 1129 1130 class Item_func_conv_charset :public Item_str_func 1131 { 1132 bool use_cached_value; 1133 String tmp_value; 1134 public: 1135 bool safe; 1136 const CHARSET_INFO *conv_charset; // keep it public Item_func_conv_charset(const POS & pos,Item * a,const CHARSET_INFO * cs)1137 Item_func_conv_charset(const POS &pos, Item *a, const CHARSET_INFO *cs) 1138 : Item_str_func(pos, a) 1139 { conv_charset= cs; use_cached_value= 0; safe= 0; } Item_func_conv_charset(Item * a,const CHARSET_INFO * cs,bool cache_if_const)1140 Item_func_conv_charset(Item *a, const CHARSET_INFO *cs, 1141 bool cache_if_const) :Item_str_func(a) 1142 { 1143 assert(is_fixed_or_outer_ref(args[0])); 1144 1145 conv_charset= cs; 1146 if (cache_if_const && args[0]->const_item()) 1147 { 1148 uint errors= 0; 1149 String tmp, *str= args[0]->val_str(&tmp); 1150 if (!str || str_value.copy(str->ptr(), str->length(), 1151 str->charset(), conv_charset, &errors)) 1152 null_value= 1; 1153 use_cached_value= 1; 1154 str_value.mark_as_const(); 1155 safe= (errors == 0); 1156 } 1157 else 1158 { 1159 use_cached_value= 0; 1160 /* 1161 Conversion from and to "binary" is safe. 1162 Conversion to Unicode is safe. 1163 Other kind of conversions are potentially lossy. 1164 */ 1165 safe= (args[0]->collation.collation == &my_charset_bin || 1166 cs == &my_charset_bin || 1167 (cs->state & MY_CS_UNICODE)); 1168 } 1169 } 1170 String *val_str(String *); 1171 void fix_length_and_dec(); func_name()1172 const char *func_name() const { return "convert"; } 1173 virtual void print(String *str, enum_query_type query_type); 1174 }; 1175 1176 class Item_func_set_collation :public Item_str_func 1177 { 1178 typedef Item_str_func super; 1179 1180 LEX_STRING collation_string; 1181 public: Item_func_set_collation(const POS & pos,Item * a,const LEX_STRING & collation_string_arg)1182 Item_func_set_collation(const POS &pos, Item *a, 1183 const LEX_STRING &collation_string_arg) 1184 :super(pos, a, NULL), collation_string(collation_string_arg) 1185 {} 1186 1187 virtual bool itemize(Parse_context *pc, Item **res); 1188 String *val_str(String *); 1189 void fix_length_and_dec(); 1190 bool eq(const Item *item, bool binary_cmp) const; func_name()1191 const char *func_name() const { return "collate"; } functype()1192 enum Functype functype() const { return COLLATE_FUNC; } 1193 virtual void print(String *str, enum_query_type query_type); field_for_view_update()1194 Item_field *field_for_view_update() 1195 { 1196 /* this function is transparent for view updating */ 1197 return args[0]->field_for_view_update(); 1198 } 1199 }; 1200 1201 class Item_func_charset :public Item_str_func 1202 { 1203 public: Item_func_charset(const POS & pos,Item * a)1204 Item_func_charset(const POS &pos, Item *a) :Item_str_func(pos, a) {} 1205 String *val_str(String *); func_name()1206 const char *func_name() const { return "charset"; } fix_length_and_dec()1207 void fix_length_and_dec() 1208 { 1209 collation.set(system_charset_info); 1210 max_length= 64 * collation.collation->mbmaxlen; // should be enough 1211 maybe_null= 0; 1212 }; not_null_tables()1213 table_map not_null_tables() const { return 0; } 1214 }; 1215 1216 class Item_func_collation :public Item_str_func 1217 { 1218 public: Item_func_collation(const POS & pos,Item * a)1219 Item_func_collation(const POS &pos, Item *a) :Item_str_func(pos, a) {} 1220 String *val_str(String *); func_name()1221 const char *func_name() const { return "collation"; } fix_length_and_dec()1222 void fix_length_and_dec() 1223 { 1224 collation.set(system_charset_info); 1225 max_length= 64 * collation.collation->mbmaxlen; // should be enough 1226 maybe_null= 0; 1227 }; not_null_tables()1228 table_map not_null_tables() const { return 0; } 1229 }; 1230 1231 class Item_func_weight_string :public Item_str_func 1232 { 1233 typedef Item_str_func super; 1234 1235 String tmp_value; 1236 uint flags; 1237 uint nweights; 1238 uint result_length; 1239 Field *field; 1240 bool as_binary; 1241 public: 1242 Item_func_weight_string(const POS &pos, Item *a, uint result_length_arg, 1243 uint nweights_arg, uint flags_arg, 1244 bool as_binary_arg= false) Item_str_func(pos,a)1245 :Item_str_func(pos, a), field(NULL), as_binary(as_binary_arg) 1246 { 1247 nweights= nweights_arg; 1248 flags= flags_arg; 1249 result_length= result_length_arg; 1250 } 1251 1252 virtual bool itemize(Parse_context *pc, Item **res); 1253 func_name()1254 const char *func_name() const { return "weight_string"; } 1255 bool eq(const Item *item, bool binary_cmp) const; 1256 String *val_str(String *); 1257 void fix_length_and_dec(); 1258 virtual void print(String *str, enum_query_type query_type); 1259 }; 1260 1261 class Item_func_crc32 :public Item_int_func 1262 { 1263 String value; 1264 public: Item_func_crc32(const POS & pos,Item * a)1265 Item_func_crc32(const POS &pos, Item *a) :Item_int_func(pos, a) 1266 { unsigned_flag= 1; } func_name()1267 const char *func_name() const { return "crc32"; } fix_length_and_dec()1268 void fix_length_and_dec() { max_length=10; } 1269 longlong val_int(); 1270 }; 1271 1272 class Item_func_uncompressed_length : public Item_int_func 1273 { 1274 String value; 1275 public: Item_func_uncompressed_length(const POS & pos,Item * a)1276 Item_func_uncompressed_length(const POS &pos, Item *a) :Item_int_func(pos, a) 1277 {} func_name()1278 const char *func_name() const{return "uncompressed_length";} fix_length_and_dec()1279 void fix_length_and_dec() { max_length=10; } 1280 longlong val_int(); 1281 }; 1282 1283 #ifdef HAVE_COMPRESS 1284 #define ZLIB_DEPENDED_FUNCTION ; 1285 #else 1286 #define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; } 1287 #endif 1288 1289 class Item_func_compress: public Item_str_func 1290 { 1291 String buffer; 1292 public: Item_func_compress(const POS & pos,Item * a)1293 Item_func_compress(const POS &pos, Item *a):Item_str_func(pos, a){} fix_length_and_dec()1294 void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} func_name()1295 const char *func_name() const{return "compress";} 1296 String *val_str(String *) ZLIB_DEPENDED_FUNCTION 1297 }; 1298 1299 class Item_func_uncompress: public Item_str_func 1300 { 1301 String buffer; 1302 public: Item_func_uncompress(const POS & pos,Item * a)1303 Item_func_uncompress(const POS &pos, Item *a): Item_str_func(pos, a) {} fix_length_and_dec()1304 void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; } func_name()1305 const char *func_name() const{return "uncompress";} 1306 String *val_str(String *) ZLIB_DEPENDED_FUNCTION 1307 }; 1308 1309 class Item_func_uuid: public Item_str_func 1310 { 1311 typedef Item_str_func super; 1312 public: Item_func_uuid()1313 Item_func_uuid(): Item_str_func() {} 1314 explicit Item_func_uuid(const POS & pos)1315 Item_func_uuid(const POS &pos): Item_str_func(pos) {} 1316 1317 virtual bool itemize(Parse_context *pc, Item **res); fix_length_and_dec()1318 void fix_length_and_dec() 1319 { 1320 collation.set(system_charset_info, 1321 DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); 1322 fix_char_length(UUID_LENGTH); 1323 } func_name()1324 const char *func_name() const{ return "uuid"; } 1325 String *val_str(String *); check_gcol_func_processor(uchar * int_arg)1326 bool check_gcol_func_processor(uchar *int_arg) 1327 { return true; } 1328 }; 1329 1330 class Item_func_gtid_subtract: public Item_str_ascii_func 1331 { 1332 String buf1, buf2; 1333 public: Item_func_gtid_subtract(const POS & pos,Item * a,Item * b)1334 Item_func_gtid_subtract(const POS &pos, Item *a, Item *b) 1335 :Item_str_ascii_func(pos, a, b) 1336 {} 1337 void fix_length_and_dec(); func_name()1338 const char *func_name() const{ return "gtid_subtract"; } 1339 String *val_str_ascii(String *); 1340 }; 1341 1342 #endif /* ITEM_STRFUNC_INCLUDED */ 1343