Commit 4305c3ca authored by Alexander Barkov's avatar Alexander Barkov

MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters

parent a70809c0
......@@ -679,3 +679,105 @@ rec.b
b0
DROP TABLE t1;
DROP PROCEDURE p1;
#
# MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
#
CREATE TABLE t1 (a INT, b TEXT, c ENUM('a','b','c'));
CREATE PROCEDURE p1 (a ROW TYPE OF t1)
BEGIN
CREATE TABLE t2 AS SELECT a.a AS a, a.b AS b, a.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE a ROW TYPE OF t1;
CALL p1(a);
END;
$$
CALL p2();
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` text DEFAULT NULL,
`c` varchar(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b TEXT);
CREATE PROCEDURE p1 (OUT a ROW TYPE OF t1)
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE a ROW TYPE OF t1;
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a ROW TYPE OF t1) RETURNS TEXT
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2() RETURNS TEXT
BEGIN
DECLARE a ROW TYPE OF t1;
CALL p1(a);
RETURN f1(a);
END;
$$
CALL p2();
a.a a.b
10 text
SELECT f2();
f2()
10 text
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP TABLE t1;
CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT, b TEXT);
CREATE PROCEDURE p1 (OUT a ROW TYPE OF db1.t1)
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE a ROW TYPE OF db1.t1;
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a ROW TYPE OF db1.t1) RETURNS TEXT
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2() RETURNS TEXT
BEGIN
DECLARE a ROW TYPE OF db1.t1;
CALL p1(a);
RETURN f1(a);
END;
$$
CALL p2();
a.a a.b
10 text
SELECT f2();
f2()
10 text
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP DATABASE db1;
......@@ -970,3 +970,31 @@ Pos Instruction
DROP PROCEDURE testp_bug11763507;
DROP FUNCTION testf_bug11763507;
#END OF BUG#11763507 test.
#
# MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
#
CREATE TABLE t1 (a INT, b TEXT);
CREATE PROCEDURE p1(a ROW TYPE OF t1, OUT b ROW TYPE OF t1)
BEGIN
SET a.a = 100;
SET a.b = 'aaa';
SET b.a = 200;
SET b.b = 'bbb';
SET a = b;
SET b = a;
SET a.a = b.a;
SET b.a = a.a;
END;
$$
SHOW PROCEDURE CODE p1;
Pos Instruction
0 set a.a@0["a"] 100
1 set a.b@0["b"] 'aaa'
2 set b.a@1["a"] 200
3 set b.b@1["b"] 'bbb'
4 set a@0 b@1
5 set b@1 a@0
6 set a.a@0["a"] b.a@1["a"]
7 set b.a@1["a"] a.a@0["a"]
DROP PROCEDURE p1;
DROP TABLE t1;
SET sql_mode=ORACLE;
#
# MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
#
CREATE TABLE t1 (a INT, b TEXT, c ENUM('a','b','c'));
CREATE PROCEDURE p1 (a t1%ROWTYPE) AS
BEGIN
CREATE TABLE t2 AS SELECT a.a AS a, a.b AS b, a.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
CREATE PROCEDURE p2 AS
a t1%ROWTYPE;
BEGIN
CALL p1(a);
END;
$$
CALL p2();
Table Create Table
t2 CREATE TABLE "t2" (
"a" int(11) DEFAULT NULL,
"b" text DEFAULT NULL,
"c" varchar(1) DEFAULT NULL
)
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b TEXT);
CREATE PROCEDURE p1 (a OUT t1%ROWTYPE) AS
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2 AS
a t1%ROWTYPE;
BEGIN
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a t1%ROWTYPE) RETURN TEXT AS
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2 RETURN TEXT AS
a t1%ROWTYPE;
BEGIN
CALL p1(a);
RETURN f1(a);
END;
$$
CALL p2();
a.a a.b
10 text
SELECT f2();
f2()
10 text
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP TABLE t1;
CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT, b TEXT);
CREATE PROCEDURE p1 (a OUT db1.t1%ROWTYPE) AS
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2 AS
a db1.t1%ROWTYPE;
BEGIN
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a db1.t1%ROWTYPE) RETURN TEXT AS
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2() RETURN TEXT AS
a db1.t1%ROWTYPE;
BEGIN
CALL p1(a);
RETURN f1(a);
END;
$$
CALL p2();
a.a a.b
10 text
SELECT f2();
f2()
10 text
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP DATABASE db1;
SET sql_mode=ORACLE;
--echo #
--echo # MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
--echo #
CREATE TABLE t1 (a INT, b TEXT, c ENUM('a','b','c'));
DELIMITER $$;
CREATE PROCEDURE p1 (a t1%ROWTYPE) AS
BEGIN
CREATE TABLE t2 AS SELECT a.a AS a, a.b AS b, a.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
CREATE PROCEDURE p2 AS
a t1%ROWTYPE;
BEGIN
CALL p1(a);
END;
$$
DELIMITER ;$$
CALL p2();
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b TEXT);
DELIMITER $$;
CREATE PROCEDURE p1 (a OUT t1%ROWTYPE) AS
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2 AS
a t1%ROWTYPE;
BEGIN
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a t1%ROWTYPE) RETURN TEXT AS
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2 RETURN TEXT AS
a t1%ROWTYPE;
BEGIN
CALL p1(a);
RETURN f1(a);
END;
$$
DELIMITER ;$$
CALL p2();
SELECT f2();
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP TABLE t1;
CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT, b TEXT);
DELIMITER $$;
CREATE PROCEDURE p1 (a OUT db1.t1%ROWTYPE) AS
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2 AS
a db1.t1%ROWTYPE;
BEGIN
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a db1.t1%ROWTYPE) RETURN TEXT AS
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2() RETURN TEXT AS
a db1.t1%ROWTYPE;
BEGIN
CALL p1(a);
RETURN f1(a);
END;
$$
DELIMITER ;$$
CALL p2();
SELECT f2();
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP DATABASE db1;
......@@ -759,3 +759,104 @@ DELIMITER ;$$
CALL p1();
DROP TABLE t1;
DROP PROCEDURE p1;
--echo #
--echo # MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
--echo #
CREATE TABLE t1 (a INT, b TEXT, c ENUM('a','b','c'));
DELIMITER $$;
CREATE PROCEDURE p1 (a ROW TYPE OF t1)
BEGIN
CREATE TABLE t2 AS SELECT a.a AS a, a.b AS b, a.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE a ROW TYPE OF t1;
CALL p1(a);
END;
$$
DELIMITER ;$$
CALL p2();
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b TEXT);
DELIMITER $$;
CREATE PROCEDURE p1 (OUT a ROW TYPE OF t1)
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE a ROW TYPE OF t1;
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a ROW TYPE OF t1) RETURNS TEXT
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2() RETURNS TEXT
BEGIN
DECLARE a ROW TYPE OF t1;
CALL p1(a);
RETURN f1(a);
END;
$$
DELIMITER ;$$
CALL p2();
SELECT f2();
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP TABLE t1;
CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT, b TEXT);
DELIMITER $$;
CREATE PROCEDURE p1 (OUT a ROW TYPE OF db1.t1)
BEGIN
SET a.a=10;
SET a.b='text';
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE a ROW TYPE OF db1.t1;
CALL p1(a);
SELECT a.a, a.b;
END;
$$
CREATE FUNCTION f1(a ROW TYPE OF db1.t1) RETURNS TEXT
BEGIN
RETURN CONCAT(a.a, ' ', a.b);
END;
$$
CREATE FUNCTION f2() RETURNS TEXT
BEGIN
DECLARE a ROW TYPE OF db1.t1;
CALL p1(a);
RETURN f1(a);
END;
$$
DELIMITER ;$$
CALL p2();
SELECT f2();
DROP PROCEDURE p2;
DROP PROCEDURE p1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP DATABASE db1;
......@@ -734,3 +734,27 @@ DROP PROCEDURE testp_bug11763507;
DROP FUNCTION testf_bug11763507;
--echo #END OF BUG#11763507 test.
--echo #
--echo # MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters
--echo #
CREATE TABLE t1 (a INT, b TEXT);
DELIMITER $$;
CREATE PROCEDURE p1(a ROW TYPE OF t1, OUT b ROW TYPE OF t1)
BEGIN
SET a.a = 100;
SET a.b = 'aaa';
SET b.a = 200;
SET b.b = 'bbb';
SET a = b;
SET b = a;
SET a.a = b.a;
SET b.a = a.a;
END;
$$
DELIMITER ;$$
SHOW PROCEDURE CODE p1;
DROP PROCEDURE p1;
DROP TABLE t1;
......@@ -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;
}
......@@ -676,6 +676,8 @@ class sp_head :private Query_arena,
def->field_name= *name;
return fill_spvar_definition(thd, def);
}
private:
/**
Set a column type reference for a parameter definition
*/
......@@ -687,6 +689,31 @@ class sp_head :private Query_arena,
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);
......
......@@ -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
{
......
......@@ -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
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment