diff options
Diffstat (limited to 'sql/item_strfunc.h')
-rw-r--r-- | sql/item_strfunc.h | 199 |
1 files changed, 145 insertions, 54 deletions
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 3a3c5338..340847dd 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -307,6 +307,12 @@ protected: public: Item_func_concat(THD *thd, List<Item> &list): Item_str_func(thd, list) {} Item_func_concat(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {} + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } String *val_str(String *) override; bool fix_length_and_dec(THD *thd) override; LEX_CSTRING func_name_cstring() const override @@ -333,10 +339,17 @@ public: :Item_func_concat(thd, a, b) { } String *val_str(String *) override; - LEX_CSTRING func_name_cstring() const override + const Schema *schema() const override { return &oracle_schema_ref; } + void print(String *str, enum_query_type query_type) override { - static LEX_CSTRING name= {STRING_WITH_LEN("concat_operator_oracle") }; - return name; + if (query_type & QT_FOR_FRM) + { + // 10.3 downgrade compatibility for FRM + str->append(STRING_WITH_LEN("concat_operator_oracle")); + } + else + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); } Item *get_copy(THD *thd) override { @@ -430,12 +443,19 @@ public: class Item_func_replace :public Item_str_func { String tmp_value,tmp_value2; +protected: + String *val_str_internal(String *str, bool null_to_empty); public: Item_func_replace(THD *thd, Item *org, Item *find, Item *replace): Item_str_func(thd, org, find, replace) {} - String *val_str(String *to) override { return val_str_internal(to, NULL); }; + String *val_str(String *to) override { return val_str_internal(to, false); }; bool fix_length_and_dec(THD *thd) override; - String *val_str_internal(String *str, String *empty_string_for_null); + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("replace") }; @@ -453,11 +473,18 @@ public: Item_func_replace_oracle(THD *thd, Item *org, Item *find, Item *replace): Item_func_replace(thd, org, find, replace) {} String *val_str(String *to) override - { return val_str_internal(to, &tmp_emtpystr); }; - LEX_CSTRING func_name_cstring() const override + { return val_str_internal(to, true); }; + const Schema *schema() const override { return &oracle_schema_ref; } + void print(String *str, enum_query_type query_type) override { - static LEX_CSTRING name= {STRING_WITH_LEN("replace_oracle") }; - return name; + if (query_type & QT_FOR_FRM) + { + // 10.3 downgrade compatibility for FRM + str->append(STRING_WITH_LEN("replace_oracle")); + } + else + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); } Item *get_copy(THD *thd) override { return get_item_copy<Item_func_replace_oracle>(thd, this); } @@ -470,10 +497,18 @@ class Item_func_regexp_replace :public Item_str_func bool append_replacement(String *str, const LEX_CSTRING *source, const LEX_CSTRING *replace); +protected: + String *val_str_internal(String *str, bool null_to_empty); public: Item_func_regexp_replace(THD *thd, Item *a, Item *b, Item *c): Item_str_func(thd, a, b, c) {} + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } void cleanup() override { DBUG_ENTER("Item_func_regexp_replace::cleanup"); @@ -481,7 +516,10 @@ public: re.cleanup(); DBUG_VOID_RETURN; } - String *val_str(String *str) override; + String *val_str(String *str) override + { + return val_str_internal(str, false); + } bool fix_length_and_dec(THD *thd) override; LEX_CSTRING func_name_cstring() const override { @@ -492,6 +530,26 @@ public: }; +class Item_func_regexp_replace_oracle: public Item_func_regexp_replace +{ +public: + Item_func_regexp_replace_oracle(THD *thd, Item *a, Item *b, Item *c) + :Item_func_regexp_replace(thd, a, b, c) + {} + const Schema *schema() const { return &oracle_schema_ref; } + bool fix_length_and_dec(THD *thd) + { + bool rc= Item_func_regexp_replace::fix_length_and_dec(thd); + set_maybe_null(); // Empty result is converted to NULL + return rc; + } + String *val_str(String *str) + { + return val_str_internal(str, true); + } +}; + + class Item_func_regexp_substr :public Item_str_func { Regexp_processor_pcre re; @@ -621,8 +679,16 @@ public: Item_func_substr(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {} Item_func_substr(THD *thd, Item *a, Item *b, Item *c): Item_str_func(thd, a, b, c) {} + Item_func_substr(THD *thd, List<Item> &list) + :Item_str_func(thd, list) {} String *val_str(String *) override; bool fix_length_and_dec(THD *thd) override; + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("substr") }; @@ -661,16 +727,25 @@ public: Item_func_substr(thd, a, b) {} Item_func_substr_oracle(THD *thd, Item *a, Item *b, Item *c): Item_func_substr(thd, a, b, c) {} + Item_func_substr_oracle(THD *thd, List<Item> &list) + :Item_func_substr(thd, list) {} bool fix_length_and_dec(THD *thd) override { bool res= Item_func_substr::fix_length_and_dec(thd); set_maybe_null(); return res; } - LEX_CSTRING func_name_cstring() const override + const Schema *schema() const override { return &oracle_schema_ref; } + void print(String *str, enum_query_type query_type) override { - static LEX_CSTRING name= {STRING_WITH_LEN("substr_oracle") }; - return name; + if (query_type & QT_FOR_FRM) + { + // 10.3 downgrade compatibility for FRM + str->append(STRING_WITH_LEN("substr_oracle")); + } + else + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); } Item *get_copy(THD *thd) override { return get_item_copy<Item_func_substr_oracle>(thd, this); } @@ -718,17 +793,13 @@ protected: { return trimmed_value(res, 0, res->length()); } - virtual LEX_CSTRING func_name_ext() const - { - static LEX_CSTRING name_ext= {STRING_WITH_LEN("") }; - return name_ext; - } public: Item_func_trim(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {} Item_func_trim(THD *thd, Item *a): Item_str_func(thd, a) {} Sql_mode_dependency value_depends_on_sql_mode() const override; String *val_str(String *) override; bool fix_length_and_dec(THD *thd) override; + const Schema *schema() const override { return &mariadb_schema; } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("trim") }; @@ -746,20 +817,11 @@ class Item_func_trim_oracle :public Item_func_trim protected: String *make_empty_result(String *str) override { null_value= 1; return NULL; } - LEX_CSTRING func_name_ext() const override - { - static LEX_CSTRING name_ext= {STRING_WITH_LEN("_oracle") }; - return name_ext; - } public: Item_func_trim_oracle(THD *thd, Item *a, Item *b): Item_func_trim(thd, a, b) {} Item_func_trim_oracle(THD *thd, Item *a): Item_func_trim(thd, a) {} - LEX_CSTRING func_name_cstring() const override - { - static LEX_CSTRING name= {STRING_WITH_LEN("trim_oracle") }; - return name; - } + const Schema *schema() const override { return &oracle_schema_ref; } bool fix_length_and_dec(THD *thd) override { bool res= Item_func_trim::fix_length_and_dec(thd); @@ -781,6 +843,7 @@ public: return Item_func::value_depends_on_sql_mode(); } String *val_str(String *) override; + const Schema *schema() const override { return &mariadb_schema; } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("ltrim") }; @@ -798,20 +861,11 @@ class Item_func_ltrim_oracle :public Item_func_ltrim protected: String *make_empty_result(String *str) override { null_value= 1; return NULL; } - LEX_CSTRING func_name_ext() const override - { - static LEX_CSTRING name_ext= {STRING_WITH_LEN("_oracle") }; - return name_ext; - } public: Item_func_ltrim_oracle(THD *thd, Item *a, Item *b): Item_func_ltrim(thd, a, b) {} Item_func_ltrim_oracle(THD *thd, Item *a): Item_func_ltrim(thd, a) {} - LEX_CSTRING func_name_cstring() const override - { - static LEX_CSTRING name= {STRING_WITH_LEN("ltrim_oracle") }; - return name; - } + const Schema *schema() const override { return &oracle_schema_ref; } bool fix_length_and_dec(THD *thd) override { bool res= Item_func_ltrim::fix_length_and_dec(thd); @@ -829,6 +883,7 @@ public: Item_func_rtrim(THD *thd, Item *a, Item *b): Item_func_trim(thd, a, b) {} Item_func_rtrim(THD *thd, Item *a): Item_func_trim(thd, a) {} String *val_str(String *) override; + const Schema *schema() const override { return &mariadb_schema; } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("rtrim") }; @@ -846,20 +901,11 @@ class Item_func_rtrim_oracle :public Item_func_rtrim protected: String *make_empty_result(String *str) override { null_value= 1; return NULL; } - LEX_CSTRING func_name_ext() const override - { - static LEX_CSTRING name_ext= {STRING_WITH_LEN("_oracle") }; - return name_ext; - } public: Item_func_rtrim_oracle(THD *thd, Item *a, Item *b): Item_func_rtrim(thd, a, b) {} Item_func_rtrim_oracle(THD *thd, Item *a): Item_func_rtrim(thd, a) {} - LEX_CSTRING func_name_cstring() const override - { - static LEX_CSTRING name= {STRING_WITH_LEN("rtrim_oracle") }; - return name; - } + const Schema *schema() const override { return &oracle_schema_ref; } bool fix_length_and_dec(THD *thd) override { bool res= Item_func_rtrim::fix_length_and_dec(thd); @@ -1032,6 +1078,12 @@ class Item_func_decode :public Item_func_encode { public: Item_func_decode(THD *thd, Item *a, Item *seed_arg): Item_func_encode(thd, a, seed_arg) {} + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("decode") }; @@ -1402,6 +1454,8 @@ public: Item_str_func(thd, arg1, arg2, arg3) {} Item_func_pad(THD *thd, Item *arg1, Item *arg2): Item_str_func(thd, arg1, arg2) {} + Item_func_pad(THD *thd, List<Item> &list): + Item_str_func(thd,list) {} bool fix_length_and_dec(THD *thd) override; }; @@ -1413,7 +1467,15 @@ public: Item_func_pad(thd, arg1, arg2, arg3) {} Item_func_rpad(THD *thd, Item *arg1, Item *arg2): Item_func_pad(thd, arg1, arg2) {} + Item_func_rpad(THD *thd, List<Item> &list): + Item_func_pad(thd,list) {} String *val_str(String *) override; + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("rpad") }; @@ -1434,16 +1496,25 @@ public: Item_func_rpad(thd, arg1, arg2, arg3) {} Item_func_rpad_oracle(THD *thd, Item *arg1, Item *arg2): Item_func_rpad(thd, arg1, arg2) {} + Item_func_rpad_oracle(THD *thd, List<Item> &list): + Item_func_rpad(thd,list) {} bool fix_length_and_dec(THD *thd) override { bool res= Item_func_rpad::fix_length_and_dec(thd); set_maybe_null(); return res; } - LEX_CSTRING func_name_cstring() const override + const Schema *schema() const override { return &oracle_schema_ref; } + void print(String *str, enum_query_type query_type) override { - static LEX_CSTRING name= {STRING_WITH_LEN("rpad_oracle") }; - return name; + if (query_type & QT_FOR_FRM) + { + // 10.3 downgrade compatibility for FRM + str->append(STRING_WITH_LEN("rpad_oracle")); + } + else + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); } Item *get_copy(THD *thd) override { return get_item_copy<Item_func_rpad_oracle>(thd, this); } @@ -1457,7 +1528,15 @@ public: Item_func_pad(thd, arg1, arg2, arg3) {} Item_func_lpad(THD *thd, Item *arg1, Item *arg2): Item_func_pad(thd, arg1, arg2) {} + Item_func_lpad(THD *thd, List<Item> &list): + Item_func_pad(thd,list) {} String *val_str(String *) override; + const Schema *schema() const override { return &mariadb_schema; } + void print(String *str, enum_query_type query_type) override + { + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); + } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("lpad") }; @@ -1477,16 +1556,25 @@ public: Item_func_lpad(thd, arg1, arg2, arg3) {} Item_func_lpad_oracle(THD *thd, Item *arg1, Item *arg2): Item_func_lpad(thd, arg1, arg2) {} + Item_func_lpad_oracle(THD *thd, List<Item> &list): + Item_func_lpad(thd,list) {} bool fix_length_and_dec(THD *thd) override { bool res= Item_func_lpad::fix_length_and_dec(thd); set_maybe_null(); return res; } - LEX_CSTRING func_name_cstring() const override + const Schema *schema() const override { return &oracle_schema_ref; } + void print(String *str, enum_query_type query_type) override { - static LEX_CSTRING name= {STRING_WITH_LEN("lpad_oracle") }; - return name; + if (query_type & QT_FOR_FRM) + { + // 10.3 downgrade compatibility for FRM + str->append(STRING_WITH_LEN("lpad_oracle")); + } + else + print_sql_mode_qualified_name(str, query_type); + print_args_parenthesized(str, query_type); } Item *get_copy(THD *thd) override { return get_item_copy<Item_func_lpad_oracle>(thd, this); } @@ -1732,6 +1820,9 @@ public: collation.set(args[0]->collation); ulonglong max_result_length= (ulonglong) args[0]->max_length * 2 + 2 * collation.collation->mbmaxlen; + // NULL argument is returned as a string "NULL" without quotes + if (args[0]->maybe_null()) + set_if_bigger(max_result_length, 4 * collation.collation->mbmaxlen); max_length= (uint32) MY_MIN(max_result_length, MAX_BLOB_WIDTH); return FALSE; } |