From 209375fdd07d9be79784984f8543be73d1f92a9a Mon Sep 17 00:00:00 2001 From: halfspawn Date: Tue, 27 Mar 2018 09:08:30 +0200 Subject: MDEV-15664 : sql_mode=ORACLE: Make TRIM return NULL instead of empty string --- sql/item_strfunc.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'sql/item_strfunc.h') diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index da77f29f108..4e1514c5476 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -539,6 +539,9 @@ protected: String remove; String *trimmed_value(String *res, uint32 offset, uint32 length) { + if (length == 0) + return make_empty_result(); + tmp_value.set(*res, offset, length); /* Make sure to return correct charset and collation: @@ -552,6 +555,7 @@ protected: { return trimmed_value(res, 0, res->length()); } + virtual const char *func_name_ext() const { return ""; } 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) {} @@ -565,6 +569,27 @@ public: }; +class Item_func_trim_oracle :public Item_func_trim +{ +protected: + String *make_empty_result() + { null_value= 1; return NULL; } + const char *func_name_ext() const { return "_oracle"; } +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) {} + const char *func_name() const { return "trim_oracle"; } + void fix_length_and_dec() + { + Item_func_trim::fix_length_and_dec(); + maybe_null= true; + } + Item *get_copy(THD *thd) + { return get_item_copy(thd, this); } +}; + + class Item_func_ltrim :public Item_func_trim { public: @@ -578,6 +603,27 @@ public: }; +class Item_func_ltrim_oracle :public Item_func_ltrim +{ +protected: + String *make_empty_result() + { null_value= 1; return NULL; } + const char *func_name_ext() const { return "_oracle"; } +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) {} + const char *func_name() const { return "ltrim_oracle"; } + void fix_length_and_dec() + { + Item_func_ltrim::fix_length_and_dec(); + maybe_null= true; + } + Item *get_copy(THD *thd) + { return get_item_copy(thd, this); } +}; + + class Item_func_rtrim :public Item_func_trim { public: @@ -591,6 +637,26 @@ public: }; +class Item_func_rtrim_oracle :public Item_func_rtrim +{ +protected: + String *make_empty_result() + { null_value= 1; return NULL; } + const char *func_name_ext() const { return "_oracle"; } +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) {} + const char *func_name() const { return "rtrim_oracle"; } + void fix_length_and_dec() + { + Item_func_rtrim::fix_length_and_dec(); + maybe_null= true; + } + Item *get_copy(THD *thd) + { return get_item_copy(thd, this); } +}; + /* Item_func_password -- new (4.1.1) PASSWORD() function implementation. Returns strcat('*', octet2hex(sha1(sha1(password)))). '*' stands for new -- cgit v1.2.1