diff options
author | Alexander Barkov <bar@mariadb.com> | 2023-04-28 16:13:38 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2023-05-04 10:44:44 +0400 |
commit | ce1458de6499f6764ffccbdbe55c6fd34fd44fc9 (patch) | |
tree | 4756a58e147b80f957eef7143580e74baf1634f7 | |
parent | 01ea779149a32f0dfd6fe8ea52c7ba51a69e1016 (diff) | |
download | mariadb-git-bb-10.4-bar.tar.gz |
MDEV-31184 Remove parser tokens DECODE_MARIADB_SYM and DECODE_ORACLE_SYMbb-10.4-bar
Changing the code handling sql_mode-dependent function DECODE():
- removing parser tokens DECODE_MARIADB_SYM and DECODE_ORACLE_SYM
- removing the DECODE() related code from sql_yacc.yy/sql_yacc_ora.yy
- adding handling of DECODE() with help of a new Create_func_func_decode
-rw-r--r-- | mysql-test/suite/compat/oracle/r/func_decode.result | 8 | ||||
-rw-r--r-- | mysql-test/suite/compat/oracle/t/func_decode.test | 8 | ||||
-rw-r--r-- | sql/item_create.cc | 53 | ||||
-rw-r--r-- | sql/lex.h | 1 | ||||
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 36 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 36 |
7 files changed, 47 insertions, 96 deletions
diff --git a/mysql-test/suite/compat/oracle/r/func_decode.result b/mysql-test/suite/compat/oracle/r/func_decode.result index b49bad93627..2809e971be3 100644 --- a/mysql-test/suite/compat/oracle/r/func_decode.result +++ b/mysql-test/suite/compat/oracle/r/func_decode.result @@ -1,8 +1,8 @@ SET sql_mode=ORACLE; SELECT DECODE(10); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' SELECT DECODE(10,10); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' SELECT DECODE(10,10,'x10'); DECODE(10,10,'x10') x10 @@ -35,9 +35,9 @@ DROP TABLE decode; # MDEV-13863 sql_mode=ORACLE: DECODE does not treat two NULLs as equivalent # SELECT DECODE(10); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' SELECT DECODE(10,10); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' SELECT DECODE_ORACLE(10); ERROR 42000: Incorrect parameter count in the call to native function 'DECODE_ORACLE' SELECT DECODE_ORACLE(10,10); diff --git a/mysql-test/suite/compat/oracle/t/func_decode.test b/mysql-test/suite/compat/oracle/t/func_decode.test index 1d49cdd2102..b8be7178570 100644 --- a/mysql-test/suite/compat/oracle/t/func_decode.test +++ b/mysql-test/suite/compat/oracle/t/func_decode.test @@ -1,8 +1,8 @@ SET sql_mode=ORACLE; ---error ER_PARSE_ERROR +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT SELECT DECODE(10); ---error ER_PARSE_ERROR +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT SELECT DECODE(10,10); SELECT DECODE(10,10,'x10'); @@ -25,9 +25,9 @@ DROP TABLE decode; --echo # MDEV-13863 sql_mode=ORACLE: DECODE does not treat two NULLs as equivalent --echo # ---error ER_PARSE_ERROR +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT SELECT DECODE(10); ---error ER_PARSE_ERROR +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT SELECT DECODE(10,10); --error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT diff --git a/sql/item_create.cc b/sql/item_create.cc index a95d2ae4f9a..3f8c71cbe00 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -602,7 +602,15 @@ class Create_func_decode_oracle : public Create_native_func { public: virtual Item *create_native(THD *thd, const LEX_CSTRING *name, - List<Item> *item_list); + List<Item> *item_list) + { + if (unlikely(!item_list || item_list->elements < 3)) + { + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str); + return NULL; + } + return new (thd->mem_root) Item_func_decode_oracle(thd, *item_list); + } static Create_func_decode_oracle s_singleton; @@ -612,6 +620,33 @@ protected: }; +class Create_func_decode : public Create_native_func +{ +public: + virtual Item *create_native(THD *thd, const LEX_CSTRING *name, + List<Item> *item_list) + { + if (thd->variables.sql_mode & MODE_ORACLE) + return Create_func_decode_oracle::s_singleton.create_native(thd, name, + item_list); + if (unlikely(!item_list || item_list->elements != 2)) + { + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str); + return NULL; + } + Item_args args(thd, *item_list); + return new (thd->mem_root) Item_func_decode(thd, args.arguments()[0], + args.arguments()[1]); + } + + static Create_func_decode s_singleton; + +protected: + Create_func_decode() {} + virtual ~Create_func_decode() {} +}; + + class Create_func_concat_ws : public Create_native_func { public: @@ -4074,20 +4109,9 @@ Create_func_decode_histogram::create_2_arg(THD *thd, Item *arg1, Item *arg2) return new (thd->mem_root) Item_func_decode_histogram(thd, arg1, arg2); } -Create_func_decode_oracle Create_func_decode_oracle::s_singleton; +Create_func_decode Create_func_decode::s_singleton; -Item* -Create_func_decode_oracle::create_native(THD *thd, const LEX_CSTRING *name, - List<Item> *item_list) -{ - uint arg_count= item_list ? item_list->elements : 0; - if (unlikely(arg_count < 3)) - { - my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str); - return NULL; - } - return new (thd->mem_root) Item_func_decode_oracle(thd, *item_list); -} +Create_func_decode_oracle Create_func_decode_oracle::s_singleton; Create_func_concat_ws Create_func_concat_ws::s_singleton; @@ -7299,6 +7323,7 @@ const Native_func_registry func_array[] = { { STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)}, { { STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)}, { { STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)}, + { { STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)}, { { STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)}, { { STRING_WITH_LEN("DECODE_HISTOGRAM") }, BUILDER(Create_func_decode_histogram)}, { { STRING_WITH_LEN("DECODE_ORACLE") }, BUILDER(Create_func_decode_oracle)}, diff --git a/sql/lex.h b/sql/lex.h index e35e109a3bf..6f083075d3e 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -744,7 +744,6 @@ SYMBOL sql_functions[] = { { "DATE_ADD", SYM(DATE_ADD_INTERVAL)}, { "DATE_SUB", SYM(DATE_SUB_INTERVAL)}, { "DATE_FORMAT", SYM(DATE_FORMAT_SYM)}, - { "DECODE", SYM(DECODE_MARIADB_SYM)}, { "DENSE_RANK", SYM(DENSE_RANK_SYM)}, { "EXTRACT", SYM(EXTRACT_SYM)}, { "FIRST_VALUE", SYM(FIRST_VALUE_SYM)}, diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 019377061a0..71f592a3852 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -873,7 +873,6 @@ int Lex_input_stream::find_keyword(Lex_ident_cli_st *kwd, case CLOB_MARIADB_SYM: return CLOB_ORACLE_SYM; case CONTINUE_MARIADB_SYM: return CONTINUE_ORACLE_SYM; case DECLARE_MARIADB_SYM: return DECLARE_ORACLE_SYM; - case DECODE_MARIADB_SYM: return DECODE_ORACLE_SYM; case ELSEIF_MARIADB_SYM: return ELSEIF_ORACLE_SYM; case ELSIF_MARIADB_SYM: return ELSIF_ORACLE_SYM; case EXCEPTION_MARIADB_SYM: return EXCEPTION_ORACLE_SYM; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cdc04d93708..048741b6ca1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1275,8 +1275,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token <kwd> DATE_SYM /* SQL-2003-R, Oracle-R, PLSQL-R */ %token <kwd> DAY_SYM /* SQL-2003-R */ %token <kwd> DEALLOCATE_SYM /* SQL-2003-R */ -%token <kwd> DECODE_MARIADB_SYM /* Function, non-reserved */ -%token <kwd> DECODE_ORACLE_SYM /* Function, non-reserved */ %token <kwd> DEFINER_SYM %token <kwd> DELAYED_SYM %token <kwd> DELAY_KEY_WRITE_SYM @@ -1949,7 +1947,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <item_list> expr_list opt_udf_expr_list udf_expr_list when_list when_list_opt_else ident_list ident_list_arg opt_expr_list - decode_when_list_oracle execute_using execute_params @@ -11027,18 +11024,6 @@ function_call_nonkeyword: if (unlikely($$ == NULL)) MYSQL_YYABORT; } - | DECODE_MARIADB_SYM '(' expr ',' expr ')' - { - $$= new (thd->mem_root) Item_func_decode(thd, $3, $5); - if (unlikely($$ == NULL)) - MYSQL_YYABORT; - } - | DECODE_ORACLE_SYM '(' expr ',' decode_when_list_oracle ')' - { - $5->push_front($3, thd->mem_root); - if (unlikely(!($$= new (thd->mem_root) Item_func_decode_oracle(thd, *$5)))) - MYSQL_YYABORT; - } | EXTRACT_SYM '(' interval FROM expr ')' { $$=new (thd->mem_root) Item_extract(thd, $3, $5); @@ -12209,25 +12194,6 @@ when_list_opt_else: } ; -decode_when_list_oracle: - expr ',' expr - { - $$= new (thd->mem_root) List<Item>; - if (unlikely($$ == NULL) || - unlikely($$->push_back($1, thd->mem_root)) || - unlikely($$->push_back($3, thd->mem_root))) - MYSQL_YYABORT; - - } - | decode_when_list_oracle ',' expr - { - $$= $1; - if (unlikely($$->push_back($3, thd->mem_root))) - MYSQL_YYABORT; - } - ; - - /* Equivalent to <table reference> in the SQL:2003 standard. */ /* Warning - may return NULL in case of incomplete SELECT */ table_ref: @@ -16365,8 +16331,6 @@ keyword_sp_var_and_label: | DATAFILE_SYM | DATE_FORMAT_SYM | DAY_SYM - | DECODE_MARIADB_SYM - | DECODE_ORACLE_SYM | DEFINER_SYM | DELAY_KEY_WRITE_SYM | DES_KEY_FILE diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 5b734a27f8c..325ca4ccdc6 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -751,8 +751,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token <kwd> DATE_SYM /* SQL-2003-R, Oracle-R, PLSQL-R */ %token <kwd> DAY_SYM /* SQL-2003-R */ %token <kwd> DEALLOCATE_SYM /* SQL-2003-R */ -%token <kwd> DECODE_MARIADB_SYM /* Function, non-reserved */ -%token <kwd> DECODE_ORACLE_SYM /* Function, non-reserved */ %token <kwd> DEFINER_SYM %token <kwd> DELAYED_SYM %token <kwd> DELAY_KEY_WRITE_SYM @@ -1432,7 +1430,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <item_list> expr_list opt_udf_expr_list udf_expr_list when_list when_list_opt_else ident_list ident_list_arg opt_expr_list - decode_when_list_oracle execute_using execute_params @@ -11142,18 +11139,6 @@ function_call_nonkeyword: if (unlikely($$ == NULL)) MYSQL_YYABORT; } - | DECODE_MARIADB_SYM '(' expr ',' expr ')' - { - $$= new (thd->mem_root) Item_func_decode(thd, $3, $5); - if (unlikely($$ == NULL)) - MYSQL_YYABORT; - } - | DECODE_ORACLE_SYM '(' expr ',' decode_when_list_oracle ')' - { - $5->push_front($3, thd->mem_root); - if (unlikely(!($$= new (thd->mem_root) Item_func_decode_oracle(thd, *$5)))) - MYSQL_YYABORT; - } | EXTRACT_SYM '(' interval FROM expr ')' { $$=new (thd->mem_root) Item_extract(thd, $3, $5); @@ -12324,25 +12309,6 @@ when_list_opt_else: } ; -decode_when_list_oracle: - expr ',' expr - { - $$= new (thd->mem_root) List<Item>; - if (unlikely($$ == NULL) || - unlikely($$->push_back($1, thd->mem_root)) || - unlikely($$->push_back($3, thd->mem_root))) - MYSQL_YYABORT; - - } - | decode_when_list_oracle ',' expr - { - $$= $1; - if (unlikely($$->push_back($3, thd->mem_root))) - MYSQL_YYABORT; - } - ; - - /* Equivalent to <table reference> in the SQL:2003 standard. */ /* Warning - may return NULL in case of incomplete SELECT */ table_ref: @@ -16535,8 +16501,6 @@ keyword_sp_var_and_label: | DATAFILE_SYM | DATE_FORMAT_SYM | DAY_SYM - | DECODE_MARIADB_SYM - | DECODE_ORACLE_SYM | DEFINER_SYM | DELAY_KEY_WRITE_SYM | DES_KEY_FILE |