diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-11-18 16:41:21 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-11-19 08:06:04 +0400 |
commit | 251c6e1726971376a65315adc5a8e74bea62ee05 (patch) | |
tree | f0a65761b7d7be6c3dc036d507210ed2075b6718 | |
parent | a9846f329935faba560387bab8fd897102e17385 (diff) | |
download | mariadb-git-251c6e1726971376a65315adc5a8e74bea62ee05.tar.gz |
MDEV-21073 Collect different grammar rules into a single chunk
On order to unify the two *.yy files easier,
this patch collects all different rules to the end of *.yy files,
so the rule section looks like this:
%%
common rules
different rules
-rw-r--r-- | sql/sql_lex.cc | 38 | ||||
-rw-r--r-- | sql/sql_lex.h | 7 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 877 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 2086 |
4 files changed, 1627 insertions, 1381 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index d522b8e3a5e..a7e6ecd3387 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -9741,6 +9741,17 @@ LEX::add_primary_to_query_expression_body(SELECT_LEX_UNIT *unit, } +SELECT_LEX_UNIT * +LEX::add_primary_to_query_expression_body(SELECT_LEX_UNIT *unit, + SELECT_LEX *sel, + enum sub_select_type unit_type, + bool distinct) +{ + return + add_primary_to_query_expression_body(unit, sel, unit_type, distinct, + thd->variables.sql_mode & MODE_ORACLE); +} + /** Add query primary to a parenthesized query primary pruducing a new query expression body @@ -11130,3 +11141,30 @@ bool LEX::sp_if_after_statements(THD *thd) sphead->push_backpatch(thd, i, spcont->push_label(thd, &empty_clex_str, 0)); return false; } + + +sp_condition_value *LEX::stmt_signal_value(const Lex_ident_sys_st &ident) +{ + sp_condition_value *cond; + /* SIGNAL foo cannot be used outside of stored programs */ + if (unlikely(spcont == NULL)) + { + my_error(ER_SP_COND_MISMATCH, MYF(0), ident.str); + return NULL; + } + cond= spcont->find_declared_or_predefined_condition(thd, &ident); + if (unlikely(cond == NULL)) + { + my_error(ER_SP_COND_MISMATCH, MYF(0), ident.str); + return NULL; + } + bool bad= thd->variables.sql_mode & MODE_ORACLE ? + !cond->has_sql_state() : + cond->type != sp_condition_value::SQLSTATE; + if (unlikely(bad)) + { + my_error(ER_SIGNAL_BAD_CONDITION_TYPE, MYF(0)); + return NULL; + } + return cond; +} diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 44e4e579fdc..4abc7dde940 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -4509,6 +4509,11 @@ public: bool distinct, bool oracle); SELECT_LEX_UNIT * + add_primary_to_query_expression_body(SELECT_LEX_UNIT *unit, + SELECT_LEX *sel, + enum sub_select_type unit_type, + bool distinct); + SELECT_LEX_UNIT * add_primary_to_query_expression_body_ext_parens( SELECT_LEX_UNIT *unit, SELECT_LEX *sel, @@ -4597,6 +4602,8 @@ public: bool stmt_alter_function_start(sp_name *name); bool stmt_alter_procedure_start(sp_name *name); + sp_condition_value *stmt_signal_value(const Lex_ident_sys_st &ident); + Spvar_definition *row_field_name(THD *thd, const Lex_ident_sys_st &name); bool set_field_type_udt(Lex_field_type_st *type, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9c0068b5436..59c22eff31c 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1257,7 +1257,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); key_cache_name sp_opt_label BIN_NUM TEXT_STRING_filesystem opt_constraint constraint opt_ident - sp_block_label opt_place opt_db + sp_block_label sp_control_label opt_place opt_db %type <ident_sys> IDENT_sys @@ -1267,6 +1267,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); ident_or_empty ident_table_alias ident_sysvar_name + ident_for_loop_index %type <lex_string_with_metadata> TEXT_STRING @@ -1301,6 +1302,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); keyword_verb_clause charset reserved_keyword_udt + reserved_keyword_udt_not_param_type non_reserved_keyword_udt %type <table> @@ -1558,9 +1560,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <select_order> opt_order_clause order_clause order_list %type <NONE> + directly_executable_statement analyze_stmt_command backup backup_statements - query verb_clause create change select select_into - do drop insert replace insert_start stmt_end + query verb_clause create create_routine change select select_into + do drop drop_routine insert replace insert_start stmt_end insert_values update delete truncate rename compound_statement show describe load alter optimize keycache preload flush reset purge begin_stmt_mariadb commit rollback savepoint release @@ -1631,6 +1634,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); opt_constraint_no_id %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt +%type <NONE> sp_if_then_statements sp_case_then_statements %type <NONE> sp_proc_stmt_statement sp_proc_stmt_return %type <NONE> sp_proc_stmt_compound_ok %type <NONE> sp_proc_stmt_if @@ -1641,9 +1645,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <NONE> sp_proc_stmt_leave %type <NONE> sp_proc_stmt_iterate %type <NONE> sp_proc_stmt_goto_oracle +%type <NONE> sp_proc_stmt_with_cursor %type <NONE> sp_proc_stmt_open sp_proc_stmt_fetch sp_proc_stmt_close %type <NONE> case_stmt_specification %type <NONE> loop_body while_body repeat_body +%type <NONE> for_loop_statements %type <num> view_algorithm view_check_option %type <view_suid> view_suid opt_view_suid @@ -1657,11 +1663,12 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value %type <spname> sp_name %type <spvar> sp_param_name sp_param_name_and_type +%type <spvar> sp_param_name_and_type_anchored %type <for_loop> sp_for_loop_index_and_bounds %type <for_loop_bounds> sp_for_loop_bounds %type <trim> trim_operands %type <num> opt_sp_for_loop_direction -%type <spvar_mode> sp_opt_inout +%type <spvar_mode> sp_parameter_type %type <index_hint> index_hint_type %type <num> index_hint_clause normal_join inner_join %type <filetype> data_or_xml @@ -1707,7 +1714,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <vers_column_versioning> with_or_without_system /* Start of sql_mode=DEFAULT specific declarations */ -%type <NONE> sp_tail +%type <NONE> sp_tail_standalone %type <NONE> sp_unlabeled_block_not_atomic %type <NONE> sp_proc_stmt_in_returns_clause %type <lex_str> sp_label @@ -1716,6 +1723,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <spblock> sp_decl %type <spblock> sp_decl_body %type <spblock> sp_decl_variable_list +%type <spblock> sp_decl_variable_list_anchored +%type <kwd> reserved_keyword_udt_param_type + /* End of sql_mode=DEFAULT specific declarations */ %% @@ -1752,7 +1762,7 @@ query: thd->lex->sql_command= SQLCOM_EMPTY_QUERY; YYLIP->found_semicolon= NULL; } - | verb_clause + | directly_executable_statement { Lex_input_stream *lip = YYLIP; @@ -1777,7 +1787,7 @@ query: } ';' opt_end_of_input - | verb_clause END_OF_INPUT + | directly_executable_statement END_OF_INPUT { /* Single query, not terminated. */ YYLIP->found_semicolon= NULL; @@ -1789,14 +1799,14 @@ opt_end_of_input: | END_OF_INPUT ; -verb_clause: +directly_executable_statement: statement | begin_stmt_mariadb | compound_statement ; /* Verb clauses, except begin and compound_statement */ -statement: +verb_clause: alter | analyze | analyze_stmt_command @@ -2378,15 +2388,6 @@ create: { Lex->pop_select(); //main select } - | create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists - { - if (Lex->stmt_create_procedure_start($1 | $4)) - MYSQL_YYABORT; - } - sp_tail - { - Lex->stmt_create_routine_finalize(); - } | create_or_replace definer_opt EVENT_SYM { if (Lex->main_select_push()) @@ -2397,37 +2398,6 @@ create: { Lex->pop_select(); //main select } - | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists - sp_name - { - if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) - MYSQL_YYABORT; - } - sp_parenthesized_fdparam_list - sf_return_type - sf_c_chistics_and_body - { - Lex->stmt_create_routine_finalize(); - } - | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists - sp_name - { - if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) - MYSQL_YYABORT; - } - sp_parenthesized_fdparam_list - sf_return_type - sf_c_chistics_and_body - { - Lex->stmt_create_routine_finalize(); - } - | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists - ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys - { - if (Lex->stmt_create_udf_function($1 | $5, $3, $6, - (Item_result) $8, $10)) - MYSQL_YYABORT; - } | create_or_replace USER_SYM opt_if_not_exists clear_privileges grant_list opt_require_clause opt_resource_options opt_account_locking opt_password_expiration { @@ -2453,6 +2423,7 @@ create: | create_or_replace { Lex->set_command(SQLCOM_CREATE_SERVER, $1); } server_def { } + | create_routine ; opt_sequence: @@ -2924,34 +2895,12 @@ sp_param_name_and_type: if (unlikely(Lex->sp_param_fill_definition($$= $1, $2))) MYSQL_YYABORT; } - | sp_param_name TYPE_SYM OF_SYM ident '.' ident - { - if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, - $$= $1, $4, - $6))) - MYSQL_YYABORT; - } - | sp_param_name TYPE_SYM OF_SYM ident '.' ident '.' ident - { - if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, - $4, $6, $8))) - MYSQL_YYABORT; - } - | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident - { - if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5))) - MYSQL_YYABORT; - } - | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident '.' ident - { - if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5, $7))) - MYSQL_YYABORT; - } | sp_param_name ROW_SYM row_type_body { if (unlikely(Lex->sphead->spvar_fill_row(thd, $$= $1, $3))) MYSQL_YYABORT; } + | sp_param_name_and_type_anchored ; /* Stored PROCEDURE parameter declaration list */ @@ -2965,13 +2914,8 @@ sp_pdparams: | sp_pdparam ; -sp_pdparam: - sp_opt_inout sp_param_name_and_type { $2->mode=$1; } - ; - -sp_opt_inout: - /* Empty */ { $$= sp_variable::MODE_IN; } - | IN_SYM { $$= sp_variable::MODE_IN; } +sp_parameter_type: + IN_SYM { $$= sp_variable::MODE_IN; } | OUT_SYM { $$= sp_variable::MODE_OUT; } | INOUT_SYM { $$= sp_variable::MODE_INOUT; } ; @@ -3002,26 +2946,6 @@ sp_proc_stmts1: | sp_proc_stmts1 sp_proc_stmt ';' ; -sp_decls: - /* Empty */ - { - $$.init(); - } - | sp_decls sp_decl ';' - { - /* We check for declarations out of (standard) order this way - because letting the grammar rules reflect it caused tricky - shift/reduce conflicts with the wrong result. (And we get - better error handling this way.) */ - if (unlikely(Lex->sp_declarations_join(&$$, $1, $2))) - MYSQL_YYABORT; - } - ; - -sp_decl: - DECLARE_MARIADB_SYM sp_decl_body { $$= $2; } - ; - optionally_qualified_column_ident: sp_decl_ident @@ -3044,13 +2968,6 @@ optionally_qualified_column_ident: } ; -row_field_name: - ident - { - if (!($$= Lex->row_field_name(thd, $1))) - MYSQL_YYABORT; - } - ; row_field_definition: row_field_name type_with_opt_collate @@ -3100,22 +3017,6 @@ sp_decl_variable_list: $$.init_using_vars($1); } | sp_decl_idents_init_vars - TYPE_SYM OF_SYM optionally_qualified_column_ident - sp_opt_default - { - if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $4, $5))) - MYSQL_YYABORT; - $$.init_using_vars($1); - } - | sp_decl_idents_init_vars - ROW_SYM TYPE_SYM OF_SYM optionally_qualified_column_ident - sp_opt_default - { - if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $5, $6))) - MYSQL_YYABORT; - $$.init_using_vars($1); - } - | sp_decl_idents_init_vars ROW_SYM row_type_body sp_opt_default { @@ -3123,33 +3024,7 @@ sp_decl_variable_list: MYSQL_YYABORT; $$.init_using_vars($1); } - ; - -sp_decl_body: - sp_decl_variable_list - | sp_decl_ident CONDITION_SYM FOR_SYM sp_cond - { - if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4))) - MYSQL_YYABORT; - $$.vars= $$.hndlrs= $$.curs= 0; - $$.conds= 1; - } - | sp_decl_handler - | sp_decl_ident CURSOR_SYM - { - Lex->sp_block_init(thd); - } - opt_parenthesized_cursor_formal_parameters - FOR_SYM sp_cursor_stmt - { - sp_pcontext *param_ctx= Lex->spcont; - if (unlikely(Lex->sp_block_finalize(thd))) - MYSQL_YYABORT; - if (unlikely(Lex->sp_declare_cursor(thd, &$1, $6, param_ctx, true))) - MYSQL_YYABORT; - $$.vars= $$.conds= $$.hndlrs= 0; - $$.curs= 1; - } + | sp_decl_variable_list_anchored ; sp_decl_handler: @@ -3327,18 +3202,8 @@ signal_stmt: signal_value: ident { - LEX *lex= Lex; - sp_condition_value *cond; - - /* SIGNAL foo cannot be used outside of stored programs */ - if (unlikely(lex->spcont == NULL)) - my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str)); - cond= lex->spcont->find_declared_or_predefined_condition(thd, &$1); - if (unlikely(cond == NULL)) - my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str)); - if (unlikely(cond->type != sp_condition_value::SQLSTATE)) - my_yyabort_error((ER_SIGNAL_BAD_CONDITION_TYPE, MYF(0))); - $$= cond; + if (!($$= Lex->stmt_signal_value($1))) + MYSQL_YYABORT; } | sqlstate { $$= $1; } @@ -3629,48 +3494,6 @@ sp_decl_idents: } ; -sp_opt_default: - /* Empty */ { $$ = NULL; } - | DEFAULT expr { $$ = $2; } - ; - -/* - ps_proc_stmt_in_returns_clause is a statement that is allowed - in the RETURNS clause of a stored function definition directly, - without the BEGIN..END block. - It should not include any syntax structures starting with '(', to avoid - shift/reduce conflicts with the rule "field_type" and its sub-rules - that scan an optional length, like CHAR(1) or YEAR(4). - See MDEV-9166. -*/ -sp_proc_stmt_in_returns_clause: - sp_proc_stmt_return - | sp_labeled_block - | sp_unlabeled_block - | sp_labeled_control - | sp_proc_stmt_compound_ok - ; - -sp_proc_stmt: - sp_proc_stmt_in_returns_clause - | sp_proc_stmt_statement - | sp_proc_stmt_continue_oracle - | sp_proc_stmt_exit_oracle - | sp_proc_stmt_leave - | sp_proc_stmt_iterate - | sp_proc_stmt_goto_oracle - | sp_proc_stmt_open - | sp_proc_stmt_fetch - | sp_proc_stmt_close - ; - -sp_proc_stmt_compound_ok: - sp_proc_stmt_if - | case_stmt_specification - | sp_unlabeled_block_not_atomic - | sp_unlabeled_control - ; - sp_proc_stmt_if: IF_SYM { @@ -3681,7 +3504,7 @@ sp_proc_stmt_if: sp_if END IF_SYM { Lex->sphead->do_cont_backpatch(); } ; - + sp_proc_stmt_statement: { LEX *lex= thd->lex; @@ -3690,7 +3513,7 @@ sp_proc_stmt_statement: lex->sphead->reset_lex(thd); lex->sphead->m_tmp_query= lip->get_tok_start(); } - statement + sp_statement { if (Lex->sp_proc_stmt_statement_finalize(thd, yychar == YYEMPTY) || Lex->sphead->restore_lex(thd)) @@ -3877,6 +3700,12 @@ opt_parenthesized_cursor_actual_parameters: | '(' cursor_actual_parameters ')' { $$= $2; } ; +sp_proc_stmt_with_cursor: + sp_proc_stmt_open + | sp_proc_stmt_fetch + | sp_proc_stmt_close + ; + sp_proc_stmt_open: OPEN_SYM ident opt_parenthesized_cursor_actual_parameters { @@ -3967,7 +3796,7 @@ sp_if: if (unlikely($1->sp_if_expr(thd))) MYSQL_YYABORT; } - sp_proc_stmts1 + sp_if_then_statements { if (unlikely($1->sp_if_after_statements(thd))) MYSQL_YYABORT; @@ -3983,7 +3812,8 @@ sp_if: sp_elseifs: /* Empty */ | ELSEIF_MARIADB_SYM sp_if - | ELSE sp_proc_stmts1 + | ELSIF_ORACLE_SYM sp_if + | ELSE sp_if_then_statements ; case_stmt_specification: @@ -4086,7 +3916,7 @@ simple_when_clause: MYSQL_YYABORT; } THEN_SYM - sp_proc_stmts1 + sp_case_then_statements { if (unlikely(Lex->case_stmt_action_then())) MYSQL_YYABORT; @@ -4100,7 +3930,7 @@ searched_when_clause: MYSQL_YYABORT; } THEN_SYM - sp_proc_stmts1 + sp_case_then_statements { if (unlikely(Lex->case_stmt_action_then())) MYSQL_YYABORT; @@ -4119,11 +3949,7 @@ else_clause_opt: unlikely(sp->add_instr(i))) MYSQL_YYABORT; } - | ELSE sp_proc_stmts1 - ; - -sp_label: - label_ident ':' { $$= $1; } + | ELSE sp_case_then_statements ; sp_opt_label: @@ -4131,61 +3957,6 @@ sp_opt_label: | label_ident { $$= $1; } ; -sp_block_label: - sp_label - { - if (unlikely(Lex->spcont->block_label_declare(&$1))) - MYSQL_YYABORT; - $$= $1; - } - ; - -sp_labeled_block: - sp_block_label - BEGIN_MARIADB_SYM - { - Lex->sp_block_init(thd, &$1); - } - sp_decls - sp_proc_stmts - END - sp_opt_label - { - if (unlikely(Lex->sp_block_finalize(thd, $4, &$7))) - MYSQL_YYABORT; - } - ; - -sp_unlabeled_block: - BEGIN_MARIADB_SYM - { - Lex->sp_block_init(thd); - } - sp_decls - sp_proc_stmts - END - { - if (unlikely(Lex->sp_block_finalize(thd, $3))) - MYSQL_YYABORT; - } - ; - -sp_unlabeled_block_not_atomic: - BEGIN_MARIADB_SYM not ATOMIC_SYM /* TODO: BEGIN ATOMIC (not -> opt_not) */ - { - if (unlikely(Lex->maybe_start_compound_statement(thd))) - MYSQL_YYABORT; - Lex->sp_block_init(thd); - } - sp_decls - sp_proc_stmts - END - { - if (unlikely(Lex->sp_block_finalize(thd, $5))) - MYSQL_YYABORT; - } - ; - /* This adds one shift/reduce conflict */ opt_sp_for_loop_direction: /* Empty */ { $$= 1; } @@ -4193,7 +3964,7 @@ opt_sp_for_loop_direction: ; sp_for_loop_index_and_bounds: - ident sp_for_loop_bounds + ident_for_loop_index sp_for_loop_bounds { if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $2))) MYSQL_YYABORT; @@ -4235,19 +4006,6 @@ loop_body: } ; -while_body: - expr_lex DO_SYM - { - if (unlikely($1->sp_while_loop_expression(thd))) - MYSQL_YYABORT; - } - sp_proc_stmts1 END WHILE_SYM - { - if (unlikely(Lex->sp_while_loop_finalize(thd))) - MYSQL_YYABORT; - } - ; - repeat_body: sp_proc_stmts1 UNTIL_SYM expr_lex END REPEAT_SYM { @@ -4265,21 +4023,21 @@ pop_sp_loop_label: ; sp_labeled_control: - sp_label LOOP_SYM + sp_control_label LOOP_SYM { if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; } loop_body pop_sp_loop_label { } - | sp_label WHILE_SYM + | sp_control_label WHILE_SYM { if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; } while_body pop_sp_loop_label { } - | sp_label FOR_SYM + | sp_control_label FOR_SYM { // See "The FOR LOOP statement" comments in sql_lex.cc Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block @@ -4291,9 +4049,7 @@ sp_labeled_control: if (unlikely(Lex->sp_for_loop_condition_test(thd, $4))) MYSQL_YYABORT; } - DO_SYM - sp_proc_stmts1 - END FOR_SYM + for_loop_statements { if (unlikely(Lex->sp_for_loop_finalize(thd, $4))) MYSQL_YYABORT; @@ -4303,7 +4059,7 @@ sp_labeled_control: if (unlikely(Lex->sp_for_loop_outer_block_finalize(thd, $4))) MYSQL_YYABORT; } - | sp_label REPEAT_SYM + | sp_control_label REPEAT_SYM { if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; @@ -4345,9 +4101,7 @@ sp_unlabeled_control: if (unlikely(Lex->sp_for_loop_condition_test(thd, $3))) MYSQL_YYABORT; } - DO_SYM - sp_proc_stmts1 - END FOR_SYM + for_loop_statements { if (unlikely(Lex->sp_for_loop_finalize(thd, $3))) MYSQL_YYABORT; @@ -8912,8 +8666,7 @@ query_expression_body: { if (!($$= Lex->add_primary_to_query_expression_body($1, $4, $2.unit_type, - $2.distinct, - FALSE))) + $2.distinct))) MYSQL_YYABORT; } | query_expression_body_ext_parens @@ -12767,21 +12520,6 @@ drop: lex->set_command(SQLCOM_DROP_DB, $3); lex->name= $4; } - | DROP FUNCTION_SYM opt_if_exists ident '.' ident - { - if (Lex->stmt_drop_function($3, $4, $6)) - MYSQL_YYABORT; - } - | DROP FUNCTION_SYM opt_if_exists ident - { - if (Lex->stmt_drop_function($3, $4)) - MYSQL_YYABORT; - } - | DROP PROCEDURE_SYM opt_if_exists sp_name - { - if (Lex->stmt_drop_procedure($3, $4)) - MYSQL_YYABORT; - } | DROP USER_SYM opt_if_exists clear_privileges user_list { Lex->set_command(SQLCOM_DROP_USER, $3); @@ -12836,6 +12574,7 @@ drop: } table_list {} + | drop_routine ; table_list: @@ -13477,6 +13216,7 @@ truncate: if (unlikely(lex->m_sql_cmd == NULL)) MYSQL_YYABORT; } + opt_truncate_table_storage_clause { } ; opt_table_sym: @@ -13840,12 +13580,24 @@ show_param: lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE; lex->spname= $3; } + | CREATE PACKAGE_ORACLE_SYM sp_name + { + LEX *lex= Lex; + lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE; + lex->spname= $3; + } | CREATE PACKAGE_MARIADB_SYM BODY_MARIADB_SYM sp_name { LEX *lex= Lex; lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE_BODY; lex->spname= $4; } + | CREATE PACKAGE_ORACLE_SYM BODY_ORACLE_SYM sp_name + { + LEX *lex= Lex; + lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE_BODY; + lex->spname= $4; + } | CREATE TRIGGER_SYM sp_name { LEX *lex= Lex; @@ -13886,6 +13638,13 @@ show_param: if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) MYSQL_YYABORT; } + | PACKAGE_ORACLE_SYM STATUS_SYM wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE; + if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) + MYSQL_YYABORT; + } | PACKAGE_MARIADB_SYM BODY_MARIADB_SYM STATUS_SYM wild_and_where { LEX *lex= Lex; @@ -13893,6 +13652,13 @@ show_param: if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) MYSQL_YYABORT; } + | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM STATUS_SYM wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE_BODY; + if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) + MYSQL_YYABORT; + } | PROCEDURE_SYM CODE_SYM sp_name { Lex->sql_command= SQLCOM_SHOW_PROC_CODE; @@ -13908,6 +13674,11 @@ show_param: Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE; Lex->spname= $4; } + | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM CODE_SYM sp_name + { + Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE; + Lex->spname= $4; + } | CREATE EVENT_SYM sp_name { Lex->spname= $3; @@ -15280,6 +15051,7 @@ keyword_table_alias: | keyword_sp_var_not_label | keyword_sysvar_type | keyword_verb_clause + | FUNCTION_SYM | EXCEPTION_ORACLE_SYM ; @@ -15294,22 +15066,11 @@ keyword_ident: | keyword_sp_var_not_label | keyword_sysvar_type | keyword_verb_clause + | FUNCTION_SYM | WINDOW_SYM | EXCEPTION_ORACLE_SYM ; -/* - Keywords that we allow for labels in SPs. - Should not include keywords that start a statement or SP characteristics. -*/ -keyword_label: - keyword_data_type - | keyword_set_special_case - | keyword_sp_var_and_label - | keyword_sysvar_type - | EXCEPTION_ORACLE_SYM - ; - keyword_sysvar_name: keyword_data_type | keyword_cast_type @@ -15319,23 +15080,11 @@ keyword_sysvar_name: | keyword_sp_var_and_label | keyword_sp_var_not_label | keyword_verb_clause + | FUNCTION_SYM | WINDOW_SYM | EXCEPTION_ORACLE_SYM ; -keyword_sp_decl: - keyword_data_type - | keyword_cast_type - | keyword_set_special_case - | keyword_sp_block_section - | keyword_sp_head - | keyword_sp_var_and_label - | keyword_sp_var_not_label - | keyword_sysvar_type - | keyword_verb_clause - | WINDOW_SYM - ; - keyword_set_usual_case: keyword_data_type | keyword_cast_type @@ -15345,6 +15094,7 @@ keyword_set_usual_case: | keyword_sp_var_not_label | keyword_sysvar_type | keyword_verb_clause + | FUNCTION_SYM | WINDOW_SYM | EXCEPTION_ORACLE_SYM ; @@ -15497,14 +15247,6 @@ keyword_set_special_case: | PASSWORD_SYM ; -/* - Keywords that start an SP block section. -*/ -keyword_sp_block_section: - BEGIN_MARIADB_SYM - | END - ; - keyword_sysvar_type: GLOBAL_SYM | LOCAL_SYM @@ -15853,7 +15595,6 @@ keyword_sp_var_and_label: | TYPES_SYM | TYPE_SYM | UDF_RETURNS_SYM - | FUNCTION_SYM | UNCOMMITTED_SYM | UNDEFINED_SYM | UNDO_BUFFER_SIZE_SYM @@ -15879,7 +15620,7 @@ keyword_sp_var_and_label: ; -reserved_keyword_udt: +reserved_keyword_udt_not_param_type: ACCESSIBLE_SYM | ADD | ALL @@ -15969,13 +15710,11 @@ reserved_keyword_udt: | INDEX_SYM | INFILE | INNER_SYM - | INOUT_SYM | INSENSITIVE_SYM | INSERT | INTERSECT_SYM | INTERVAL_SYM | INTO - | IN_SYM | IS | ITERATE_SYM | JOIN_SYM @@ -16020,7 +15759,6 @@ reserved_keyword_udt: | OTHERS_ORACLE_SYM | OUTER | OUTFILE - | OUT_SYM | OVER_SYM | PACKAGE_ORACLE_SYM | PAGE_CHECKSUM_SYM @@ -16170,7 +15908,7 @@ set_param: if (Lex->check_main_unit_semantics()) MYSQL_YYABORT; } - FOR_SYM verb_clause + FOR_SYM directly_executable_statement ; set_stmt_option_list: @@ -17505,6 +17243,7 @@ query_expression_option: Select->options|= SELECT_HIGH_PRIORITY; } | DISTINCT { Select->options|= SELECT_DISTINCT; } + | UNIQUE_SYM { Select->options|= SELECT_DISTINCT; } | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; } | SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; } | SQL_BUFFER_RESULT { Select->options|= OPTION_BUFFER_RESULT; } @@ -17713,7 +17452,6 @@ trigger_tail: sf_return_type: - RETURNS_SYM { LEX *lex= Lex; lex->init_last_field(&lex->sphead->m_return_field_def, @@ -17722,47 +17460,12 @@ sf_return_type: } type_with_opt_collate { - if (unlikely(Lex->sf_return_fill_definition($3))) - MYSQL_YYABORT; - } - ; - -sf_c_chistics_and_body: - sp_c_chistics - { - LEX *lex= thd->lex; - lex->sphead->set_c_chistics(lex->sp_chistics); - lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); - } - sp_proc_stmt_in_returns_clause - { - if (unlikely(Lex->sp_body_finalize_function(thd))) + if (unlikely(Lex->sf_return_fill_definition($2))) MYSQL_YYABORT; } ; -sp_tail: - sp_name - { - if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1, - &sp_handler_procedure, - DEFAULT_AGGREGATE))) - MYSQL_YYABORT; - } - sp_parenthesized_pdparam_list - sp_c_chistics - { - Lex->sphead->set_c_chistics(Lex->sp_chistics); - Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); - } - sp_proc_stmt - { - if (unlikely(Lex->sp_body_finalize_procedure(thd))) - MYSQL_YYABORT; - } - ; - /*************************************************************************/ xa: @@ -17897,6 +17600,408 @@ keep_gcc_happy: } ; +/* Start of sql_mode=DEFAULT specific rules */ + +statement: + verb_clause + ; + +sp_statement: + statement + ; + +sp_if_then_statements: + sp_proc_stmts1 + ; + +sp_case_then_statements: + sp_proc_stmts1 + ; + +reserved_keyword_udt_param_type: + INOUT_SYM + | IN_SYM + | OUT_SYM + ; + +reserved_keyword_udt: + reserved_keyword_udt_not_param_type + | reserved_keyword_udt_param_type + ; + +/* Keywords that start an SP block section. */ +keyword_sp_block_section: + BEGIN_MARIADB_SYM + | END + ; + +/* + Keywords that we allow for labels in SPs. + Should not include keywords that start a statement or SP characteristics. +*/ +keyword_label: + keyword_data_type + | keyword_set_special_case + | keyword_sp_var_and_label + | keyword_sysvar_type + | FUNCTION_SYM + | EXCEPTION_ORACLE_SYM + ; + +keyword_sp_decl: + keyword_data_type + | keyword_cast_type + | keyword_set_special_case + | keyword_sp_block_section + | keyword_sp_head + | keyword_sp_var_and_label + | keyword_sp_var_not_label + | keyword_sysvar_type + | keyword_verb_clause + | FUNCTION_SYM + | WINDOW_SYM + ; + +opt_truncate_table_storage_clause: + /* Empty */ + ; + + +ident_for_loop_index: + ident + ; + +row_field_name: + ident + { + if (!($$= Lex->row_field_name(thd, $1))) + MYSQL_YYABORT; + } + ; + +while_body: + expr_lex DO_SYM + { + if (unlikely($1->sp_while_loop_expression(thd))) + MYSQL_YYABORT; + } + sp_proc_stmts1 END WHILE_SYM + { + if (unlikely(Lex->sp_while_loop_finalize(thd))) + MYSQL_YYABORT; + } + ; + +for_loop_statements: + DO_SYM sp_proc_stmts1 END FOR_SYM + { } + ; + +sp_label: + label_ident ':' { $$= $1; } + ; + +sp_control_label: + sp_label + ; + +sp_block_label: + sp_label + { + if (unlikely(Lex->spcont->block_label_declare(&$1))) + MYSQL_YYABORT; + $$= $1; + } + ; + +sp_opt_default: + /* Empty */ { $$ = NULL; } + | DEFAULT expr { $$ = $2; } + ; + +sp_pdparam: + sp_parameter_type sp_param_name_and_type { $2->mode=$1; } + | sp_param_name_and_type { $1->mode= sp_variable::MODE_IN; } + ; + +sp_decl_variable_list_anchored: + sp_decl_idents_init_vars + TYPE_SYM OF_SYM optionally_qualified_column_ident + sp_opt_default + { + if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $4, $5))) + MYSQL_YYABORT; + $$.init_using_vars($1); + } + | sp_decl_idents_init_vars + ROW_SYM TYPE_SYM OF_SYM optionally_qualified_column_ident + sp_opt_default + { + if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $5, $6))) + MYSQL_YYABORT; + $$.init_using_vars($1); + } + ; + +sp_param_name_and_type_anchored: + sp_param_name TYPE_SYM OF_SYM ident '.' ident + { + if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, + $$= $1, $4, + $6))) + MYSQL_YYABORT; + } + | sp_param_name TYPE_SYM OF_SYM ident '.' ident '.' ident + { + if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, + $4, $6, $8))) + MYSQL_YYABORT; + } + | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident + { + if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5))) + MYSQL_YYABORT; + } + | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident '.' ident + { + if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5, $7))) + MYSQL_YYABORT; + } + ; + + +sf_c_chistics_and_body_standalone: + sp_c_chistics + { + LEX *lex= thd->lex; + lex->sphead->set_c_chistics(lex->sp_chistics); + lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); + } + sp_proc_stmt_in_returns_clause + { + if (unlikely(Lex->sp_body_finalize_function(thd))) + MYSQL_YYABORT; + } + ; + +sp_tail_standalone: + sp_name + { + if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1, + &sp_handler_procedure, + DEFAULT_AGGREGATE))) + MYSQL_YYABORT; + } + sp_parenthesized_pdparam_list + sp_c_chistics + { + Lex->sphead->set_c_chistics(Lex->sp_chistics); + Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); + } + sp_proc_stmt + { + if (unlikely(Lex->sp_body_finalize_procedure(thd))) + MYSQL_YYABORT; + } + ; + +drop_routine: + DROP FUNCTION_SYM opt_if_exists ident '.' ident + { + if (Lex->stmt_drop_function($3, $4, $6)) + MYSQL_YYABORT; + } + | DROP FUNCTION_SYM opt_if_exists ident + { + if (Lex->stmt_drop_function($3, $4)) + MYSQL_YYABORT; + } + | DROP PROCEDURE_SYM opt_if_exists sp_name + { + if (Lex->stmt_drop_procedure($3, $4)) + MYSQL_YYABORT; + } + ; + + +create_routine: + create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists + { + if (Lex->stmt_create_procedure_start($1 | $4)) + MYSQL_YYABORT; + } + sp_tail_standalone + { + Lex->stmt_create_routine_finalize(); + } + | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists + sp_name + { + if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) + MYSQL_YYABORT; + } + sp_parenthesized_fdparam_list + RETURNS_SYM sf_return_type + sf_c_chistics_and_body_standalone + { + Lex->stmt_create_routine_finalize(); + } + | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists + sp_name + { + if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) + MYSQL_YYABORT; + } + sp_parenthesized_fdparam_list + RETURNS_SYM sf_return_type + sf_c_chistics_and_body_standalone + { + Lex->stmt_create_routine_finalize(); + } + | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists + ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys + { + if (Lex->stmt_create_udf_function($1 | $5, $3, $6, + (Item_result) $8, $10)) + MYSQL_YYABORT; + } + ; + + +sp_decls: + /* Empty */ + { + $$.init(); + } + | sp_decls sp_decl ';' + { + /* We check for declarations out of (standard) order this way + because letting the grammar rules reflect it caused tricky + shift/reduce conflicts with the wrong result. (And we get + better error handling this way.) */ + if (unlikely(Lex->sp_declarations_join(&$$, $1, $2))) + MYSQL_YYABORT; + } + ; + +sp_decl: + DECLARE_MARIADB_SYM sp_decl_body { $$= $2; } + ; + + +sp_decl_body: + sp_decl_variable_list + | sp_decl_ident CONDITION_SYM FOR_SYM sp_cond + { + if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4))) + MYSQL_YYABORT; + $$.vars= $$.hndlrs= $$.curs= 0; + $$.conds= 1; + } + | sp_decl_handler + | sp_decl_ident CURSOR_SYM + { + Lex->sp_block_init(thd); + } + opt_parenthesized_cursor_formal_parameters + FOR_SYM sp_cursor_stmt + { + sp_pcontext *param_ctx= Lex->spcont; + if (unlikely(Lex->sp_block_finalize(thd))) + MYSQL_YYABORT; + if (unlikely(Lex->sp_declare_cursor(thd, &$1, $6, param_ctx, true))) + MYSQL_YYABORT; + $$.vars= $$.conds= $$.hndlrs= 0; + $$.curs= 1; + } + ; + + +/* + ps_proc_stmt_in_returns_clause is a statement that is allowed + in the RETURNS clause of a stored function definition directly, + without the BEGIN..END block. + It should not include any syntax structures starting with '(', to avoid + shift/reduce conflicts with the rule "field_type" and its sub-rules + that scan an optional length, like CHAR(1) or YEAR(4). + See MDEV-9166. +*/ +sp_proc_stmt_in_returns_clause: + sp_proc_stmt_return + | sp_labeled_block + | sp_unlabeled_block + | sp_labeled_control + | sp_proc_stmt_compound_ok + ; + +sp_proc_stmt: + sp_proc_stmt_in_returns_clause + | sp_proc_stmt_statement + | sp_proc_stmt_continue_oracle + | sp_proc_stmt_exit_oracle + | sp_proc_stmt_leave + | sp_proc_stmt_iterate + | sp_proc_stmt_goto_oracle + | sp_proc_stmt_with_cursor + ; + +sp_proc_stmt_compound_ok: + sp_proc_stmt_if + | case_stmt_specification + | sp_unlabeled_block_not_atomic + | sp_unlabeled_control + ; + + +sp_labeled_block: + sp_block_label + BEGIN_MARIADB_SYM + { + Lex->sp_block_init(thd, &$1); + } + sp_decls + sp_proc_stmts + END + sp_opt_label + { + if (unlikely(Lex->sp_block_finalize(thd, $4, &$7))) + MYSQL_YYABORT; + } + ; + +sp_unlabeled_block: + BEGIN_MARIADB_SYM + { + Lex->sp_block_init(thd); + } + sp_decls + sp_proc_stmts + END + { + if (unlikely(Lex->sp_block_finalize(thd, $3))) + MYSQL_YYABORT; + } + ; + +sp_unlabeled_block_not_atomic: + BEGIN_MARIADB_SYM not ATOMIC_SYM /* TODO: BEGIN ATOMIC (not -> opt_not) */ + { + if (unlikely(Lex->maybe_start_compound_statement(thd))) + MYSQL_YYABORT; + Lex->sp_block_init(thd); + } + sp_decls + sp_proc_stmts + END + { + if (unlikely(Lex->sp_block_finalize(thd, $5))) + MYSQL_YYABORT; + } + ; + + +/* End of sql_mode=DEFAULT specific rules */ + /** @} (end of group Parser) */ diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 83691438581..8d55ce76362 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -1234,7 +1234,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); key_cache_name sp_opt_label BIN_NUM TEXT_STRING_filesystem opt_constraint constraint opt_ident - sp_block_label opt_place opt_db + sp_block_label sp_control_label opt_place opt_db %type <ident_sys> IDENT_sys @@ -1244,6 +1244,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); ident_or_empty ident_table_alias ident_sysvar_name + ident_for_loop_index %type <lex_string_with_metadata> TEXT_STRING @@ -1278,6 +1279,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); keyword_verb_clause charset reserved_keyword_udt + reserved_keyword_udt_not_param_type non_reserved_keyword_udt %type <table> @@ -1535,9 +1537,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <select_order> opt_order_clause order_clause order_list %type <NONE> + directly_executable_statement analyze_stmt_command backup backup_statements - query verb_clause create change select select_into - do drop insert replace insert_start stmt_end + query verb_clause create create_routine change select select_into + do drop drop_routine insert replace insert_start stmt_end insert_values update delete truncate rename compound_statement show describe load alter optimize keycache preload flush reset purge begin_stmt_mariadb commit rollback savepoint release @@ -1608,6 +1611,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); opt_constraint_no_id %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt +%type <NONE> sp_if_then_statements sp_case_then_statements %type <NONE> sp_proc_stmt_statement sp_proc_stmt_return %type <NONE> sp_proc_stmt_compound_ok %type <NONE> sp_proc_stmt_if @@ -1618,9 +1622,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <NONE> sp_proc_stmt_leave %type <NONE> sp_proc_stmt_iterate %type <NONE> sp_proc_stmt_goto_oracle +%type <NONE> sp_proc_stmt_with_cursor %type <NONE> sp_proc_stmt_open sp_proc_stmt_fetch sp_proc_stmt_close %type <NONE> case_stmt_specification %type <NONE> loop_body while_body repeat_body +%type <NONE> for_loop_statements %type <num> view_algorithm view_check_option %type <view_suid> view_suid opt_view_suid @@ -1634,11 +1640,12 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value %type <spname> sp_name %type <spvar> sp_param_name sp_param_name_and_type +%type <spvar> sp_param_name_and_type_anchored %type <for_loop> sp_for_loop_index_and_bounds %type <for_loop_bounds> sp_for_loop_bounds %type <trim> trim_operands %type <num> opt_sp_for_loop_direction -%type <spvar_mode> sp_opt_inout +%type <spvar_mode> sp_parameter_type %type <index_hint> index_hint_type %type <num> index_hint_clause normal_join inner_join %type <filetype> data_or_xml @@ -1685,6 +1692,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); /* Start of sql_mode=ORACLE specific declarations */ %type <NONE> set_assign +%type <spvar_mode> sp_opt_inout %type <NONE> sp_tail_standalone %type <NONE> sp_labelable_stmt %type <simple_string> remember_end_opt @@ -1697,7 +1705,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <spname> opt_sp_name %type <spblock> sp_decl_body_list %type <spblock> opt_sp_decl_body_list -%type <spblock> sp_decl_vars +%type <spblock> sp_decl_variable_list +%type <spblock> sp_decl_variable_list_anchored %type <spblock> sp_decl_non_handler %type <spblock> sp_decl_non_handler_list %type <spblock> sp_decl_handler @@ -1752,7 +1761,7 @@ query: thd->lex->sql_command= SQLCOM_EMPTY_QUERY; YYLIP->found_semicolon= NULL; } - | verb_clause + | directly_executable_statement { Lex_input_stream *lip = YYLIP; @@ -1777,7 +1786,7 @@ query: } ';' opt_end_of_input - | verb_clause END_OF_INPUT + | directly_executable_statement END_OF_INPUT { /* Single query, not terminated. */ YYLIP->found_semicolon= NULL; @@ -1789,14 +1798,14 @@ opt_end_of_input: | END_OF_INPUT ; -verb_clause: +directly_executable_statement: statement | begin_stmt_mariadb | compound_statement ; /* Verb clauses, except begin and compound_statement */ -statement: +verb_clause: alter | analyze | analyze_stmt_command @@ -1845,7 +1854,6 @@ statement: | select | select_into | set - | set_assign | signal_stmt | show | shutdown @@ -2379,15 +2387,6 @@ create: { Lex->pop_select(); //main select } - | create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists - { - if (Lex->stmt_create_procedure_start($1 | $4)) - MYSQL_YYABORT; - } - sp_tail_standalone - { - Lex->stmt_create_routine_finalize(); - } | create_or_replace definer_opt EVENT_SYM { if (Lex->main_select_push()) @@ -2398,41 +2397,6 @@ create: { Lex->pop_select(); //main select } - | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists - sp_name - { - if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) - MYSQL_YYABORT; - } - opt_sp_parenthesized_fdparam_list - RETURN_ORACLE_SYM sf_return_type - sf_c_chistics_and_body_standalone - opt_sp_name - { - if (Lex->stmt_create_stored_function_finalize_standalone($12)) - MYSQL_YYABORT; - } - | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists - sp_name - { - if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) - MYSQL_YYABORT; - } - opt_sp_parenthesized_fdparam_list - RETURN_ORACLE_SYM sf_return_type - sf_c_chistics_and_body_standalone - opt_sp_name - { - if (Lex->stmt_create_stored_function_finalize_standalone($12)) - MYSQL_YYABORT; - } - | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists - ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys - { - if (Lex->stmt_create_udf_function($1 | $5, $3, $6, - (Item_result) $8, $10)) - MYSQL_YYABORT; - } | create_or_replace USER_SYM opt_if_not_exists clear_privileges grant_list opt_require_clause opt_resource_options opt_account_locking opt_password_expiration { @@ -2458,251 +2422,9 @@ create: | create_or_replace { Lex->set_command(SQLCOM_CREATE_SERVER, $1); } server_def { } - | create_or_replace definer_opt PACKAGE_ORACLE_SYM - opt_if_not_exists sp_name opt_create_package_chistics_init - sp_tail_is - remember_name - { - sp_package *pkg; - if (unlikely(!(pkg= Lex-> - create_package_start(thd, - SQLCOM_CREATE_PACKAGE, - &sp_handler_package_spec, - $5, $1 | $4)))) - MYSQL_YYABORT; - pkg->set_c_chistics(Lex->sp_chistics); - } - opt_package_specification_element_list END - remember_end_opt opt_sp_name - { - if (unlikely(Lex->create_package_finalize(thd, $5, $13, $8, $12))) - MYSQL_YYABORT; - } - | create_or_replace definer_opt PACKAGE_ORACLE_SYM BODY_ORACLE_SYM - opt_if_not_exists sp_name opt_create_package_chistics_init - sp_tail_is - remember_name - { - sp_package *pkg; - if (unlikely(!(pkg= Lex-> - create_package_start(thd, - SQLCOM_CREATE_PACKAGE_BODY, - &sp_handler_package_body, - $6, $1 | $5)))) - MYSQL_YYABORT; - pkg->set_c_chistics(Lex->sp_chistics); - Lex->sp_block_init(thd); - } - package_implementation_declare_section - { - if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) - MYSQL_YYABORT; - } - package_implementation_executable_section - { - $11.hndlrs+= $13.hndlrs; - if (unlikely(Lex->sp_block_finalize(thd, $11))) - MYSQL_YYABORT; - } - remember_end_opt opt_sp_name - { - if (unlikely(Lex->create_package_finalize(thd, $6, $16, $9, $15))) - MYSQL_YYABORT; - } + | create_routine ; -package_implementation_executable_section: - END - { - if (unlikely(Lex->sp_block_with_exceptions_add_empty(thd))) - MYSQL_YYABORT; - $$.init(0); - } - | BEGIN_ORACLE_SYM sp_block_statements_and_exceptions END { $$= $2; } - ; - -/* - Inside CREATE PACKAGE BODY, package-wide items (e.g. variables) - must be declared before routine definitions. -*/ -package_implementation_declare_section: - package_implementation_declare_section_list1 - | package_implementation_declare_section_list2 - | package_implementation_declare_section_list1 - package_implementation_declare_section_list2 - { $$.join($1, $2); } - ; - -package_implementation_declare_section_list1: - package_implementation_item_declaration - | package_implementation_declare_section_list1 - package_implementation_item_declaration - { $$.join($1, $2); } - ; - -package_implementation_declare_section_list2: - package_implementation_routine_definition - | package_implementation_declare_section_list2 - package_implementation_routine_definition - { $$.join($1, $2); } - ; - -package_routine_lex: - { - if (unlikely(!($$= new (thd->mem_root) - sp_lex_local(thd, thd->lex)))) - MYSQL_YYABORT; - thd->m_parser_state->m_yacc.reset_before_substatement(); - } - ; - - -package_specification_function: - remember_lex package_routine_lex ident - { - DBUG_ASSERT($1->sphead->get_package()); - $2->sql_command= SQLCOM_CREATE_FUNCTION; - sp_name *spname= $1->make_sp_name_package_routine(thd, &$3); - if (unlikely(!spname)) - MYSQL_YYABORT; - thd->lex= $2; - if (unlikely(!$2->make_sp_head_no_recursive(thd, spname, - &sp_handler_package_function, - NOT_AGGREGATE))) - MYSQL_YYABORT; - $1->sphead->get_package()->m_current_routine= $2; - (void) is_native_function_with_warn(thd, &$3); - } - opt_sp_parenthesized_fdparam_list - RETURN_ORACLE_SYM sf_return_type - sp_c_chistics - { - sp_head *sp= thd->lex->sphead; - sp->restore_thd_mem_root(thd); - thd->lex= $1; - $$= $2; - } - ; - -package_specification_procedure: - remember_lex package_routine_lex ident - { - DBUG_ASSERT($1->sphead->get_package()); - $2->sql_command= SQLCOM_CREATE_PROCEDURE; - sp_name *spname= $1->make_sp_name_package_routine(thd, &$3); - if (unlikely(!spname)) - MYSQL_YYABORT; - thd->lex= $2; - if (unlikely(!$2->make_sp_head_no_recursive(thd, spname, - &sp_handler_package_procedure, - DEFAULT_AGGREGATE))) - MYSQL_YYABORT; - $1->sphead->get_package()->m_current_routine= $2; - } - opt_sp_parenthesized_pdparam_list - sp_c_chistics - { - sp_head *sp= thd->lex->sphead; - sp->restore_thd_mem_root(thd); - thd->lex= $1; - $$= $2; - - } - ; - - -package_implementation_routine_definition: - FUNCTION_SYM package_specification_function - package_implementation_function_body ';' - { - sp_package *pkg= Lex->get_sp_package(); - if (unlikely(pkg->add_routine_implementation($2))) - MYSQL_YYABORT; - pkg->m_current_routine= NULL; - $$.init(); - } - | PROCEDURE_SYM package_specification_procedure - package_implementation_procedure_body ';' - { - sp_package *pkg= Lex->get_sp_package(); - if (unlikely(pkg->add_routine_implementation($2))) - MYSQL_YYABORT; - pkg->m_current_routine= NULL; - $$.init(); - } - | package_specification_element { $$.init(); } - ; - - -package_implementation_function_body: - sp_tail_is remember_lex - { - sp_package *pkg= Lex->get_sp_package(); - sp_head *sp= pkg->m_current_routine->sphead; - thd->lex= pkg->m_current_routine; - sp->reset_thd_mem_root(thd); - sp->set_body_start(thd, YYLIP->get_cpp_tok_start()); - } - sp_body opt_package_routine_end_name - { - if (unlikely(thd->lex->sp_body_finalize_function(thd) || - thd->lex->sphead->check_package_routine_end_name($5))) - MYSQL_YYABORT; - thd->lex= $2; - } - ; - -package_implementation_procedure_body: - sp_tail_is remember_lex - { - sp_package *pkg= Lex->get_sp_package(); - sp_head *sp= pkg->m_current_routine->sphead; - thd->lex= pkg->m_current_routine; - sp->reset_thd_mem_root(thd); - sp->set_body_start(thd, YYLIP->get_cpp_tok_start()); - } - sp_body opt_package_routine_end_name - { - if (unlikely(thd->lex->sp_body_finalize_procedure(thd) || - thd->lex->sphead->check_package_routine_end_name($5))) - MYSQL_YYABORT; - thd->lex= $2; - } - ; - - -package_implementation_item_declaration: - sp_decl_vars ';' - ; - -opt_package_specification_element_list: - /* Empty */ - | package_specification_element_list - ; - -package_specification_element_list: - package_specification_element - | package_specification_element_list package_specification_element - ; - -package_specification_element: - FUNCTION_SYM package_specification_function ';' - { - sp_package *pkg= Lex->get_sp_package(); - if (unlikely(pkg->add_routine_declaration($2))) - MYSQL_YYABORT; - pkg->m_current_routine= NULL; - } - | PROCEDURE_SYM package_specification_procedure ';' - { - sp_package *pkg= Lex->get_sp_package(); - if (unlikely(pkg->add_routine_declaration($2))) - MYSQL_YYABORT; - pkg->m_current_routine= NULL; - } - ; - - opt_sequence: /* empty */ { } | sequence_defs @@ -3066,11 +2788,6 @@ sp_name: } ; -opt_sp_name: - /* Empty */ { $$= NULL; } - | sp_name { $$= $1; } - ; - sp_a_chistics: /* Empty */ {} | sp_a_chistics sp_chistic {} @@ -3099,28 +2816,6 @@ sp_chistic: { Lex->sp_chistics.suid= $1; } ; -create_package_chistic: - COMMENT_SYM TEXT_STRING_sys - { Lex->sp_chistics.comment= $2; } - | sp_suid - { Lex->sp_chistics.suid= $1; } - ; - -create_package_chistics: - create_package_chistic {} - | create_package_chistics create_package_chistic { } - ; - -opt_create_package_chistics: - /* Empty */ - | create_package_chistics { } - ; - -opt_create_package_chistics_init: - { Lex->sp_chistics.init(); } - opt_create_package_chistics - ; - /* Create characteristics */ sp_c_chistic: sp_chistic { } @@ -3199,31 +2894,12 @@ sp_param_name_and_type: if (unlikely(Lex->sp_param_fill_definition($$= $1, $2))) MYSQL_YYABORT; } - | sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM - { - if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4))) - MYSQL_YYABORT; - } - | sp_param_name sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM - { - if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4, $6))) - MYSQL_YYABORT; - } - | sp_param_name sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM - { - if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2))) - MYSQL_YYABORT; - } - | sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM - { - if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2, $4))) - MYSQL_YYABORT; - } | sp_param_name ROW_SYM row_type_body { if (unlikely(Lex->sphead->spvar_fill_row(thd, $$= $1, $3))) MYSQL_YYABORT; } + | sp_param_name_and_type_anchored ; /* Stored PROCEDURE parameter declaration list */ @@ -3237,51 +2913,10 @@ sp_pdparams: | sp_pdparam ; -sp_pdparam: - sp_param_name sp_opt_inout type_with_opt_collate - { - $1->mode= $2; - if (unlikely(Lex->sp_param_fill_definition($1, $3))) - MYSQL_YYABORT; - } - | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM - { - $1->mode= $2; - if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5))) - MYSQL_YYABORT; - } - | sp_param_name sp_opt_inout sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM - { - $1->mode= $2; - if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5, $7))) - MYSQL_YYABORT; - } - | sp_param_name sp_opt_inout sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM - { - $1->mode= $2; - if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3))) - MYSQL_YYABORT; - } - | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM - { - $1->mode= $2; - if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3, $5))) - MYSQL_YYABORT; - } - | sp_param_name sp_opt_inout ROW_SYM row_type_body - { - $1->mode= $2; - if (unlikely(Lex->sphead->spvar_fill_row(thd, $1, $4))) - MYSQL_YYABORT; - } - ; - -sp_opt_inout: - /* Empty */ { $$= sp_variable::MODE_IN; } - | IN_SYM { $$= sp_variable::MODE_IN; } +sp_parameter_type: + IN_SYM { $$= sp_variable::MODE_IN; } | OUT_SYM { $$= sp_variable::MODE_OUT; } | INOUT_SYM { $$= sp_variable::MODE_INOUT; } - | IN_SYM OUT_SYM { $$= sp_variable::MODE_INOUT; } ; sp_parenthesized_pdparam_list: @@ -3296,22 +2931,8 @@ sp_parenthesized_pdparam_list: } ; -sp_no_param: - /* Empty */ - { - Lex->sphead->m_param_begin= Lex->sphead->m_param_end= - YYLIP->get_cpp_tok_start() + 1; - } - ; - -opt_sp_parenthesized_fdparam_list: - sp_no_param - | '(' sp_fdparam_list ')' - ; - -opt_sp_parenthesized_pdparam_list: - sp_no_param - | sp_parenthesized_pdparam_list +sp_parenthesized_fdparam_list: + '(' sp_fdparam_list ')' ; sp_proc_stmts: @@ -3324,58 +2945,6 @@ sp_proc_stmts1: | sp_proc_stmts1 sp_proc_stmt ';' ; -sp_proc_stmts1_implicit_block: - { - Lex->sp_block_init(thd); - } - sp_proc_stmts1 - { - if (unlikely(Lex->sp_block_finalize(thd))) - MYSQL_YYABORT; - } - ; - -opt_sp_decl_body_list: - /* Empty */ - { - $$.init(); - } - | sp_decl_body_list { $$= $1; } - ; - -sp_decl_body_list: - sp_decl_non_handler_list - { - if (unlikely(Lex->sphead->sp_add_instr_cpush_for_cursors(thd, Lex->spcont))) - MYSQL_YYABORT; - } - opt_sp_decl_handler_list - { - $$.join($1, $3); - } - | sp_decl_handler_list - ; - -sp_decl_non_handler_list: - sp_decl_non_handler ';' { $$= $1; } - | sp_decl_non_handler_list sp_decl_non_handler ';' - { - $$.join($1, $2); - } - ; - -sp_decl_handler_list: - sp_decl_handler ';' { $$= $1; } - | sp_decl_handler_list sp_decl_handler ';' - { - $$.join($1, $2); - } - ; - -opt_sp_decl_handler_list: - /* Empty*/ { $$.init(); } - | sp_decl_handler_list - ; optionally_qualified_column_ident: sp_decl_ident @@ -3398,13 +2967,6 @@ optionally_qualified_column_ident: } ; -row_field_name: - ident_directly_assignable - { - if (!($$= Lex->row_field_name(thd, $1))) - MYSQL_YYABORT; - } - ; row_field_definition: row_field_name type_with_opt_collate @@ -3438,7 +3000,7 @@ sp_decl_idents_init_vars: } ; -sp_decl_vars: +sp_decl_variable_list: sp_decl_idents_init_vars type_with_opt_collate { @@ -3454,22 +3016,6 @@ sp_decl_vars: $$.init_using_vars($1); } | sp_decl_idents_init_vars - optionally_qualified_column_ident PERCENT_ORACLE_SYM TYPE_SYM - sp_opt_default - { - if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $2, $5))) - MYSQL_YYABORT; - $$.init_using_vars($1); - } - | sp_decl_idents_init_vars - optionally_qualified_column_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM - sp_opt_default - { - if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $2, $5))) - MYSQL_YYABORT; - $$.init_using_vars($1); - } - | sp_decl_idents_init_vars ROW_SYM row_type_body sp_opt_default { @@ -3477,42 +3023,7 @@ sp_decl_vars: MYSQL_YYABORT; $$.init_using_vars($1); } - ; - -sp_decl_non_handler: - sp_decl_vars - | ident_directly_assignable CONDITION_SYM FOR_SYM sp_cond - { - if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4))) - MYSQL_YYABORT; - $$.vars= $$.hndlrs= $$.curs= 0; - $$.conds= 1; - } - | ident_directly_assignable EXCEPTION_ORACLE_SYM - { - sp_condition_value *spcond= new (thd->mem_root) - sp_condition_value_user_defined(); - if (unlikely(!spcond) || - unlikely(Lex->spcont->declare_condition(thd, &$1, spcond))) - MYSQL_YYABORT; - $$.vars= $$.hndlrs= $$.curs= 0; - $$.conds= 1; - } - | CURSOR_SYM ident_directly_assignable - { - Lex->sp_block_init(thd); - } - opt_parenthesized_cursor_formal_parameters - IS sp_cursor_stmt - { - sp_pcontext *param_ctx= Lex->spcont; - if (unlikely(Lex->sp_block_finalize(thd))) - MYSQL_YYABORT; - if (unlikely(Lex->sp_declare_cursor(thd, &$2, $6, param_ctx, false))) - MYSQL_YYABORT; - $$.vars= $$.conds= $$.hndlrs= 0; - $$.curs= 1; - } + | sp_decl_variable_list_anchored ; sp_decl_handler: @@ -3690,18 +3201,8 @@ signal_stmt: signal_value: ident { - LEX *lex= Lex; - sp_condition_value *cond; - - /* SIGNAL foo cannot be used outside of stored programs */ - if (unlikely(lex->spcont == NULL)) - my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str)); - cond= lex->spcont->find_declared_or_predefined_condition(thd, &$1); - if (unlikely(cond == NULL)) - my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str)); - if (unlikely(!cond->has_sql_state())) - my_yyabort_error((ER_SIGNAL_BAD_CONDITION_TYPE, MYF(0))); - $$= cond; + if (!($$= Lex->stmt_signal_value($1))) + MYSQL_YYABORT; } | sqlstate { $$= $1; } @@ -3992,44 +3493,6 @@ sp_decl_idents: } ; -sp_opt_default: - /* Empty */ { $$ = NULL; } - | DEFAULT expr { $$ = $2; } - | SET_VAR expr { $$ = $2; } - ; - -sp_proc_stmt: - sp_labeled_block - | sp_unlabeled_block - | sp_labeled_control - | sp_unlabeled_control - | sp_labelable_stmt - | labels_declaration_oracle sp_labelable_stmt {} - ; - -sp_labelable_stmt: - sp_proc_stmt_statement - | sp_proc_stmt_continue_oracle - | sp_proc_stmt_exit_oracle - | sp_proc_stmt_leave - | sp_proc_stmt_iterate - | sp_proc_stmt_goto_oracle - | sp_proc_stmt_open - | sp_proc_stmt_fetch - | sp_proc_stmt_close - | sp_proc_stmt_return - | sp_proc_stmt_if - | case_stmt_specification - | NULL_SYM { } - ; - -sp_proc_stmt_compound_ok: - sp_proc_stmt_if - | case_stmt_specification - | sp_unlabeled_block - | sp_unlabeled_control - ; - sp_proc_stmt_if: IF_SYM { @@ -4041,25 +3504,6 @@ sp_proc_stmt_if: { Lex->sphead->do_cont_backpatch(); } ; -sp_statement: - statement - | ident_cli_directly_assignable - { - // Direct procedure call (without the CALL keyword) - Lex_ident_sys tmp(thd, &$1); - if (unlikely(Lex->call_statement_start(thd, &tmp))) - MYSQL_YYABORT; - } - opt_sp_cparam_list - | ident_cli_directly_assignable '.' ident - { - Lex_ident_sys tmp(thd, &$1); - if (unlikely(Lex->call_statement_start(thd, &tmp, &$3))) - MYSQL_YYABORT; - } - opt_sp_cparam_list - ; - sp_proc_stmt_statement: { LEX *lex= thd->lex; @@ -4172,13 +3616,6 @@ sp_proc_stmt_goto_oracle: ; -remember_lex: - { - $$= thd->lex; - } - ; - - expr_lex: { DBUG_ASSERT(Lex->sphead); @@ -4262,6 +3699,12 @@ opt_parenthesized_cursor_actual_parameters: | '(' cursor_actual_parameters ')' { $$= $2; } ; +sp_proc_stmt_with_cursor: + sp_proc_stmt_open + | sp_proc_stmt_fetch + | sp_proc_stmt_close + ; + sp_proc_stmt_open: OPEN_SYM ident opt_parenthesized_cursor_actual_parameters { @@ -4352,7 +3795,7 @@ sp_if: if (unlikely($1->sp_if_expr(thd))) MYSQL_YYABORT; } - sp_proc_stmts1_implicit_block + sp_if_then_statements { if (unlikely($1->sp_if_after_statements(thd))) MYSQL_YYABORT; @@ -4367,8 +3810,9 @@ sp_if: sp_elseifs: /* Empty */ + | ELSEIF_MARIADB_SYM sp_if | ELSIF_ORACLE_SYM sp_if - | ELSE sp_proc_stmts1_implicit_block + | ELSE sp_if_then_statements ; case_stmt_specification: @@ -4471,7 +3915,7 @@ simple_when_clause: MYSQL_YYABORT; } THEN_SYM - sp_proc_stmts1_implicit_block + sp_case_then_statements { if (unlikely(Lex->case_stmt_action_then())) MYSQL_YYABORT; @@ -4485,7 +3929,7 @@ searched_when_clause: MYSQL_YYABORT; } THEN_SYM - sp_proc_stmts1_implicit_block + sp_case_then_statements { if (unlikely(Lex->case_stmt_action_then())) MYSQL_YYABORT; @@ -4504,7 +3948,7 @@ else_clause_opt: unlikely(sp->add_instr(i))) MYSQL_YYABORT; } - | ELSE sp_proc_stmts1_implicit_block + | ELSE sp_case_then_statements ; sp_opt_label: @@ -4512,155 +3956,6 @@ sp_opt_label: | label_ident { $$= $1; } ; -sp_block_label: - labels_declaration_oracle - { - if (unlikely(Lex->spcont->block_label_declare(&$1))) - MYSQL_YYABORT; - $$= $1; - } - ; - -sp_labeled_block: - sp_block_label - BEGIN_ORACLE_SYM - { - Lex->sp_block_init(thd, &$1); - if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) - MYSQL_YYABORT; - } - sp_block_statements_and_exceptions - END - sp_opt_label - { - if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4), &$6))) - MYSQL_YYABORT; - } - | sp_block_label - DECLARE_ORACLE_SYM - { - Lex->sp_block_init(thd, &$1); - } - sp_decl_body_list - { - if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) - MYSQL_YYABORT; - } - BEGIN_ORACLE_SYM - sp_block_statements_and_exceptions - END - sp_opt_label - { - $4.hndlrs+= $7.hndlrs; - if (unlikely(Lex->sp_block_finalize(thd, $4, &$9))) - MYSQL_YYABORT; - } - ; - -opt_not_atomic: - /* Empty */ - | not ATOMIC_SYM /* TODO: BEGIN ATOMIC (not -> opt_not) */ - ; - -sp_unlabeled_block: - BEGIN_ORACLE_SYM opt_not_atomic - { - if (unlikely(Lex->maybe_start_compound_statement(thd))) - MYSQL_YYABORT; - Lex->sp_block_init(thd); - if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) - MYSQL_YYABORT; - } - sp_block_statements_and_exceptions - END - { - if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4)))) - MYSQL_YYABORT; - } - | DECLARE_ORACLE_SYM - { - if (unlikely(Lex->maybe_start_compound_statement(thd))) - MYSQL_YYABORT; - Lex->sp_block_init(thd); - } - sp_decl_body_list - { - if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) - MYSQL_YYABORT; - } - BEGIN_ORACLE_SYM - sp_block_statements_and_exceptions - END - { - $3.hndlrs+= $6.hndlrs; - if (unlikely(Lex->sp_block_finalize(thd, $3))) - MYSQL_YYABORT; - } - ; - -sp_instr_addr: - { $$= Lex->sphead->instructions(); } - ; - -sp_body: - { - Lex->sp_block_init(thd); - } - opt_sp_decl_body_list - { - if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) - MYSQL_YYABORT; - } - BEGIN_ORACLE_SYM - sp_block_statements_and_exceptions - { - $2.hndlrs+= $5.hndlrs; - if (unlikely(Lex->sp_block_finalize(thd, $2))) - MYSQL_YYABORT; - } - END - ; - -sp_block_statements_and_exceptions: - sp_instr_addr - sp_proc_stmts - { - if (unlikely(Lex->sp_block_with_exceptions_finalize_executable_section(thd, $1))) - MYSQL_YYABORT; - } - opt_exception_clause - { - if (unlikely(Lex->sp_block_with_exceptions_finalize_exceptions(thd, $1, $4))) - MYSQL_YYABORT; - $$.init($4); - } - ; - -opt_exception_clause: - /* Empty */ { $$= 0; } - | EXCEPTION_ORACLE_SYM exception_handlers { $$= $2; } - ; - -exception_handlers: - exception_handler { $$= 1; } - | exception_handlers exception_handler { $$= $1 + 1; } - ; - -exception_handler: - WHEN_SYM - { - if (unlikely(Lex->sp_handler_declaration_init(thd, sp_handler::EXIT))) - MYSQL_YYABORT; - } - sp_hcond_list - THEN_SYM - sp_proc_stmts1_implicit_block - { - if (unlikely(Lex->sp_handler_declaration_finalize(thd, sp_handler::EXIT))) - MYSQL_YYABORT; - } - ; - /* This adds one shift/reduce conflict */ opt_sp_for_loop_direction: /* Empty */ { $$= 1; } @@ -4668,7 +3963,7 @@ opt_sp_for_loop_direction: ; sp_for_loop_index_and_bounds: - ident_directly_assignable sp_for_loop_bounds + ident_for_loop_index sp_for_loop_bounds { if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $2))) MYSQL_YYABORT; @@ -4710,19 +4005,6 @@ loop_body: } ; -while_body: - expr_lex LOOP_SYM - { - if (unlikely($1->sp_while_loop_expression(thd))) - MYSQL_YYABORT; - } - sp_proc_stmts1 END LOOP_SYM - { - if (unlikely(Lex->sp_while_loop_finalize(thd))) - MYSQL_YYABORT; - } - ; - repeat_body: sp_proc_stmts1 UNTIL_SYM expr_lex END REPEAT_SYM { @@ -4740,21 +4022,21 @@ pop_sp_loop_label: ; sp_labeled_control: - labels_declaration_oracle LOOP_SYM + sp_control_label LOOP_SYM { if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; } loop_body pop_sp_loop_label { } - | labels_declaration_oracle WHILE_SYM + | sp_control_label WHILE_SYM { if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; } while_body pop_sp_loop_label { } - | labels_declaration_oracle FOR_SYM + | sp_control_label FOR_SYM { // See "The FOR LOOP statement" comments in sql_lex.cc Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block @@ -4766,9 +4048,7 @@ sp_labeled_control: if (unlikely(Lex->sp_for_loop_condition_test(thd, $4))) MYSQL_YYABORT; } - LOOP_SYM - sp_proc_stmts1 - END LOOP_SYM + for_loop_statements { if (unlikely(Lex->sp_for_loop_finalize(thd, $4))) MYSQL_YYABORT; @@ -4778,7 +4058,7 @@ sp_labeled_control: if (unlikely(Lex->sp_for_loop_outer_block_finalize(thd, $4))) MYSQL_YYABORT; } - | labels_declaration_oracle REPEAT_SYM + | sp_control_label REPEAT_SYM { if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; @@ -4820,9 +4100,7 @@ sp_unlabeled_control: if (unlikely(Lex->sp_for_loop_condition_test(thd, $3))) MYSQL_YYABORT; } - LOOP_SYM - sp_proc_stmts1 - END LOOP_SYM + for_loop_statements { if (unlikely(Lex->sp_for_loop_finalize(thd, $3))) MYSQL_YYABORT; @@ -9387,8 +8665,7 @@ query_expression_body: { if (!($$= Lex->add_primary_to_query_expression_body($1, $4, $2.unit_type, - $2.distinct, - TRUE))) + $2.distinct))) MYSQL_YYABORT; } | query_expression_body_ext_parens @@ -9743,15 +9020,6 @@ remember_end: } ; -remember_end_opt: - { - if (yychar == YYEMPTY) - $$= (char*) YYLIP->get_cpp_ptr_rtrim(); - else - $$= (char*) YYLIP->get_cpp_tok_end_rtrim(); - } - ; - select_alias: /* empty */ { $$=null_clex_str;} | AS ident { $$=$2; } @@ -13251,37 +12519,6 @@ drop: lex->set_command(SQLCOM_DROP_DB, $3); lex->name= $4; } - | DROP PACKAGE_ORACLE_SYM opt_if_exists sp_name - { - LEX *lex= Lex; - lex->set_command(SQLCOM_DROP_PACKAGE, $3); - if (unlikely(lex->sphead)) - my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE")); - lex->spname= $4; - } - | DROP PACKAGE_ORACLE_SYM BODY_ORACLE_SYM opt_if_exists sp_name - { - LEX *lex= Lex; - lex->set_command(SQLCOM_DROP_PACKAGE_BODY, $4); - if (unlikely(lex->sphead)) - my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE BODY")); - lex->spname= $5; - } - | DROP FUNCTION_SYM opt_if_exists ident '.' ident - { - if (Lex->stmt_drop_function($3, $4, $6)) - MYSQL_YYABORT; - } - | DROP FUNCTION_SYM opt_if_exists ident - { - if (Lex->stmt_drop_function($3, $4)) - MYSQL_YYABORT; - } - | DROP PROCEDURE_SYM opt_if_exists sp_name - { - if (Lex->stmt_drop_procedure($3, $4)) - MYSQL_YYABORT; - } | DROP USER_SYM opt_if_exists clear_privileges user_list { Lex->set_command(SQLCOM_DROP_USER, $3); @@ -13336,6 +12573,7 @@ drop: } table_list {} + | drop_routine ; table_list: @@ -13980,12 +13218,6 @@ truncate: opt_truncate_table_storage_clause { } ; -opt_truncate_table_storage_clause: - /* Empty */ - | DROP STORAGE_SYM - | REUSE_SYM STORAGE_SYM - ; - opt_table_sym: /* empty */ | TABLE_SYM @@ -14341,12 +13573,24 @@ show_param: lex->sql_command = SQLCOM_SHOW_CREATE_FUNC; lex->spname= $3; } + | CREATE PACKAGE_MARIADB_SYM sp_name + { + LEX *lex= Lex; + lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE; + lex->spname= $3; + } | CREATE PACKAGE_ORACLE_SYM sp_name { LEX *lex= Lex; lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE; lex->spname= $3; } + | CREATE PACKAGE_MARIADB_SYM BODY_MARIADB_SYM sp_name + { + LEX *lex= Lex; + lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE_BODY; + lex->spname= $4; + } | CREATE PACKAGE_ORACLE_SYM BODY_ORACLE_SYM sp_name { LEX *lex= Lex; @@ -14386,6 +13630,13 @@ show_param: if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) MYSQL_YYABORT; } + | PACKAGE_MARIADB_SYM STATUS_SYM wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE; + if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) + MYSQL_YYABORT; + } | PACKAGE_ORACLE_SYM STATUS_SYM wild_and_where { LEX *lex= Lex; @@ -14393,6 +13644,13 @@ show_param: if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) MYSQL_YYABORT; } + | PACKAGE_MARIADB_SYM BODY_MARIADB_SYM STATUS_SYM wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE_BODY; + if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES))) + MYSQL_YYABORT; + } | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM STATUS_SYM wild_and_where { LEX *lex= Lex; @@ -14410,6 +13668,11 @@ show_param: Lex->sql_command= SQLCOM_SHOW_FUNC_CODE; Lex->spname= $3; } + | PACKAGE_MARIADB_SYM BODY_MARIADB_SYM CODE_SYM sp_name + { + Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE; + Lex->spname= $4; + } | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM CODE_SYM sp_name { Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE; @@ -15701,22 +14964,6 @@ ident: } ; -ident_directly_assignable: - IDENT_sys - | keyword_directly_assignable - { - if (unlikely($$.copy_keyword(thd, &$1))) - MYSQL_YYABORT; - } - ; - - -ident_cli_directly_assignable: - IDENT_cli - | keyword_directly_assignable { $$= $1; } - ; - - label_ident: IDENT_sys | keyword_label @@ -15726,20 +14973,6 @@ label_ident: } ; -labels_declaration_oracle: - label_declaration_oracle { $$= $1; } - | labels_declaration_oracle label_declaration_oracle { $$= $2; } - ; - -label_declaration_oracle: - SHIFT_LEFT label_ident SHIFT_RIGHT - { - if (unlikely(Lex->sp_push_goto_label(thd, &$2))) - MYSQL_YYABORT; - $$= $2; - } - ; - ident_or_text: ident { $$=$1;} | TEXT_STRING_sys { $$=$1;} @@ -15837,20 +15070,6 @@ keyword_ident: | EXCEPTION_ORACLE_SYM ; -/* - Keywords that we allow for labels in SPs. - Should not include keywords that start a statement or SP characteristics. -*/ -keyword_label: - keyword_data_type - | keyword_set_special_case - | keyword_sp_var_and_label - | keyword_sysvar_type - | FUNCTION_SYM - | COMPRESSED_SYM - | EXCEPTION_ORACLE_SYM - ; - keyword_sysvar_name: keyword_data_type | keyword_cast_type @@ -15865,16 +15084,6 @@ keyword_sysvar_name: | EXCEPTION_ORACLE_SYM ; -keyword_sp_decl: - keyword_sp_head - | keyword_set_special_case - | keyword_sp_var_and_label - | keyword_sp_var_not_label - | keyword_sysvar_type - | keyword_verb_clause - | WINDOW_SYM - ; - keyword_set_usual_case: keyword_data_type | keyword_cast_type @@ -15889,17 +15098,6 @@ keyword_set_usual_case: | EXCEPTION_ORACLE_SYM ; -keyword_directly_assignable: - keyword_data_type - | keyword_cast_type - | keyword_set_special_case - | keyword_sp_var_and_label - | keyword_sp_var_not_label - | keyword_sysvar_type - | FUNCTION_SYM - | WINDOW_SYM - ; - non_reserved_keyword_udt: keyword_sp_var_not_label | keyword_sp_head @@ -16048,14 +15246,6 @@ keyword_set_special_case: | PASSWORD_SYM ; -/* - Keywords that start an SP block section. -*/ -keyword_sp_block_section: - BEGIN_ORACLE_SYM - | END - ; - keyword_sysvar_type: GLOBAL_SYM | LOCAL_SYM @@ -16429,7 +15619,7 @@ keyword_sp_var_and_label: ; -reserved_keyword_udt: +reserved_keyword_udt_not_param_type: ACCESSIBLE_SYM | ADD | ALL @@ -16717,62 +15907,7 @@ set_param: if (Lex->check_main_unit_semantics()) MYSQL_YYABORT; } - FOR_SYM verb_clause - ; - -set_assign: - ident_cli_directly_assignable SET_VAR - { - LEX *lex=Lex; - lex->set_stmt_init(); - if (sp_create_assignment_lex(thd, $1.pos())) - MYSQL_YYABORT; - } - set_expr_or_default - { - Lex_ident_sys tmp(thd, &$1); - if (unlikely(Lex->set_variable(&tmp, $4)) || - unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY, - false))) - MYSQL_YYABORT; - } - | ident_cli_directly_assignable '.' ident SET_VAR - { - LEX *lex=Lex; - lex->set_stmt_init(); - if (sp_create_assignment_lex(thd, $1.pos())) - MYSQL_YYABORT; - } - set_expr_or_default - { - LEX *lex= Lex; - DBUG_ASSERT(lex->var_list.is_empty()); - Lex_ident_sys tmp(thd, &$1); - if (unlikely(lex->set_variable(&tmp, &$3, $6)) || - unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY, - false))) - MYSQL_YYABORT; - } - | COLON_ORACLE_SYM ident '.' ident SET_VAR - { - LEX *lex= Lex; - if (unlikely(!lex->is_trigger_new_or_old_reference(&$2))) - { - thd->parse_error(ER_SYNTAX_ERROR, $1.pos()); - MYSQL_YYABORT; - } - lex->set_stmt_init(); - if (sp_create_assignment_lex(thd, $1.pos())) - MYSQL_YYABORT; - } - set_expr_or_default - { - LEX_CSTRING tmp= { $2.str, $2.length }; - if (unlikely(Lex->set_trigger_field(&tmp, &$4, $7)) || - unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY, - false))) - MYSQL_YYABORT; - } + FOR_SYM directly_executable_statement ; set_stmt_option_list: @@ -18329,54 +17464,6 @@ sf_return_type: } ; -sf_c_chistics_and_body_standalone: - sp_c_chistics - { - LEX *lex= thd->lex; - lex->sphead->set_c_chistics(lex->sp_chistics); - lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); - } - sp_tail_is - sp_body - { - if (unlikely(Lex->sp_body_finalize_function(thd))) - MYSQL_YYABORT; - } - ; - -sp_tail_standalone: - sp_name - { - if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1, - &sp_handler_procedure, - DEFAULT_AGGREGATE))) - MYSQL_YYABORT; - } - opt_sp_parenthesized_pdparam_list - sp_c_chistics - { - Lex->sphead->set_c_chistics(Lex->sp_chistics); - Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); - } - sp_tail_is - sp_body - opt_sp_name - { - if (unlikely(Lex->sp_body_finalize_procedure_standalone(thd, $8))) - MYSQL_YYABORT; - } - ; - - -opt_package_routine_end_name: - /* Empty */ { $$= null_clex_str; } - | ident { $$= $1; } - ; - -sp_tail_is: - IS - | AS - ; /*************************************************************************/ @@ -18512,6 +17599,1015 @@ keep_gcc_happy: } ; +/* Start of sql_mode=ORACLE specific rules */ + +statement: + verb_clause + | set_assign + ; + +sp_statement: + statement + | ident_cli_directly_assignable + { + // Direct procedure call (without the CALL keyword) + Lex_ident_sys tmp(thd, &$1); + if (unlikely(Lex->call_statement_start(thd, &tmp))) + MYSQL_YYABORT; + } + opt_sp_cparam_list + | ident_cli_directly_assignable '.' ident + { + Lex_ident_sys tmp(thd, &$1); + if (unlikely(Lex->call_statement_start(thd, &tmp, &$3))) + MYSQL_YYABORT; + } + opt_sp_cparam_list + ; + +sp_if_then_statements: + sp_proc_stmts1_implicit_block { } + ; + +sp_case_then_statements: + sp_proc_stmts1_implicit_block { } + ; + +reserved_keyword_udt: + reserved_keyword_udt_not_param_type + ; + +/* Keywords that start an SP block section. */ +keyword_sp_block_section: + BEGIN_ORACLE_SYM + | END + ; + +/* + Keywords that we allow for labels in SPs. + Should not include keywords that start a statement or SP characteristics. +*/ +keyword_label: + keyword_data_type + | keyword_set_special_case + | keyword_sp_var_and_label + | keyword_sysvar_type + | FUNCTION_SYM + | COMPRESSED_SYM + | EXCEPTION_ORACLE_SYM + ; + +keyword_sp_decl: + keyword_sp_head + | keyword_set_special_case + | keyword_sp_var_and_label + | keyword_sp_var_not_label + | keyword_sysvar_type + | keyword_verb_clause + | WINDOW_SYM + ; + +opt_truncate_table_storage_clause: + /* Empty */ + | DROP STORAGE_SYM + | REUSE_SYM STORAGE_SYM + ; + + +ident_for_loop_index: + ident_directly_assignable + ; + +row_field_name: + ident_directly_assignable + { + if (!($$= Lex->row_field_name(thd, $1))) + MYSQL_YYABORT; + } + ; + +while_body: + expr_lex LOOP_SYM + { + if (unlikely($1->sp_while_loop_expression(thd))) + MYSQL_YYABORT; + } + sp_proc_stmts1 END LOOP_SYM + { + if (unlikely(Lex->sp_while_loop_finalize(thd))) + MYSQL_YYABORT; + } + ; + +for_loop_statements: + LOOP_SYM sp_proc_stmts1 END LOOP_SYM + { } + ; + + +sp_control_label: + labels_declaration_oracle + ; + +sp_block_label: + labels_declaration_oracle + { + if (unlikely(Lex->spcont->block_label_declare(&$1))) + MYSQL_YYABORT; + $$= $1; + } + ; + + +remember_end_opt: + { + if (yychar == YYEMPTY) + $$= (char*) YYLIP->get_cpp_ptr_rtrim(); + else + $$= (char*) YYLIP->get_cpp_tok_end_rtrim(); + } + ; + +sp_opt_default: + /* Empty */ { $$ = NULL; } + | DEFAULT expr { $$ = $2; } + | SET_VAR expr { $$ = $2; } + ; + +sp_opt_inout: + /*Empty*/ { $$= sp_variable::MODE_IN; } + | sp_parameter_type + | IN_SYM OUT_SYM { $$= sp_variable::MODE_INOUT; } + ; + +sp_pdparam: + sp_param_name sp_opt_inout type_with_opt_collate + { + $1->mode= $2; + if (unlikely(Lex->sp_param_fill_definition($1, $3))) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM + { + $1->mode= $2; + if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5))) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM + { + $1->mode= $2; + if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5, $7))) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM + { + $1->mode= $2; + if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3))) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM + { + $1->mode= $2; + if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3, $5))) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout ROW_SYM row_type_body + { + $1->mode= $2; + if (unlikely(Lex->sphead->spvar_fill_row(thd, $1, $4))) + MYSQL_YYABORT; + } + ; + + +sp_proc_stmts1_implicit_block: + { + Lex->sp_block_init(thd); + } + sp_proc_stmts1 + { + if (unlikely(Lex->sp_block_finalize(thd))) + MYSQL_YYABORT; + } + ; + + +remember_lex: + { + $$= thd->lex; + } + ; + +keyword_directly_assignable: + keyword_data_type + | keyword_cast_type + | keyword_set_special_case + | keyword_sp_var_and_label + | keyword_sp_var_not_label + | keyword_sysvar_type + | FUNCTION_SYM + | WINDOW_SYM + ; + +ident_directly_assignable: + IDENT_sys + | keyword_directly_assignable + { + if (unlikely($$.copy_keyword(thd, &$1))) + MYSQL_YYABORT; + } + ; + +ident_cli_directly_assignable: + IDENT_cli + | keyword_directly_assignable { $$= $1; } + ; + + +set_assign: + ident_cli_directly_assignable SET_VAR + { + LEX *lex=Lex; + lex->set_stmt_init(); + if (sp_create_assignment_lex(thd, $1.pos())) + MYSQL_YYABORT; + } + set_expr_or_default + { + Lex_ident_sys tmp(thd, &$1); + if (unlikely(Lex->set_variable(&tmp, $4)) || + unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY, + false))) + MYSQL_YYABORT; + } + | ident_cli_directly_assignable '.' ident SET_VAR + { + LEX *lex=Lex; + lex->set_stmt_init(); + if (sp_create_assignment_lex(thd, $1.pos())) + MYSQL_YYABORT; + } + set_expr_or_default + { + LEX *lex= Lex; + DBUG_ASSERT(lex->var_list.is_empty()); + Lex_ident_sys tmp(thd, &$1); + if (unlikely(lex->set_variable(&tmp, &$3, $6)) || + unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY, + false))) + MYSQL_YYABORT; + } + | COLON_ORACLE_SYM ident '.' ident SET_VAR + { + LEX *lex= Lex; + if (unlikely(!lex->is_trigger_new_or_old_reference(&$2))) + { + thd->parse_error(ER_SYNTAX_ERROR, $1.pos()); + MYSQL_YYABORT; + } + lex->set_stmt_init(); + if (sp_create_assignment_lex(thd, $1.pos())) + MYSQL_YYABORT; + } + set_expr_or_default + { + LEX_CSTRING tmp= { $2.str, $2.length }; + if (unlikely(Lex->set_trigger_field(&tmp, &$4, $7)) || + unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY, + false))) + MYSQL_YYABORT; + } + ; + + +labels_declaration_oracle: + label_declaration_oracle { $$= $1; } + | labels_declaration_oracle label_declaration_oracle { $$= $2; } + ; + +label_declaration_oracle: + SHIFT_LEFT label_ident SHIFT_RIGHT + { + if (unlikely(Lex->sp_push_goto_label(thd, &$2))) + MYSQL_YYABORT; + $$= $2; + } + ; + +opt_exception_clause: + /* Empty */ { $$= 0; } + | EXCEPTION_ORACLE_SYM exception_handlers { $$= $2; } + ; + +exception_handlers: + exception_handler { $$= 1; } + | exception_handlers exception_handler { $$= $1 + 1; } + ; + +exception_handler: + WHEN_SYM + { + if (unlikely(Lex->sp_handler_declaration_init(thd, sp_handler::EXIT))) + MYSQL_YYABORT; + } + sp_hcond_list + THEN_SYM + sp_proc_stmts1_implicit_block + { + if (unlikely(Lex->sp_handler_declaration_finalize(thd, sp_handler::EXIT))) + MYSQL_YYABORT; + } + ; + +sp_no_param: + /* Empty */ + { + Lex->sphead->m_param_begin= Lex->sphead->m_param_end= + YYLIP->get_cpp_tok_start() + 1; + } + ; + +opt_sp_parenthesized_fdparam_list: + sp_no_param + | sp_parenthesized_fdparam_list + ; + +opt_sp_parenthesized_pdparam_list: + sp_no_param + | sp_parenthesized_pdparam_list + ; + + +opt_sp_name: + /* Empty */ { $$= NULL; } + | sp_name { $$= $1; } + ; + + +opt_package_routine_end_name: + /* Empty */ { $$= null_clex_str; } + | ident { $$= $1; } + ; + +sp_tail_is: + IS + | AS + ; + +sp_instr_addr: + { $$= Lex->sphead->instructions(); } + ; + +sp_body: + { + Lex->sp_block_init(thd); + } + opt_sp_decl_body_list + { + if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) + MYSQL_YYABORT; + } + BEGIN_ORACLE_SYM + sp_block_statements_and_exceptions + { + $2.hndlrs+= $5.hndlrs; + if (unlikely(Lex->sp_block_finalize(thd, $2))) + MYSQL_YYABORT; + } + END + ; + +create_package_chistic: + COMMENT_SYM TEXT_STRING_sys + { Lex->sp_chistics.comment= $2; } + | sp_suid + { Lex->sp_chistics.suid= $1; } + ; + +create_package_chistics: + create_package_chistic {} + | create_package_chistics create_package_chistic { } + ; + +opt_create_package_chistics: + /* Empty */ + | create_package_chistics { } + ; + +opt_create_package_chistics_init: + { Lex->sp_chistics.init(); } + opt_create_package_chistics + ; + + +package_implementation_executable_section: + END + { + if (unlikely(Lex->sp_block_with_exceptions_add_empty(thd))) + MYSQL_YYABORT; + $$.init(0); + } + | BEGIN_ORACLE_SYM sp_block_statements_and_exceptions END { $$= $2; } + ; + +/* + Inside CREATE PACKAGE BODY, package-wide items (e.g. variables) + must be declared before routine definitions. +*/ +package_implementation_declare_section: + package_implementation_declare_section_list1 + | package_implementation_declare_section_list2 + | package_implementation_declare_section_list1 + package_implementation_declare_section_list2 + { $$.join($1, $2); } + ; + +package_implementation_declare_section_list1: + package_implementation_item_declaration + | package_implementation_declare_section_list1 + package_implementation_item_declaration + { $$.join($1, $2); } + ; + +package_implementation_declare_section_list2: + package_implementation_routine_definition + | package_implementation_declare_section_list2 + package_implementation_routine_definition + { $$.join($1, $2); } + ; + +package_routine_lex: + { + if (unlikely(!($$= new (thd->mem_root) + sp_lex_local(thd, thd->lex)))) + MYSQL_YYABORT; + thd->m_parser_state->m_yacc.reset_before_substatement(); + } + ; + + +package_specification_function: + remember_lex package_routine_lex ident + { + DBUG_ASSERT($1->sphead->get_package()); + $2->sql_command= SQLCOM_CREATE_FUNCTION; + sp_name *spname= $1->make_sp_name_package_routine(thd, &$3); + if (unlikely(!spname)) + MYSQL_YYABORT; + thd->lex= $2; + if (unlikely(!$2->make_sp_head_no_recursive(thd, spname, + &sp_handler_package_function, + NOT_AGGREGATE))) + MYSQL_YYABORT; + $1->sphead->get_package()->m_current_routine= $2; + (void) is_native_function_with_warn(thd, &$3); + } + opt_sp_parenthesized_fdparam_list + RETURN_ORACLE_SYM sf_return_type + sp_c_chistics + { + sp_head *sp= thd->lex->sphead; + sp->restore_thd_mem_root(thd); + thd->lex= $1; + $$= $2; + } + ; + +package_specification_procedure: + remember_lex package_routine_lex ident + { + DBUG_ASSERT($1->sphead->get_package()); + $2->sql_command= SQLCOM_CREATE_PROCEDURE; + sp_name *spname= $1->make_sp_name_package_routine(thd, &$3); + if (unlikely(!spname)) + MYSQL_YYABORT; + thd->lex= $2; + if (unlikely(!$2->make_sp_head_no_recursive(thd, spname, + &sp_handler_package_procedure, + DEFAULT_AGGREGATE))) + MYSQL_YYABORT; + $1->sphead->get_package()->m_current_routine= $2; + } + opt_sp_parenthesized_pdparam_list + sp_c_chistics + { + sp_head *sp= thd->lex->sphead; + sp->restore_thd_mem_root(thd); + thd->lex= $1; + $$= $2; + } + ; + + +package_implementation_routine_definition: + FUNCTION_SYM package_specification_function + package_implementation_function_body ';' + { + sp_package *pkg= Lex->get_sp_package(); + if (unlikely(pkg->add_routine_implementation($2))) + MYSQL_YYABORT; + pkg->m_current_routine= NULL; + $$.init(); + } + | PROCEDURE_SYM package_specification_procedure + package_implementation_procedure_body ';' + { + sp_package *pkg= Lex->get_sp_package(); + if (unlikely(pkg->add_routine_implementation($2))) + MYSQL_YYABORT; + pkg->m_current_routine= NULL; + $$.init(); + } + | package_specification_element { $$.init(); } + ; + + +package_implementation_function_body: + sp_tail_is remember_lex + { + sp_package *pkg= Lex->get_sp_package(); + sp_head *sp= pkg->m_current_routine->sphead; + thd->lex= pkg->m_current_routine; + sp->reset_thd_mem_root(thd); + sp->set_body_start(thd, YYLIP->get_cpp_tok_start()); + } + sp_body opt_package_routine_end_name + { + if (unlikely(thd->lex->sp_body_finalize_function(thd) || + thd->lex->sphead->check_package_routine_end_name($5))) + MYSQL_YYABORT; + thd->lex= $2; + } + ; + +package_implementation_procedure_body: + sp_tail_is remember_lex + { + sp_package *pkg= Lex->get_sp_package(); + sp_head *sp= pkg->m_current_routine->sphead; + thd->lex= pkg->m_current_routine; + sp->reset_thd_mem_root(thd); + sp->set_body_start(thd, YYLIP->get_cpp_tok_start()); + } + sp_body opt_package_routine_end_name + { + if (unlikely(thd->lex->sp_body_finalize_procedure(thd) || + thd->lex->sphead->check_package_routine_end_name($5))) + MYSQL_YYABORT; + thd->lex= $2; + } + ; + + +package_implementation_item_declaration: + sp_decl_variable_list ';' + ; + +opt_package_specification_element_list: + /* Empty */ + | package_specification_element_list + ; + +package_specification_element_list: + package_specification_element + | package_specification_element_list package_specification_element + ; + +package_specification_element: + FUNCTION_SYM package_specification_function ';' + { + sp_package *pkg= Lex->get_sp_package(); + if (unlikely(pkg->add_routine_declaration($2))) + MYSQL_YYABORT; + pkg->m_current_routine= NULL; + } + | PROCEDURE_SYM package_specification_procedure ';' + { + sp_package *pkg= Lex->get_sp_package(); + if (unlikely(pkg->add_routine_declaration($2))) + MYSQL_YYABORT; + pkg->m_current_routine= NULL; + } + ; + +sp_decl_variable_list_anchored: + sp_decl_idents_init_vars + optionally_qualified_column_ident PERCENT_ORACLE_SYM TYPE_SYM + sp_opt_default + { + if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $2, $5))) + MYSQL_YYABORT; + $$.init_using_vars($1); + } + | sp_decl_idents_init_vars + optionally_qualified_column_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM + sp_opt_default + { + if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $2, $5))) + MYSQL_YYABORT; + $$.init_using_vars($1); + } + ; + +sp_param_name_and_type_anchored: + sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM + { + if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4))) + MYSQL_YYABORT; + } + | sp_param_name sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM + { + if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4, $6))) + MYSQL_YYABORT; + } + | sp_param_name sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM + { + if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2))) + MYSQL_YYABORT; + } + | sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM + { + if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2, $4))) + MYSQL_YYABORT; + } + ; + + +sf_c_chistics_and_body_standalone: + sp_c_chistics + { + LEX *lex= thd->lex; + lex->sphead->set_c_chistics(lex->sp_chistics); + lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); + } + sp_tail_is + sp_body + { + if (unlikely(Lex->sp_body_finalize_function(thd))) + MYSQL_YYABORT; + } + ; + +sp_tail_standalone: + sp_name + { + if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1, + &sp_handler_procedure, + DEFAULT_AGGREGATE))) + MYSQL_YYABORT; + } + opt_sp_parenthesized_pdparam_list + sp_c_chistics + { + Lex->sphead->set_c_chistics(Lex->sp_chistics); + Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); + } + sp_tail_is + sp_body + opt_sp_name + { + if (unlikely(Lex->sp_body_finalize_procedure_standalone(thd, $8))) + MYSQL_YYABORT; + } + ; + +drop_routine: + DROP FUNCTION_SYM opt_if_exists ident '.' ident + { + if (Lex->stmt_drop_function($3, $4, $6)) + MYSQL_YYABORT; + } + | DROP FUNCTION_SYM opt_if_exists ident + { + if (Lex->stmt_drop_function($3, $4)) + MYSQL_YYABORT; + } + | DROP PROCEDURE_SYM opt_if_exists sp_name + { + if (Lex->stmt_drop_procedure($3, $4)) + MYSQL_YYABORT; + } + | DROP PACKAGE_ORACLE_SYM opt_if_exists sp_name + { + LEX *lex= Lex; + lex->set_command(SQLCOM_DROP_PACKAGE, $3); + if (unlikely(lex->sphead)) + my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE")); + lex->spname= $4; + } + | DROP PACKAGE_ORACLE_SYM BODY_ORACLE_SYM opt_if_exists sp_name + { + LEX *lex= Lex; + lex->set_command(SQLCOM_DROP_PACKAGE_BODY, $4); + if (unlikely(lex->sphead)) + my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE BODY")); + lex->spname= $5; + } + ; + + +create_routine: + create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists + { + if (Lex->stmt_create_procedure_start($1 | $4)) + MYSQL_YYABORT; + } + sp_tail_standalone + { + Lex->stmt_create_routine_finalize(); + } + | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists + sp_name + { + if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) + MYSQL_YYABORT; + } + opt_sp_parenthesized_fdparam_list + RETURN_ORACLE_SYM sf_return_type + sf_c_chistics_and_body_standalone + opt_sp_name + { + if (Lex->stmt_create_stored_function_finalize_standalone($12)) + MYSQL_YYABORT; + } + | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists + sp_name + { + if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6)) + MYSQL_YYABORT; + } + opt_sp_parenthesized_fdparam_list + RETURN_ORACLE_SYM sf_return_type + sf_c_chistics_and_body_standalone + opt_sp_name + { + if (Lex->stmt_create_stored_function_finalize_standalone($12)) + MYSQL_YYABORT; + } + | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists + ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys + { + if (Lex->stmt_create_udf_function($1 | $5, $3, $6, + (Item_result) $8, $10)) + MYSQL_YYABORT; + } + | create_or_replace definer_opt PACKAGE_ORACLE_SYM + opt_if_not_exists sp_name opt_create_package_chistics_init + sp_tail_is + remember_name + { + sp_package *pkg; + if (unlikely(!(pkg= Lex-> + create_package_start(thd, + SQLCOM_CREATE_PACKAGE, + &sp_handler_package_spec, + $5, $1 | $4)))) + MYSQL_YYABORT; + pkg->set_c_chistics(Lex->sp_chistics); + } + opt_package_specification_element_list END + remember_end_opt opt_sp_name + { + if (unlikely(Lex->create_package_finalize(thd, $5, $13, $8, $12))) + MYSQL_YYABORT; + } + | create_or_replace definer_opt PACKAGE_ORACLE_SYM BODY_ORACLE_SYM + opt_if_not_exists sp_name opt_create_package_chistics_init + sp_tail_is + remember_name + { + sp_package *pkg; + if (unlikely(!(pkg= Lex-> + create_package_start(thd, + SQLCOM_CREATE_PACKAGE_BODY, + &sp_handler_package_body, + $6, $1 | $5)))) + MYSQL_YYABORT; + pkg->set_c_chistics(Lex->sp_chistics); + Lex->sp_block_init(thd); + } + package_implementation_declare_section + { + if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) + MYSQL_YYABORT; + } + package_implementation_executable_section + { + $11.hndlrs+= $13.hndlrs; + if (unlikely(Lex->sp_block_finalize(thd, $11))) + MYSQL_YYABORT; + } + remember_end_opt opt_sp_name + { + if (unlikely(Lex->create_package_finalize(thd, $6, $16, $9, $15))) + MYSQL_YYABORT; + } + ; + +opt_sp_decl_body_list: + /* Empty */ + { + $$.init(); + } + | sp_decl_body_list { $$= $1; } + ; + +sp_decl_body_list: + sp_decl_non_handler_list + { + if (unlikely(Lex->sphead->sp_add_instr_cpush_for_cursors(thd, Lex->spcont))) + MYSQL_YYABORT; + } + opt_sp_decl_handler_list + { + $$.join($1, $3); + } + | sp_decl_handler_list + ; + +sp_decl_non_handler_list: + sp_decl_non_handler ';' { $$= $1; } + | sp_decl_non_handler_list sp_decl_non_handler ';' + { + $$.join($1, $2); + } + ; + +sp_decl_handler_list: + sp_decl_handler ';' { $$= $1; } + | sp_decl_handler_list sp_decl_handler ';' + { + $$.join($1, $2); + } + ; + +opt_sp_decl_handler_list: + /* Empty*/ { $$.init(); } + | sp_decl_handler_list + ; + +sp_decl_non_handler: + sp_decl_variable_list + | ident_directly_assignable CONDITION_SYM FOR_SYM sp_cond + { + if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4))) + MYSQL_YYABORT; + $$.vars= $$.hndlrs= $$.curs= 0; + $$.conds= 1; + } + | ident_directly_assignable EXCEPTION_ORACLE_SYM + { + sp_condition_value *spcond= new (thd->mem_root) + sp_condition_value_user_defined(); + if (unlikely(!spcond) || + unlikely(Lex->spcont->declare_condition(thd, &$1, spcond))) + MYSQL_YYABORT; + $$.vars= $$.hndlrs= $$.curs= 0; + $$.conds= 1; + } + | CURSOR_SYM ident_directly_assignable + { + Lex->sp_block_init(thd); + } + opt_parenthesized_cursor_formal_parameters + IS sp_cursor_stmt + { + sp_pcontext *param_ctx= Lex->spcont; + if (unlikely(Lex->sp_block_finalize(thd))) + MYSQL_YYABORT; + if (unlikely(Lex->sp_declare_cursor(thd, &$2, $6, param_ctx, false))) + MYSQL_YYABORT; + $$.vars= $$.conds= $$.hndlrs= 0; + $$.curs= 1; + } + ; + + +sp_proc_stmt: + sp_labeled_block + | sp_unlabeled_block + | sp_labeled_control + | sp_unlabeled_control + | sp_labelable_stmt + | labels_declaration_oracle sp_labelable_stmt {} + ; + +sp_labelable_stmt: + sp_proc_stmt_statement + | sp_proc_stmt_continue_oracle + | sp_proc_stmt_exit_oracle + | sp_proc_stmt_leave + | sp_proc_stmt_iterate + | sp_proc_stmt_goto_oracle + | sp_proc_stmt_with_cursor + | sp_proc_stmt_return + | sp_proc_stmt_if + | case_stmt_specification + | NULL_SYM { } + ; + +sp_proc_stmt_compound_ok: + sp_proc_stmt_if + | case_stmt_specification + | sp_unlabeled_block + | sp_unlabeled_control + ; + + +sp_labeled_block: + sp_block_label + BEGIN_ORACLE_SYM + { + Lex->sp_block_init(thd, &$1); + if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) + MYSQL_YYABORT; + } + sp_block_statements_and_exceptions + END + sp_opt_label + { + if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4), &$6))) + MYSQL_YYABORT; + } + | sp_block_label + DECLARE_ORACLE_SYM + { + Lex->sp_block_init(thd, &$1); + } + sp_decl_body_list + { + if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) + MYSQL_YYABORT; + } + BEGIN_ORACLE_SYM + sp_block_statements_and_exceptions + END + sp_opt_label + { + $4.hndlrs+= $7.hndlrs; + if (unlikely(Lex->sp_block_finalize(thd, $4, &$9))) + MYSQL_YYABORT; + } + ; + +opt_not_atomic: + /* Empty */ + | not ATOMIC_SYM /* TODO: BEGIN ATOMIC (not -> opt_not) */ + ; + +sp_unlabeled_block: + BEGIN_ORACLE_SYM opt_not_atomic + { + if (unlikely(Lex->maybe_start_compound_statement(thd))) + MYSQL_YYABORT; + Lex->sp_block_init(thd); + if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) + MYSQL_YYABORT; + } + sp_block_statements_and_exceptions + END + { + if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4)))) + MYSQL_YYABORT; + } + | DECLARE_ORACLE_SYM + { + if (unlikely(Lex->maybe_start_compound_statement(thd))) + MYSQL_YYABORT; + Lex->sp_block_init(thd); + } + sp_decl_body_list + { + if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd))) + MYSQL_YYABORT; + } + BEGIN_ORACLE_SYM + sp_block_statements_and_exceptions + END + { + $3.hndlrs+= $6.hndlrs; + if (unlikely(Lex->sp_block_finalize(thd, $3))) + MYSQL_YYABORT; + } + ; + +sp_block_statements_and_exceptions: + sp_instr_addr + sp_proc_stmts + { + if (unlikely(Lex->sp_block_with_exceptions_finalize_executable_section(thd, $1))) + MYSQL_YYABORT; + } + opt_exception_clause + { + if (unlikely(Lex->sp_block_with_exceptions_finalize_exceptions(thd, $1, $4))) + MYSQL_YYABORT; + $$.init($4); + } + ; + +/* End of sql_mode=ORACLE specific rules */ + /** @} (end of group Parser) */ |