diff options
author | Alexander Barkov <bar@mariadb.org> | 2017-02-01 16:35:23 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2017-04-05 15:02:55 +0400 |
commit | 08799831ccf5f052518ce121bf532dda86168ca3 (patch) | |
tree | 85b37b8a2cfe5919b6a465408bb761a5c0609a3b /sql/item_strfunc.h | |
parent | 46255b0c0d07c257f2064786fbc4b9cf13122428 (diff) | |
download | mariadb-git-08799831ccf5f052518ce121bf532dda86168ca3.tar.gz |
MDEV-11880 sql_mode=ORACLE: Make the concatenation operator ignore NULL arguments
Now when sql_mode=ORACLE, the concatenation operator || treats
NULLs as empty strings.
Based on the contributed patch from Jérôme Brauge.
Diffstat (limited to 'sql/item_strfunc.h')
-rw-r--r-- | sql/item_strfunc.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index fb7d79d9e0d..0ff11796add 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -245,7 +245,40 @@ public: class Item_func_concat :public Item_str_func { +protected: String tmp_value; + /* + Get the i-th argument val_str() and its const_item() + @param i[IN] - The argument number + @param str[IN] - The buffer for val_str() + @param is_const[IN/OUT] - If args[i]->val_str() returned a non-null value, + then args[i]->const_item() is returned here. + Otherwise, the value of is_const is not touched. + @retval - the result of val_str(). + */ + String *arg_val_str(uint i, String *str, bool *is_const) + { + String *res= args[i]->val_str(str); + if (res) + *is_const= args[i]->const_item(); + return res; + } + /* + Append a non-NULL value to the result. + @param [IN] thd - The current thread. + @param [IN/OUT] res - The current val_str() return value. + @param [IN] res_is_const - If "false", then OK to append to "res" + @param [IN/OUT] str - The val_str() argument. + @param [IN] res2 - The value to be appended. + @param [IN/OUT] use_as_buff - Which buffer to use for the next argument: + args[next_arg]->val_str(use_as_buff) + */ + String *append_value(THD *thd, + String *res, + bool res_is_const, + String *str, + String **use_as_buff, + const String *res2); 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) {} @@ -256,6 +289,30 @@ public: { return get_item_copy<Item_func_concat>(thd, mem_root, this); } }; + +/* + This class handles the || operator in sql_mode=ORACLE. + Unlike the traditional MariaDB concat(), it treats NULL arguments as ''. +*/ +class Item_func_concat_operator_oracle :public Item_func_concat +{ +public: + Item_func_concat_operator_oracle(THD *thd, Item *a, Item *b) + :Item_func_concat(thd, a, b) + { } + void print(String *str, enum_query_type query_type) + { + print_op(str, query_type); + } + String *val_str(String *); + const char *func_name() const { return "||"; } + Item *get_copy(THD *thd, MEM_ROOT *mem_root) + { + return get_item_copy<Item_func_concat_operator_oracle>(thd, mem_root, this); + } +}; + + class Item_func_decode_histogram :public Item_str_func { String tmp_value; |