1 #ifndef ITEM_STRFUNC_INCLUDED
2 #define ITEM_STRFUNC_INCLUDED
21 #include "crypt_genhash_impl.h"
34 str_value.set(
"", 0, collation.collation);
48 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate)
56 enum Item_result result_type ()
const {
return STRING_RESULT; }
57 void left_right_max_length();
58 bool fix_fields(THD *thd,
Item **ref);
72 { collation.set_repertoire(MY_REPERTOIRE_ASCII); }
74 { collation.set_repertoire(MY_REPERTOIRE_ASCII); }
76 { collation.set_repertoire(MY_REPERTOIRE_ASCII); }
78 { collation.set_repertoire(MY_REPERTOIRE_ASCII); }
81 return val_str_from_val_str_ascii(str, &ascii_buf);
93 void fix_length_and_dec();
94 const char *func_name()
const {
return "md5"; }
103 void fix_length_and_dec();
104 const char *func_name()
const {
return "sha"; }
112 void fix_length_and_dec();
113 const char *func_name()
const {
return "sha2"; }
122 void fix_length_and_dec();
123 const char *func_name()
const {
return "to_base64"; }
132 void fix_length_and_dec();
133 const char *func_name()
const {
return "from_base64"; }
142 void fix_length_and_dec();
143 const char *func_name()
const {
return "aes_encrypt"; }
151 void fix_length_and_dec();
152 const char *func_name()
const {
return "aes_decrypt"; }
163 void fix_length_and_dec();
164 const char *func_name()
const {
return "concat"; }
173 void fix_length_and_dec();
174 const char *func_name()
const {
return "concat_ws"; }
175 table_map not_null_tables()
const {
return 0; }
184 void fix_length_and_dec();
185 const char *func_name()
const {
return "reverse"; }
191 String tmp_value,tmp_value2;
196 void fix_length_and_dec();
197 const char *func_name()
const {
return "replace"; }
208 void fix_length_and_dec();
209 const char *func_name()
const {
return "insert"; }
217 my_charset_conv_case converter;
229 const char *func_name()
const {
return "lcase"; }
230 void fix_length_and_dec();
237 const char *func_name()
const {
return "ucase"; }
238 void fix_length_and_dec();
248 void fix_length_and_dec();
249 const char *func_name()
const {
return "left"; }
259 void fix_length_and_dec();
260 const char *func_name()
const {
return "right"; }
271 void fix_length_and_dec();
272 const char *func_name()
const {
return "substr"; }
282 void fix_length_and_dec();
283 const char *func_name()
const {
return "substring_index"; }
296 void fix_length_and_dec();
297 const char *func_name()
const {
return "trim"; }
298 virtual void print(
String *str, enum_query_type query_type);
299 virtual const char *mode_name()
const {
return "both"; }
309 const char *func_name()
const {
return "ltrim"; }
310 const char *mode_name()
const {
return "leading"; }
320 const char *func_name()
const {
return "rtrim"; }
321 const char *mode_name()
const {
return "trailing"; }
335 char m_hashed_password_buffer[CRYPT_MAX_PASSWORD_SIZE + 1];
336 unsigned int m_hashed_password_buffer_len;
337 bool m_recalculate_password;
341 m_hashed_password_buffer_len= 0;
342 m_recalculate_password=
false;
345 void fix_length_and_dec();
346 const char *func_name()
const {
return "password"; }
347 static char *create_password_hash_buffer(THD *thd,
const char *password,
361 char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1];
365 void fix_length_and_dec()
367 fix_length_and_charset(SCRAMBLED_PASSWORD_CHAR_LENGTH_323, default_charset());
369 const char *func_name()
const {
return "old_password"; }
370 static char *alloc(THD *thd,
const char *password,
size_t pass_len);
381 void fix_length_and_dec()
385 max_length = args[0]->max_length + 9;
387 const char *func_name()
const {
return "des_encrypt"; }
397 void fix_length_and_dec()
401 max_length= args[0]->max_length;
402 if (max_length >= 9
U)
405 const char *func_name()
const {
return "des_decrypt"; }
413 void constructor_helper()
415 collation.set(&my_charset_bin);
420 constructor_helper();
424 constructor_helper();
427 void fix_length_and_dec() { maybe_null=1; max_length = 13; }
428 const char *func_name()
const {
return "encrypt"; }
431 #include "sql_crypt.h"
445 void fix_length_and_dec();
446 const char *func_name()
const {
return "encode"; }
448 virtual void crypto_transform(
String *);
459 const char *func_name()
const {
return "decode"; }
461 void crypto_transform(
String *);
469 { collation.set(system_charset_info,DERIVATION_SYSCONST); }
476 virtual const Name_string fully_qualified_func_name()
const = 0;
485 void fix_length_and_dec()
487 max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
490 const char *func_name()
const {
return "database"; }
491 const Name_string fully_qualified_func_name()
const
492 {
return NAME_STRING(
"database()"); }
499 bool init (
const char *user,
const char *host);
504 str_value.set(
"", 0, system_charset_info);
508 DBUG_ASSERT(fixed == 1);
509 return (null_value ? 0 : &str_value);
511 bool fix_fields(THD *thd,
Item **ref);
512 void fix_length_and_dec()
514 max_length= (USERNAME_LENGTH +
515 (HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN);
517 const char *func_name()
const {
return "user"; }
518 const Name_string fully_qualified_func_name()
const
519 {
return NAME_STRING(
"user()"); }
522 return save_str_value_in_field(field, &str_value);
533 : context(context_arg) {}
534 bool fix_fields(THD *thd,
Item **ref);
535 const char *func_name()
const {
return "current_user"; }
536 const Name_string fully_qualified_func_name()
const
537 {
return NAME_STRING(
"current_user()"); }
547 void fix_length_and_dec();
548 const char *func_name()
const {
return "soundex"; }
559 void fix_length_and_dec();
560 const char *func_name()
const {
return "elt"; }
572 bool fix_fields(THD *thd,
Item **ref)
574 DBUG_ASSERT(fixed == 0);
575 bool res= ((!item->fixed && item->fix_fields(thd, &item)) ||
576 item->check_cols(1) ||
577 Item_func::fix_fields(thd, ref));
578 maybe_null|= item->maybe_null;
583 void fix_length_and_dec();
584 void update_used_tables();
585 const char *func_name()
const {
return "make_set"; }
587 bool walk(Item_processor processor,
bool walk_subquery, uchar *arg)
589 return item->walk(processor, walk_subquery, arg) ||
590 Item_str_func::walk(processor, walk_subquery, arg);
593 virtual void print(
String *str, enum_query_type query_type);
608 void fix_length_and_dec();
609 const char *func_name()
const {
return "format"; }
610 virtual void print(
String *str, enum_query_type query_type);
618 { collation.set(&my_charset_bin); }
621 { collation.set(cs); }
623 void fix_length_and_dec()
625 max_length= arg_count * 4;
627 const char *func_name()
const {
return "char"; }
637 void fix_length_and_dec();
638 const char *func_name()
const {
return "repeat"; }
647 void fix_length_and_dec();
648 const char *func_name()
const {
return "space"; }
654 String tmp_value, rpad_str;
659 void fix_length_and_dec();
660 const char *func_name()
const {
return "rpad"; }
666 String tmp_value, lpad_str;
671 void fix_length_and_dec();
672 const char *func_name()
const {
return "lpad"; }
680 const char *func_name()
const {
return "conv"; }
682 void fix_length_and_dec()
684 collation.set(default_charset());
696 const char *func_name()
const {
return "hex"; }
698 void fix_length_and_dec()
700 collation.set(default_charset());
702 fix_char_length(args[0]->max_length * 2);
715 const char *func_name()
const {
return "unhex"; }
717 void fix_length_and_dec()
719 collation.set(&my_charset_bin);
721 max_length=(1+args[0]->max_length)/2;
738 void fix_length_and_dec()
740 collation.set(args[0]->collation);
742 max_length= MAX_BLOB_WIDTH;
752 const char *func_name()
const {
return "like_range_min"; }
761 const char *func_name()
const {
return "like_range_max"; }
770 bool charset_conversion;
774 :
Item_str_func(a), cast_length(length_arg), cast_cs(cs_arg) {}
775 enum Functype functype()
const {
return CHAR_TYPECAST_FUNC; }
776 bool eq(
const Item *item,
bool binary_cmp)
const;
777 const char *func_name()
const {
return "cast_as_char"; }
779 void fix_length_and_dec();
780 virtual void print(
String *str, enum_query_type query_type);
790 DBUG_ASSERT(fixed == 1);
791 String *tmp=args[0]->val_str(a);
792 null_value=args[0]->null_value;
794 tmp->set_charset(&my_charset_bin);
797 void fix_length_and_dec()
799 collation.set(&my_charset_bin);
800 max_length=args[0]->max_length;
802 virtual void print(
String *str, enum_query_type query_type);
803 const char *func_name()
const {
return "cast_as_binary"; }
813 const char *func_name()
const {
return "load_file"; }
814 void fix_length_and_dec()
816 collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
818 max_length=MAX_BLOB_WIDTH;
830 void fix_length_and_dec();
831 const char *func_name()
const {
return "export_set"; }
839 const char *func_name()
const {
return "quote"; }
841 void fix_length_and_dec()
843 collation.set(args[0]->collation);
844 ulong max_result_length= (ulong) args[0]->max_length * 2 +
845 2 * collation.collation->mbmaxlen;
846 max_length= std::min<ulong>(max_result_length, MAX_BLOB_WIDTH);
852 bool use_cached_value;
858 { conv_charset= cs; use_cached_value= 0; safe= 0; }
862 DBUG_ASSERT(args[0]->fixed);
864 if (cache_if_const && args[0]->const_item())
867 String tmp, *str= args[0]->val_str(&tmp);
868 if (!str || str_value.copy(str->ptr(), str->length(),
869 str->charset(), conv_charset, &errors))
872 str_value.mark_as_const();
883 safe= (args[0]->collation.collation == &my_charset_bin ||
884 cs == &my_charset_bin ||
885 (cs->state & MY_CS_UNICODE));
889 void fix_length_and_dec();
890 const char *func_name()
const {
return "convert"; }
891 virtual void print(
String *str, enum_query_type query_type);
899 void fix_length_and_dec();
900 bool eq(
const Item *item,
bool binary_cmp)
const;
901 const char *func_name()
const {
return "collate"; }
902 enum Functype functype()
const {
return COLLATE_FUNC; }
903 virtual void print(
String *str, enum_query_type query_type);
907 return args[0]->field_for_view_update();
916 const char *func_name()
const {
return "charset"; }
917 void fix_length_and_dec()
919 collation.set(system_charset_info);
920 max_length= 64 * collation.collation->mbmaxlen;
923 table_map not_null_tables()
const {
return 0; }
931 const char *func_name()
const {
return "collation"; }
932 void fix_length_and_dec()
934 collation.set(system_charset_info);
935 max_length= 64 * collation.collation->mbmaxlen;
938 table_map not_null_tables()
const {
return 0; }
950 uint nweights_arg, uint flags_arg)
953 nweights= nweights_arg;
955 result_length= result_length_arg;
957 const char *func_name()
const {
return "weight_string"; }
959 void fix_length_and_dec();
967 const char *func_name()
const {
return "crc32"; }
968 void fix_length_and_dec() { max_length=10; }
977 const char *func_name()
const{
return "uncompressed_length";}
978 void fix_length_and_dec() { max_length=10; }
983 #define ZLIB_DEPENDED_FUNCTION ;
985 #define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
993 void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
994 const char *func_name()
const{
return "compress";}
1003 void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
1004 const char *func_name()
const{
return "uncompress";}
1012 void fix_length_and_dec()
1014 collation.set(system_charset_info,
1015 DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
1016 fix_char_length(UUID_LENGTH);
1018 const char *func_name()
const{
return "uuid"; }
1027 void fix_length_and_dec();
1028 const char *func_name()
const{
return "gtid_subtract"; }