MDEV-31184 Remove parser tokens DECODE_MARIADB_SYM and DECODE_ORACLE_SYM
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
This commit is contained in:
parent
c5f776e9fa
commit
09e237088c
@ -5270,5 +5270,17 @@ SELECT GROUP_CONCAT( UpdateXML( '<a>new year</a>', '/a', '2019-01-01 00:00:00' )
|
||||
f
|
||||
2019-01-01 00:00:00F}^i
|
||||
#
|
||||
# MDEV-31184 Remove parser tokens DECODE_MARIADB_SYM and DECODE_ORACLE_SYM
|
||||
#
|
||||
SELECT DECODE();
|
||||
ERROR 42000: Incorrect parameter count in the call to native function 'DECODE'
|
||||
SELECT DECODE(NULL);
|
||||
ERROR 42000: Incorrect parameter count in the call to native function 'DECODE'
|
||||
SELECT DECODE(NULL,NULL);
|
||||
DECODE(NULL,NULL)
|
||||
NULL
|
||||
SELECT DECODE(NULL, NULL, NULL);
|
||||
ERROR 42000: Incorrect parameter count in the call to native function 'DECODE'
|
||||
#
|
||||
# End of 10.4 tests
|
||||
#
|
||||
|
@ -2292,6 +2292,19 @@ DROP TABLE t1,t2;
|
||||
SELECT GROUP_CONCAT( UpdateXML( '<a>new year</a>', '/a', '2019-01-01 00:00:00' ), ENCODE('text','pass') ) AS f;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-31184 Remove parser tokens DECODE_MARIADB_SYM and DECODE_ORACLE_SYM
|
||||
--echo #
|
||||
|
||||
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
|
||||
SELECT DECODE();
|
||||
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
|
||||
SELECT DECODE(NULL);
|
||||
SELECT DECODE(NULL,NULL);
|
||||
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
|
||||
SELECT DECODE(NULL, NULL, NULL);
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.4 tests
|
||||
--echo #
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
@ -7285,6 +7309,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)},
|
||||
|
@ -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)},
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user