diff options
author | halfspawn <j.brauge@qualiac.com> | 2017-05-03 17:39:45 +0200 |
---|---|---|
committer | halfspawn <j.brauge@qualiac.com> | 2017-05-03 17:39:45 +0200 |
commit | 850d3bafcae1aeeb4470886408e19c084d9d183e (patch) | |
tree | 61fbe76346ccdea37f9fec1aa0a9c2d7bdbea1f1 /sql/item_create.cc | |
parent | 736a1d29bc84608ef521103ca77ad3da6b7676dc (diff) | |
download | mariadb-git-850d3bafcae1aeeb4470886408e19c084d9d183e.tar.gz |
MDEV-12658 Make the third parameter to LPAD and RPAD optional
Diffstat (limited to 'sql/item_create.cc')
-rw-r--r-- | sql/item_create.cc | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index 305f62a04b1..f678bb44f21 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -2260,10 +2260,11 @@ protected: }; -class Create_func_lpad : public Create_func_arg3 +class Create_func_lpad : public Create_native_func { public: - virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3); + virtual Item *create_native(THD *thd, LEX_CSTRING *name, + List<Item> *item_list); static Create_func_lpad s_singleton; @@ -2686,10 +2687,11 @@ protected: }; -class Create_func_rpad : public Create_func_arg3 +class Create_func_rpad : public Create_native_func { public: - virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3); + virtual Item *create_native(THD *thd, LEX_CSTRING *name, + List<Item> *item_list); static Create_func_rpad s_singleton; @@ -5791,9 +5793,34 @@ Create_func_log2::create_1_arg(THD *thd, Item *arg1) Create_func_lpad Create_func_lpad::s_singleton; Item* -Create_func_lpad::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3) +Create_func_lpad::create_native(THD *thd, LEX_CSTRING *name, + List<Item> *item_list) { - return new (thd->mem_root) Item_func_lpad(thd, arg1, arg2, arg3); + Item *func= NULL; + int arg_count= item_list ? item_list->elements : 0; + + switch (arg_count) { + case 2: + { + Item *param_1= item_list->pop(); + Item *param_2= item_list->pop(); + func= new (thd->mem_root) Item_func_lpad(thd, param_1, param_2); + break; + } + case 3: + { + Item *param_1= item_list->pop(); + Item *param_2= item_list->pop(); + Item *param_3= item_list->pop(); + func= new (thd->mem_root) Item_func_lpad(thd, param_1, param_2, param_3); + break; + } + default: + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str); + break; + } + + return func; } @@ -6253,9 +6280,34 @@ Create_func_round::create_native(THD *thd, LEX_CSTRING *name, Create_func_rpad Create_func_rpad::s_singleton; Item* -Create_func_rpad::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3) +Create_func_rpad::create_native(THD *thd, LEX_CSTRING *name, + List<Item> *item_list) { - return new (thd->mem_root) Item_func_rpad(thd, arg1, arg2, arg3); + Item *func= NULL; + int arg_count= item_list ? item_list->elements : 0; + + switch (arg_count) { + case 2: + { + Item *param_1= item_list->pop(); + Item *param_2= item_list->pop(); + func= new (thd->mem_root) Item_func_rpad(thd, param_1, param_2); + break; + } + case 3: + { + Item *param_1= item_list->pop(); + Item *param_2= item_list->pop(); + Item *param_3= item_list->pop(); + func= new (thd->mem_root) Item_func_rpad(thd, param_1, param_2, param_3); + break; + } + default: + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str); + break; + } + + return func; } |