diff options
author | Alexander Barkov <bar@mariadb.org> | 2017-08-18 18:29:33 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2017-08-18 18:29:33 +0400 |
commit | 4305c3ca5797ba4157384c363579be8e934e2fb1 (patch) | |
tree | aa48de35235e7d087d385f3c28edeacdf11e9d89 /sql | |
parent | a70809c0fcd5eca38c5f6bafa92270f1704a0597 (diff) | |
download | mariadb-git-4305c3ca5797ba4157384c363579be8e934e2fb1.tar.gz |
MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sp_head.cc | 65 | ||||
-rw-r--r-- | sql/sp_head.h | 27 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 42 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 72 |
4 files changed, 156 insertions, 50 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc index bb6fe6613bf..2ea40e37754 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -4718,3 +4718,68 @@ sp_head::add_set_for_loop_cursor_param_variables(THD *thd, } return false; } + + +bool sp_head::spvar_fill_row(THD *thd, + sp_variable *spvar, + Row_definition_list *defs) +{ + spvar->field_def.field_name= spvar->name; + if (fill_spvar_definition(thd, &spvar->field_def)) + return true; + row_fill_field_definitions(thd, defs); + spvar->field_def.set_row_field_definitions(defs); + return false; +} + + +bool sp_head::spvar_fill_type_reference(THD *thd, + sp_variable *spvar, + const LEX_CSTRING &table, + const LEX_CSTRING &col) +{ + Qualified_column_ident *ref; + if (!(ref= new (thd->mem_root) Qualified_column_ident(&table, &col))) + return true; + fill_spvar_using_type_reference(spvar, ref); + return false; +} + + +bool sp_head::spvar_fill_type_reference(THD *thd, + sp_variable *spvar, + const LEX_CSTRING &db, + const LEX_CSTRING &table, + const LEX_CSTRING &col) +{ + Qualified_column_ident *ref; + if (!(ref= new (thd->mem_root) Qualified_column_ident(thd, &db, &table, &col))) + return true; + fill_spvar_using_type_reference(spvar, ref); + return false; +} + + +bool sp_head::spvar_fill_table_rowtype_reference(THD *thd, + sp_variable *spvar, + const LEX_CSTRING &table) +{ + Table_ident *ref; + if (!(ref= new (thd->mem_root) Table_ident(&table))) + return true; + fill_spvar_using_table_rowtype_reference(thd, spvar, ref); + return false; +} + + +bool sp_head::spvar_fill_table_rowtype_reference(THD *thd, + sp_variable *spvar, + const LEX_CSTRING &db, + const LEX_CSTRING &table) +{ + Table_ident *ref; + if (!(ref= new (thd->mem_root) Table_ident(thd, &db, &table, false))) + return true; + fill_spvar_using_table_rowtype_reference(thd, spvar, ref); + return false; +} diff --git a/sql/sp_head.h b/sql/sp_head.h index 730b2c11b43..c3dab609823 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -676,6 +676,8 @@ public: def->field_name= *name; return fill_spvar_definition(thd, def); } + +private: /** Set a column type reference for a parameter definition */ @@ -687,6 +689,31 @@ public: m_flags|= sp_head::HAS_COLUMN_TYPE_REFS; } + void fill_spvar_using_table_rowtype_reference(THD *thd, + sp_variable *spvar, + Table_ident *ref) + { + spvar->field_def.set_table_rowtype_ref(ref); + spvar->field_def.field_name= spvar->name; + fill_spvar_definition(thd, &spvar->field_def); + m_flags|= sp_head::HAS_COLUMN_TYPE_REFS; + } + +public: + bool spvar_fill_row(THD *thd, sp_variable *spvar, Row_definition_list *def); + bool spvar_fill_type_reference(THD *thd, sp_variable *spvar, + const LEX_CSTRING &table, + const LEX_CSTRING &column); + bool spvar_fill_type_reference(THD *thd, sp_variable *spvar, + const LEX_CSTRING &db, + const LEX_CSTRING &table, + const LEX_CSTRING &column); + bool spvar_fill_table_rowtype_reference(THD *thd, sp_variable *spvar, + const LEX_CSTRING &table); + bool spvar_fill_table_rowtype_reference(THD *thd, sp_variable *spvar, + const LEX_CSTRING &db, + const LEX_CSTRING &table); + void set_chistics(const st_sp_chistics &chistics); void set_info(longlong created, longlong modified, const st_sp_chistics &chistics, sql_mode_t sql_mode); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 647ed1a3a60..b4aa1b63213 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1633,7 +1633,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); table_ident_opt_wild create_like %type <qualified_column_ident> - qualified_column_ident optionally_qualified_column_ident %type <simple_string> @@ -3093,17 +3092,30 @@ sp_param_name_and_type: if (Lex->sp_param_fill_definition($$= $1)) MYSQL_YYABORT; } - | sp_param_name TYPE_SYM OF_SYM qualified_column_ident + | sp_param_name TYPE_SYM OF_SYM ident '.' ident { - Lex->sphead->fill_spvar_using_type_reference($$= $1, $4); + if (Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $4, $6)) + MYSQL_YYABORT; + } + | sp_param_name TYPE_SYM OF_SYM ident '.' ident '.' ident + { + if (Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $4, $6, $8)) + MYSQL_YYABORT; + } + | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident + { + if (Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5)) + MYSQL_YYABORT; + } + | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident '.' ident + { + if (Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5, $7)) + MYSQL_YYABORT; } | sp_param_name ROW_SYM row_type_body { - $$= $1; - $$->field_def.field_name= $$->name; - Lex->sphead->fill_spvar_definition(thd, &$$->field_def); - Lex->sphead->row_fill_field_definitions(thd, $3); - $$->field_def.set_row_field_definitions($3); + if (Lex->sphead->spvar_fill_row(thd, $$= $1, $3)) + MYSQL_YYABORT; } ; @@ -3184,20 +3196,6 @@ sp_decl: ; -qualified_column_ident: - sp_decl_ident '.' ident - { - if (!($$= new (thd->mem_root) Qualified_column_ident(&$1, &$3))) - MYSQL_YYABORT; - } - | sp_decl_ident '.' ident '.' ident - { - if (!($$= new (thd->mem_root) Qualified_column_ident(thd, - &$1, &$3, &$5))) - MYSQL_YYABORT; - } - ; - optionally_qualified_column_ident: sp_decl_ident { diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index f0f365d0116..746d43fdc0f 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -1044,7 +1044,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); table_ident_opt_wild create_like %type <qualified_column_ident> - qualified_column_ident optionally_qualified_column_ident %type <simple_string> @@ -2539,17 +2538,30 @@ sp_param_name_and_type: if (Lex->sp_param_fill_definition($$= $1)) MYSQL_YYABORT; } - | sp_param_name qualified_column_ident '%' TYPE_SYM + | sp_param_name sp_decl_ident '.' ident '%' TYPE_SYM { - Lex->sphead->fill_spvar_using_type_reference($$= $1, $2); + if (Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4)) + MYSQL_YYABORT; + } + | sp_param_name sp_decl_ident '.' ident '.' ident '%' TYPE_SYM + { + if (Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4, $6)) + MYSQL_YYABORT; + } + | sp_param_name sp_decl_ident '%' ROWTYPE_SYM + { + if (Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2)) + MYSQL_YYABORT; + } + | sp_param_name sp_decl_ident '.' ident '%' ROWTYPE_SYM + { + if (Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2, $4)) + MYSQL_YYABORT; } | sp_param_name ROW_SYM row_type_body { - $$= $1; - $$->field_def.field_name= $$->name; - Lex->sphead->fill_spvar_definition(thd, &$$->field_def); - Lex->sphead->row_fill_field_definitions(thd, $3); - $$->field_def.set_row_field_definitions($3); + if (Lex->sphead->spvar_fill_row(thd, $$= $1, $3)) + MYSQL_YYABORT; } ; @@ -2571,17 +2583,35 @@ sp_pdparam: if (Lex->sp_param_fill_definition($1)) MYSQL_YYABORT; } - | sp_param_name sp_opt_inout qualified_column_ident '%' TYPE_SYM + | sp_param_name sp_opt_inout sp_decl_ident '.' ident '%' TYPE_SYM + { + $1->mode= $2; + if (Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5)) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident '.' ident '.' ident '%' TYPE_SYM { - Lex->sphead->fill_spvar_using_type_reference($1, $3); + $1->mode= $2; + if (Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5, $7)) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident '%' ROWTYPE_SYM + { + $1->mode= $2; + if (Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3)) + MYSQL_YYABORT; + } + | sp_param_name sp_opt_inout sp_decl_ident '.' ident '%' ROWTYPE_SYM + { + $1->mode= $2; + if (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; - $1->field_def.field_name= $1->name; - Lex->sphead->fill_spvar_definition(thd, &$1->field_def); - Lex->sphead->row_fill_field_definitions(thd, $4); - $1->field_def.set_row_field_definitions($4); + if (Lex->sphead->spvar_fill_row(thd, $1, $4)) + MYSQL_YYABORT; } ; @@ -2698,20 +2728,6 @@ opt_sp_decl_handler_list: | sp_decl_handler_list ; -qualified_column_ident: - sp_decl_ident '.' ident - { - if (!($$= new (thd->mem_root) Qualified_column_ident(&$1, &$3))) - MYSQL_YYABORT; - } - | sp_decl_ident '.' ident '.' ident - { - if (!($$= new (thd->mem_root) Qualified_column_ident(thd, - &$1, &$3, &$5))) - MYSQL_YYABORT; - } - ; - optionally_qualified_column_ident: sp_decl_ident { |