From 8e6f10335d2c6afb1d34e99af6e1ee49b6e4a875 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Sat, 10 Nov 2018 23:11:34 +0400 Subject: [PATCH] A join patch for MDEV-17660 and MDEV-17661 MDEV-17660 sql_mode=ORACLE: Some keywords do not work as label names: history, system, versioning, without MDEV-17661 Add sql_mode specific tokens for the keyword DECODE --- .../suite/compat/oracle/r/parser.result | 33 ++++++++++ mysql-test/suite/compat/oracle/t/parser.test | 58 +++++++++++++++++ sql/lex.h | 2 +- sql/sql_lex.cc | 1 + sql/sql_yacc.yy | 34 +++++++++- sql/sql_yacc_ora.yy | 64 +++++++++++-------- 6 files changed, 160 insertions(+), 32 deletions(-) diff --git a/mysql-test/suite/compat/oracle/r/parser.result b/mysql-test/suite/compat/oracle/r/parser.result index c8600c29bd4..4ee34e5e2b3 100644 --- a/mysql-test/suite/compat/oracle/r/parser.result +++ b/mysql-test/suite/compat/oracle/r/parser.result @@ -499,3 +499,36 @@ test.comment() Warnings: Note 1585 This function 'comment' has the same name as a native function DROP FUNCTION comment; +# +# MDEV-17660 sql_mode=ORACLE: Some keywords do not work as label names: history, system, versioning, without +# +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ diff --git a/mysql-test/suite/compat/oracle/t/parser.test b/mysql-test/suite/compat/oracle/t/parser.test index 86b6b270ccd..b3387b3f922 100644 --- a/mysql-test/suite/compat/oracle/t/parser.test +++ b/mysql-test/suite/compat/oracle/t/parser.test @@ -258,3 +258,61 @@ enable_prepare_warnings; SELECT test.comment() FROM DUAL; disable_prepare_warnings; DROP FUNCTION comment; + + +--echo # +--echo # MDEV-17660 sql_mode=ORACLE: Some keywords do not work as label names: history, system, versioning, without +--echo # + +DELIMITER /; +BEGIN +<> + NULL; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +BEGIN +<> + NULL; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +BEGIN +<> + NULL; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +BEGIN +<> + NULL; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +BEGIN +<> + NULL; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +BEGIN +<> + NULL; +END; +/ +DELIMITER ;/ diff --git a/sql/lex.h b/sql/lex.h index d3878186696..707bd464a14 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -739,7 +739,7 @@ static SYMBOL sql_functions[] = { { "DATE_ADD", SYM(DATE_ADD_INTERVAL)}, { "DATE_SUB", SYM(DATE_SUB_INTERVAL)}, { "DATE_FORMAT", SYM(DATE_FORMAT_SYM)}, - { "DECODE", SYM(DECODE_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 cab5381e0ed..a80c6485cf0 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -844,6 +844,7 @@ int Lex_input_stream::find_keyword(Lex_ident_cli_st *kwd, case BEGIN_MARIADB_SYM: return BEGIN_ORACLE_SYM; case BODY_MARIADB_SYM: return BODY_ORACLE_SYM; case CONTINUE_MARIADB_SYM: return CONTINUE_ORACLE_SYM; + case DECODE_MARIADB_SYM: return DECODE_ORACLE_SYM; case ELSIF_MARIADB_SYM: return ELSIF_ORACLE_SYM; case EXCEPTION_MARIADB_SYM: return EXCEPTION_ORACLE_SYM; case EXIT_MARIADB_SYM: return EXIT_ORACLE_SYM; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 745dc5664dc..3b694a9cc81 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1314,7 +1314,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token DATE_SYM /* SQL-2003-R, Oracle-R, PLSQL-R */ %token DAY_SYM /* SQL-2003-R */ %token DEALLOCATE_SYM /* SQL-2003-R */ -%token DECODE_SYM /* Oracle function, non-reserved */ +%token DECODE_MARIADB_SYM /* Function, non-reserved */ +%token DECODE_ORACLE_SYM /* Function, non-reserved */ %token DEFINER_SYM %token DELAYED_SYM %token DELAY_KEY_WRITE_SYM @@ -1961,6 +1962,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type 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 %type sp_cursor_stmt_lex @@ -10538,12 +10540,18 @@ function_call_nonkeyword: if (unlikely($$ == NULL)) MYSQL_YYABORT; } - | DECODE_SYM '(' expr ',' expr ')' + | 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); @@ -11701,6 +11709,25 @@ when_list_opt_else: } ; +decode_when_list_oracle: + expr ',' expr + { + $$= new (thd->mem_root) List; + 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 in the SQL:2003 standard. */ /* Warning - may return NULL in case of incomplete SELECT */ table_ref: @@ -15801,7 +15828,8 @@ keyword_sp_var_and_label: | DATAFILE_SYM | DATE_FORMAT_SYM | DAY_SYM - | DECODE_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 529582d8dc9..a58af90922c 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -708,7 +708,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token DATE_SYM /* SQL-2003-R, Oracle-R, PLSQL-R */ %token DAY_SYM /* SQL-2003-R */ %token DEALLOCATE_SYM /* SQL-2003-R */ -%token DECODE_SYM /* Oracle function, non-reserved */ +%token DECODE_MARIADB_SYM /* Function, non-reserved */ +%token DECODE_ORACLE_SYM /* Function, non-reserved */ %token DEFINER_SYM %token DELAYED_SYM %token DELAY_KEY_WRITE_SYM @@ -1364,7 +1365,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type 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 + decode_when_list_oracle %type sp_cursor_stmt_lex @@ -10211,24 +10212,6 @@ column_default_non_parenthesized_expr: if (unlikely($$ == NULL)) MYSQL_YYABORT; } - | DATE_FORMAT_SYM '(' expr ',' expr ')' - { - $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5); - if (unlikely($$ == NULL)) - MYSQL_YYABORT; - } - | DATE_FORMAT_SYM '(' expr ',' expr ',' expr ')' - { - $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5, $7); - if (unlikely($$ == NULL)) - MYSQL_YYABORT; - } - | DECODE_SYM '(' expr ',' decode_when_list ')' - { - $5->push_front($3, thd->mem_root); - if (unlikely(!($$= new (thd->mem_root) Item_func_decode_oracle(thd, *$5)))) - MYSQL_YYABORT; - } | DEFAULT '(' simple_ident ')' { Item_splocal *il= $3->get_item_splocal(); @@ -10565,6 +10548,30 @@ function_call_nonkeyword: if (unlikely($$ == NULL)) MYSQL_YYABORT; } + | DATE_FORMAT_SYM '(' expr ',' expr ')' + { + $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5); + if (unlikely($$ == NULL)) + MYSQL_YYABORT; + } + | DATE_FORMAT_SYM '(' expr ',' expr ',' expr ')' + { + $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5, $7); + 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); @@ -11730,7 +11737,7 @@ when_list_opt_else: } ; -decode_when_list: +decode_when_list_oracle: expr ',' expr { $$= new (thd->mem_root) List; @@ -11740,7 +11747,7 @@ decode_when_list: MYSQL_YYABORT; } - | decode_when_list ',' expr + | decode_when_list_oracle ',' expr { $$= $1; if (unlikely($$->push_back($3, thd->mem_root))) @@ -15704,7 +15711,6 @@ keyword_sp_var_not_label: | FORMAT_SYM | GET_SYM | HELP_SYM - | HISTORY_SYM | HOST_SYM | INSTALL_SYM | OPTION @@ -15729,15 +15735,11 @@ keyword_sp_var_not_label: | START_SYM | STOP_SYM | STORED_SYM - | SYSTEM - | SYSTEM_TIME_SYM | TIES_SYM | UNICODE_SYM | UNINSTALL_SYM | UNBOUNDED_SYM - | VERSIONING_SYM | WITHIN - | WITHOUT | WRAPPER_SYM | XA_SYM | UPGRADE_SYM @@ -15925,7 +15927,8 @@ keyword_sp_var_and_label: | DATAFILE_SYM | DATE_FORMAT_SYM | DAY_SYM - | DECODE_SYM + | DECODE_MARIADB_SYM + | DECODE_ORACLE_SYM | DEFINER_SYM | DELAY_KEY_WRITE_SYM | DES_KEY_FILE @@ -15967,6 +15970,7 @@ keyword_sp_var_and_label: | GOTO_MARIADB_SYM | HASH_SYM | HARD_SYM + | HISTORY_SYM | HOSTS_SYM | HOUR_SYM | ID_SYM @@ -16144,6 +16148,8 @@ keyword_sp_var_and_label: | SUSPEND_SYM | SWAPS_SYM | SWITCHES_SYM + | SYSTEM + | SYSTEM_TIME_SYM | TABLE_NAME_SYM | TABLES | TABLE_CHECKSUM_SYM @@ -16169,6 +16175,7 @@ keyword_sp_var_and_label: | USER_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2 | USE_FRM | VARIABLES + | VERSIONING_SYM | VIEW_SYM | VIRTUAL_SYM | VALUE_SYM @@ -16176,6 +16183,7 @@ keyword_sp_var_and_label: | WAIT_SYM | WEEK_SYM | WEIGHT_STRING_SYM + | WITHOUT | WORK_SYM | X509_SYM | XML_SYM