Commit 5dd5253f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-14139 Anchored data types for variables

parent e7637ec0
...@@ -1001,3 +1001,33 @@ t1 CREATE TABLE `t1` ( ...@@ -1001,3 +1001,33 @@ t1 CREATE TABLE `t1` (
`rec1.a` int(11) DEFAULT NULL `rec1.a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP PROCEDURE p1; DROP PROCEDURE p1;
#
# MDEV-14139 Anchored data types for variables
#
BEGIN NOT ATOMIC
DECLARE c1 CURSOR FOR SELECT 10 AS a, 'bbb' AS b, TIME'10:20:30' AS c;
BEGIN
DECLARE row1 ROW TYPE OF c1;
DECLARE a_row1 TYPE OF row1;
DECLARE aa_row1 TYPE OF a_row1;
CREATE TABLE t2 AS SELECT a_row1.a AS a, a_row1.b AS b, a_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.a AS a, aa_row1.b AS b, aa_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
END;
$$
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` varchar(3) DEFAULT NULL,
`c` time DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` varchar(3) DEFAULT NULL,
`c` time DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
...@@ -781,3 +781,30 @@ DROP PROCEDURE p1; ...@@ -781,3 +781,30 @@ DROP PROCEDURE p1;
DROP FUNCTION f2; DROP FUNCTION f2;
DROP FUNCTION f1; DROP FUNCTION f1;
DROP DATABASE db1; DROP DATABASE db1;
#
# MDEV-14139 Anchored data types for variables
#
CREATE TABLE t1 (int11 INT, text0 TEXT);
BEGIN NOT ATOMIC
DECLARE row1 ROW TYPE OF t1;
DECLARE a_row1 TYPE OF row1;
DECLARE aa_row1 TYPE OF a_row1;
CREATE TABLE t2 AS SELECT a_row1.int11 AS int11, a_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.int11 AS int11, aa_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
Table Create Table
t2 CREATE TABLE `t2` (
`int11` int(11) DEFAULT NULL,
`text0` text DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Table Create Table
t2 CREATE TABLE `t2` (
`int11` int(11) DEFAULT NULL,
`text0` text DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
...@@ -965,3 +965,109 @@ DROP TABLE t1; ...@@ -965,3 +965,109 @@ DROP TABLE t1;
# #
# End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types # End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types
# #
#
# MDEV-14139 Anchored data types for variables
#
BEGIN NOT ATOMIC
DECLARE a TYPE OF a;
END;
$$
ERROR 42000: Undeclared variable: a
BEGIN NOT ATOMIC
DECLARE int11 INT;
DECLARE dec103 DECIMAL(10,3);
DECLARE flt0 FLOAT;
DECLARE dbl0 DOUBLE;
DECLARE enum0 ENUM('a','b');
DECLARE bit3 BIT(3);
DECLARE varchar10 VARCHAR(10);
DECLARE text1 TEXT;
DECLARE tinytext1 TINYTEXT;
DECLARE mediumtext1 MEDIUMTEXT;
DECLARE longtext1 LONGTEXT;
DECLARE time3 TIME(3);
DECLARE datetime4 DATETIME(4);
DECLARE timestamp5 TIMESTAMP(5);
DECLARE date0 DATE;
DECLARE a_int11 TYPE OF int11;
DECLARE a_dec103 TYPE OF dec103;
DECLARE a_flt0 TYPE OF flt0;
DECLARE a_dbl0 TYPE OF dbl0;
DECLARE a_bit3 TYPE OF bit3;
DECLARE a_enum0 TYPE OF enum0;
DECLARE a_varchar10 TYPE OF varchar10;
DECLARE a_text1 TYPE OF text1;
DECLARE a_tinytext1 TYPE OF tinytext1;
DECLARE a_mediumtext1 TYPE OF mediumtext1;
DECLARE a_longtext1 TYPE OF longtext1;
DECLARE a_time3 TYPE OF time3;
DECLARE a_datetime4 TYPE OF datetime4;
DECLARE a_timestamp5 TYPE OF timestamp5;
DECLARE a_date0 TYPE OF date0;
DECLARE aa_int11 TYPE OF a_int11;
DECLARE aa_dec103 TYPE OF a_dec103;
DECLARE aa_flt0 TYPE OF a_flt0;
DECLARE aa_dbl0 TYPE OF a_dbl0;
DECLARE aa_bit3 TYPE OF a_bit3;
DECLARE aa_enum0 TYPE OF a_enum0;
DECLARE aa_varchar10 TYPE OF a_varchar10;
DECLARE aa_text1 TYPE OF a_text1;
DECLARE aa_tinytext1 TYPE OF a_tinytext1;
DECLARE aa_mediumtext1 TYPE OF a_mediumtext1;
DECLARE aa_longtext1 TYPE OF a_longtext1;
DECLARE aa_time3 TYPE OF a_time3;
DECLARE aa_datetime4 TYPE OF a_datetime4;
DECLARE aa_timestamp5 TYPE OF a_timestamp5;
DECLARE aa_date0 TYPE OF a_date0;
CREATE TABLE t1 AS
SELECT a_int11,a_dec103,a_flt0,a_dbl0,a_bit3,
a_enum0,a_varchar10,
a_text1,a_tinytext1,a_mediumtext1,a_longtext1,
a_time3,a_datetime4,a_timestamp5,a_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS
SELECT aa_int11,aa_dec103,aa_flt0,aa_dbl0,aa_bit3,
aa_enum0,aa_varchar10,
aa_text1,aa_tinytext1,aa_mediumtext1,aa_longtext1,
aa_time3,aa_datetime4,aa_timestamp5,aa_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
Table Create Table
t1 CREATE TABLE `t1` (
`a_int11` int(11) DEFAULT NULL,
`a_dec103` decimal(10,3) DEFAULT NULL,
`a_flt0` float DEFAULT NULL,
`a_dbl0` double DEFAULT NULL,
`a_bit3` bit(3) DEFAULT NULL,
`a_enum0` varchar(1) DEFAULT NULL,
`a_varchar10` varchar(10) DEFAULT NULL,
`a_text1` text DEFAULT NULL,
`a_tinytext1` tinytext DEFAULT NULL,
`a_mediumtext1` mediumtext DEFAULT NULL,
`a_longtext1` longtext DEFAULT NULL,
`a_time3` time(3) DEFAULT NULL,
`a_datetime4` datetime(4) DEFAULT NULL,
`a_timestamp5` timestamp(5) NULL DEFAULT NULL,
`a_date0` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Table Create Table
t1 CREATE TABLE `t1` (
`aa_int11` int(11) DEFAULT NULL,
`aa_dec103` decimal(10,3) DEFAULT NULL,
`aa_flt0` float DEFAULT NULL,
`aa_dbl0` double DEFAULT NULL,
`aa_bit3` bit(3) DEFAULT NULL,
`aa_enum0` varchar(1) DEFAULT NULL,
`aa_varchar10` varchar(10) DEFAULT NULL,
`aa_text1` text DEFAULT NULL,
`aa_tinytext1` tinytext DEFAULT NULL,
`aa_mediumtext1` mediumtext DEFAULT NULL,
`aa_longtext1` longtext DEFAULT NULL,
`aa_time3` time(3) DEFAULT NULL,
`aa_datetime4` datetime(4) DEFAULT NULL,
`aa_timestamp5` timestamp(5) NULL DEFAULT NULL,
`aa_date0` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
...@@ -2256,3 +2256,28 @@ END; ...@@ -2256,3 +2256,28 @@ END;
$$ $$
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
#
# MDEV-14139 Anchored data types for variables
#
BEGIN NOT ATOMIC
DECLARE row1 ROW(int11 INT,text1 TEXT);
DECLARE a_row1 TYPE OF row1;
DECLARE aa_row1 TYPE OF a_row1;
CREATE TABLE t1 AS SELECT a_row1.int11 AS int11, a_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS SELECT aa_row1.int11 AS int11, aa_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
Table Create Table
t1 CREATE TABLE `t1` (
`int11` int(11) DEFAULT NULL,
`text1` text DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Table Create Table
t1 CREATE TABLE `t1` (
`int11` int(11) DEFAULT NULL,
`text1` text DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
...@@ -101,3 +101,31 @@ DROP PROCEDURE p1; ...@@ -101,3 +101,31 @@ DROP PROCEDURE p1;
DROP FUNCTION f2; DROP FUNCTION f2;
DROP FUNCTION f1; DROP FUNCTION f1;
DROP DATABASE db1; DROP DATABASE db1;
#
# MDEV-14139 Anchored data types for variables
#
CREATE TABLE t1 (int11 INT, text0 TEXT);
DECLARE
row1 t1%ROWTYPE;
a_row1 row1%TYPE;
aa_row1 a_row1%TYPE;
BEGIN
CREATE TABLE t2 AS SELECT a_row1.int11 AS int11, a_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.int11 AS int11, aa_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
Table Create Table
t2 CREATE TABLE "t2" (
"int11" int(11) DEFAULT NULL,
"text0" text DEFAULT NULL
)
Table Create Table
t2 CREATE TABLE "t2" (
"int11" int(11) DEFAULT NULL,
"text0" text DEFAULT NULL
)
DROP TABLE t1;
...@@ -1030,8 +1030,8 @@ Pos Instruction ...@@ -1030,8 +1030,8 @@ Pos Instruction
0 cpush cur1@0 0 cpush cur1@0
1 cpush cur2@1 1 cpush cur2@1
2 cursor_copy_struct cur1 rec1@0 2 cursor_copy_struct cur1 rec1@0
3 set rec1@0 NULL 3 cursor_copy_struct cur1 rec2@1
4 cursor_copy_struct cur1 rec2@1 4 set rec1@0 NULL
5 set rec2@1 NULL 5 set rec2@1 NULL
6 cursor_copy_struct cur2 rec3@2 6 cursor_copy_struct cur2 rec3@2
7 set rec3@2 NULL 7 set rec3@2 NULL
......
...@@ -1330,3 +1330,32 @@ rec2.a rec2.b ...@@ -1330,3 +1330,32 @@ rec2.a rec2.b
2012 bbbb3 2012 bbbb3
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-14139 Anchored data types for variables
#
DECLARE
CURSOR c1 IS SELECT 10 AS a, 'bbb' AS b, TIME'10:20:30' AS c;
row1 c1%ROWTYPE;
a_row1 row1%TYPE;
aa_row1 a_row1%TYPE;
BEGIN
CREATE TABLE t2 AS SELECT a_row1.a AS a, a_row1.b AS b, a_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.a AS a, aa_row1.b AS b, aa_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
Table Create Table
t2 CREATE TABLE "t2" (
"a" int(11) DEFAULT NULL,
"b" varchar(3) DEFAULT NULL,
"c" time DEFAULT NULL
)
Table Create Table
t2 CREATE TABLE "t2" (
"a" int(11) DEFAULT NULL,
"b" varchar(3) DEFAULT NULL,
"c" time DEFAULT NULL
)
...@@ -3081,3 +3081,29 @@ END; ...@@ -3081,3 +3081,29 @@ END;
$$ $$
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
#
# MDEV-14139 Anchored data types for variables
#
DECLARE
row1 ROW(int11 INT,text1 TEXT);
a_row1 row1%TYPE;
aa_row1 a_row1%TYPE;
BEGIN
CREATE TABLE t1 AS SELECT a_row1.int11 AS int11, a_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS SELECT aa_row1.int11 AS int11, aa_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
Table Create Table
t1 CREATE TABLE "t1" (
"int11" int(11) DEFAULT NULL,
"text1" text DEFAULT NULL
)
Table Create Table
t1 CREATE TABLE "t1" (
"int11" int(11) DEFAULT NULL,
"text1" text DEFAULT NULL
)
...@@ -2297,3 +2297,110 @@ SELECT exception FROM v1; ...@@ -2297,3 +2297,110 @@ SELECT exception FROM v1;
exception exception
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-14139 Anchored data types for variables
#
BEGIN NOT ATOMIC
DECLARE a a%TYPE;
END;
$$
ERROR 42000: Undeclared variable: a
DECLARE
int11 INT;
dec103 DECIMAL(10,3);
flt0 FLOAT;
dbl0 DOUBLE;
enum0 ENUM('a','b');
bit3 BIT(3);
varchar10 VARCHAR(10);
text1 TEXT;
tinytext1 TINYTEXT;
mediumtext1 MEDIUMTEXT;
longtext1 LONGTEXT;
time3 TIME(3);
datetime4 DATETIME(4);
timestamp5 TIMESTAMP(5);
date0 DATE;
a_int11 int11%TYPE;
a_dec103 dec103%TYPE;
a_flt0 flt0%TYPE;
a_dbl0 dbl0%TYPE;
a_bit3 bit3%TYPE;
a_enum0 enum0%TYPE;
a_varchar10 varchar10%TYPE;
a_text1 text1%TYPE;
a_tinytext1 tinytext1%TYPE;
a_mediumtext1 mediumtext1%TYPE;
a_longtext1 longtext1%TYPE;
a_time3 time3%TYPE;
a_datetime4 datetime4%TYPE;
a_timestamp5 timestamp5%TYPE;
a_date0 date0%TYPE;
aa_int11 a_int11%TYPE;
aa_dec103 a_dec103%TYPE;
aa_flt0 a_flt0%TYPE;
aa_dbl0 a_dbl0%TYPE;
aa_bit3 a_bit3%TYPE;
aa_enum0 a_enum0%TYPE;
aa_varchar10 a_varchar10%TYPE;
aa_text1 a_text1%TYPE;
aa_tinytext1 a_tinytext1%TYPE;
aa_mediumtext1 a_mediumtext1%TYPE;
aa_longtext1 a_longtext1%TYPE;
aa_time3 a_time3%TYPE;
aa_datetime4 a_datetime4%TYPE;
aa_timestamp5 a_timestamp5%TYPE;
aa_date0 a_date0%TYPE;
BEGIN
CREATE TABLE t1 AS
SELECT a_int11,a_dec103,a_flt0,a_dbl0,a_bit3,
a_enum0,a_varchar10,
a_text1,a_tinytext1,a_mediumtext1,a_longtext1,
a_time3,a_datetime4,a_timestamp5,a_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS
SELECT aa_int11,aa_dec103,aa_flt0,aa_dbl0,aa_bit3,
aa_enum0,aa_varchar10,
aa_text1,aa_tinytext1,aa_mediumtext1,aa_longtext1,
aa_time3,aa_datetime4,aa_timestamp5,aa_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
Table Create Table
t1 CREATE TABLE "t1" (
"a_int11" int(11) DEFAULT NULL,
"a_dec103" decimal(10,3) DEFAULT NULL,
"a_flt0" float DEFAULT NULL,
"a_dbl0" double DEFAULT NULL,
"a_bit3" bit(3) DEFAULT NULL,
"a_enum0" varchar(1) DEFAULT NULL,
"a_varchar10" varchar(10) DEFAULT NULL,
"a_text1" text DEFAULT NULL,
"a_tinytext1" tinytext DEFAULT NULL,
"a_mediumtext1" mediumtext DEFAULT NULL,
"a_longtext1" longtext DEFAULT NULL,
"a_time3" time(3) DEFAULT NULL,
"a_datetime4" datetime(4) DEFAULT NULL,
"a_timestamp5" timestamp(5) NULL DEFAULT NULL,
"a_date0" datetime DEFAULT NULL
)
Table Create Table
t1 CREATE TABLE "t1" (
"aa_int11" int(11) DEFAULT NULL,
"aa_dec103" decimal(10,3) DEFAULT NULL,
"aa_flt0" float DEFAULT NULL,
"aa_dbl0" double DEFAULT NULL,
"aa_bit3" bit(3) DEFAULT NULL,
"aa_enum0" varchar(1) DEFAULT NULL,
"aa_varchar10" varchar(10) DEFAULT NULL,
"aa_text1" text DEFAULT NULL,
"aa_tinytext1" tinytext DEFAULT NULL,
"aa_mediumtext1" mediumtext DEFAULT NULL,
"aa_longtext1" longtext DEFAULT NULL,
"aa_time3" time(3) DEFAULT NULL,
"aa_datetime4" datetime(4) DEFAULT NULL,
"aa_timestamp5" timestamp(5) NULL DEFAULT NULL,
"aa_date0" datetime DEFAULT NULL
)
...@@ -99,3 +99,26 @@ DROP PROCEDURE p1; ...@@ -99,3 +99,26 @@ DROP PROCEDURE p1;
DROP FUNCTION f2; DROP FUNCTION f2;
DROP FUNCTION f1; DROP FUNCTION f1;
DROP DATABASE db1; DROP DATABASE db1;
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
CREATE TABLE t1 (int11 INT, text0 TEXT);
DELIMITER $$;
DECLARE
row1 t1%ROWTYPE;
a_row1 row1%TYPE;
aa_row1 a_row1%TYPE;
BEGIN
CREATE TABLE t2 AS SELECT a_row1.int11 AS int11, a_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.int11 AS int11, aa_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
DELIMITER ;$$
DROP TABLE t1;
...@@ -1422,3 +1422,25 @@ DELIMITER ;$$ ...@@ -1422,3 +1422,25 @@ DELIMITER ;$$
CALL p1(); CALL p1();
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
DELIMITER $$;
DECLARE
CURSOR c1 IS SELECT 10 AS a, 'bbb' AS b, TIME'10:20:30' AS c;
row1 c1%ROWTYPE;
a_row1 row1%TYPE;
aa_row1 a_row1%TYPE;
BEGIN
CREATE TABLE t2 AS SELECT a_row1.a AS a, a_row1.b AS b, a_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.a AS a, aa_row1.b AS b, aa_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
DELIMITER ;$$
...@@ -2388,3 +2388,24 @@ BEGIN ...@@ -2388,3 +2388,24 @@ BEGIN
END; END;
$$ $$
DELIMITER ;$$ DELIMITER ;$$
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
DELIMITER $$;
DECLARE
row1 ROW(int11 INT,text1 TEXT);
a_row1 row1%TYPE;
aa_row1 a_row1%TYPE;
BEGIN
CREATE TABLE t1 AS SELECT a_row1.int11 AS int11, a_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS SELECT aa_row1.int11 AS int11, aa_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
DELIMITER ;$$
...@@ -2146,3 +2146,90 @@ CREATE VIEW v1 AS SELECT c1 exception FROM t1; ...@@ -2146,3 +2146,90 @@ CREATE VIEW v1 AS SELECT c1 exception FROM t1;
SELECT exception FROM v1; SELECT exception FROM v1;
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
DELIMITER $$;
--error ER_SP_UNDECLARED_VAR
BEGIN NOT ATOMIC
DECLARE a a%TYPE;
END;
$$
DELIMITER ;$$
DELIMITER $$;
DECLARE
int11 INT;
dec103 DECIMAL(10,3);
flt0 FLOAT;
dbl0 DOUBLE;
enum0 ENUM('a','b');
bit3 BIT(3);
varchar10 VARCHAR(10);
text1 TEXT;
tinytext1 TINYTEXT;
mediumtext1 MEDIUMTEXT;
longtext1 LONGTEXT;
time3 TIME(3);
datetime4 DATETIME(4);
timestamp5 TIMESTAMP(5);
date0 DATE;
a_int11 int11%TYPE;
a_dec103 dec103%TYPE;
a_flt0 flt0%TYPE;
a_dbl0 dbl0%TYPE;
a_bit3 bit3%TYPE;
a_enum0 enum0%TYPE;
a_varchar10 varchar10%TYPE;
a_text1 text1%TYPE;
a_tinytext1 tinytext1%TYPE;
a_mediumtext1 mediumtext1%TYPE;
a_longtext1 longtext1%TYPE;
a_time3 time3%TYPE;
a_datetime4 datetime4%TYPE;
a_timestamp5 timestamp5%TYPE;
a_date0 date0%TYPE;
aa_int11 a_int11%TYPE;
aa_dec103 a_dec103%TYPE;
aa_flt0 a_flt0%TYPE;
aa_dbl0 a_dbl0%TYPE;
aa_bit3 a_bit3%TYPE;
aa_enum0 a_enum0%TYPE;
aa_varchar10 a_varchar10%TYPE;
aa_text1 a_text1%TYPE;
aa_tinytext1 a_tinytext1%TYPE;
aa_mediumtext1 a_mediumtext1%TYPE;
aa_longtext1 a_longtext1%TYPE;
aa_time3 a_time3%TYPE;
aa_datetime4 a_datetime4%TYPE;
aa_timestamp5 a_timestamp5%TYPE;
aa_date0 a_date0%TYPE;
BEGIN
CREATE TABLE t1 AS
SELECT a_int11,a_dec103,a_flt0,a_dbl0,a_bit3,
a_enum0,a_varchar10,
a_text1,a_tinytext1,a_mediumtext1,a_longtext1,
a_time3,a_datetime4,a_timestamp5,a_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS
SELECT aa_int11,aa_dec103,aa_flt0,aa_dbl0,aa_bit3,
aa_enum0,aa_varchar10,
aa_text1,aa_tinytext1,aa_mediumtext1,aa_longtext1,
aa_time3,aa_datetime4,aa_timestamp5,aa_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
DELIMITER ;$$
...@@ -1093,3 +1093,26 @@ $$ ...@@ -1093,3 +1093,26 @@ $$
DELIMITER ;$$ DELIMITER ;$$
CALL p1(); CALL p1();
DROP PROCEDURE p1; DROP PROCEDURE p1;
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE c1 CURSOR FOR SELECT 10 AS a, 'bbb' AS b, TIME'10:20:30' AS c;
BEGIN
DECLARE row1 ROW TYPE OF c1;
DECLARE a_row1 TYPE OF row1;
DECLARE aa_row1 TYPE OF a_row1;
CREATE TABLE t2 AS SELECT a_row1.a AS a, a_row1.b AS b, a_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.a AS a, aa_row1.b AS b, aa_row1.c AS c;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
END;
$$
DELIMITER ;$$
...@@ -860,3 +860,24 @@ DROP PROCEDURE p1; ...@@ -860,3 +860,24 @@ DROP PROCEDURE p1;
DROP FUNCTION f2; DROP FUNCTION f2;
DROP FUNCTION f1; DROP FUNCTION f1;
DROP DATABASE db1; DROP DATABASE db1;
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
CREATE TABLE t1 (int11 INT, text0 TEXT);
DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE row1 ROW TYPE OF t1;
DECLARE a_row1 TYPE OF row1;
DECLARE aa_row1 TYPE OF a_row1;
CREATE TABLE t2 AS SELECT a_row1.int11 AS int11, a_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
CREATE TABLE t2 AS SELECT aa_row1.int11 AS int11, aa_row1.text0 AS text0;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
$$
DELIMITER ;$$
DROP TABLE t1;
...@@ -675,3 +675,88 @@ DROP TABLE t1; ...@@ -675,3 +675,88 @@ DROP TABLE t1;
--echo # --echo #
--echo # End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types --echo # End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types
--echo # --echo #
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
DELIMITER $$;
--error ER_SP_UNDECLARED_VAR
BEGIN NOT ATOMIC
DECLARE a TYPE OF a;
END;
$$
DELIMITER ;$$
DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE int11 INT;
DECLARE dec103 DECIMAL(10,3);
DECLARE flt0 FLOAT;
DECLARE dbl0 DOUBLE;
DECLARE enum0 ENUM('a','b');
DECLARE bit3 BIT(3);
DECLARE varchar10 VARCHAR(10);
DECLARE text1 TEXT;
DECLARE tinytext1 TINYTEXT;
DECLARE mediumtext1 MEDIUMTEXT;
DECLARE longtext1 LONGTEXT;
DECLARE time3 TIME(3);
DECLARE datetime4 DATETIME(4);
DECLARE timestamp5 TIMESTAMP(5);
DECLARE date0 DATE;
DECLARE a_int11 TYPE OF int11;
DECLARE a_dec103 TYPE OF dec103;
DECLARE a_flt0 TYPE OF flt0;
DECLARE a_dbl0 TYPE OF dbl0;
DECLARE a_bit3 TYPE OF bit3;
DECLARE a_enum0 TYPE OF enum0;
DECLARE a_varchar10 TYPE OF varchar10;
DECLARE a_text1 TYPE OF text1;
DECLARE a_tinytext1 TYPE OF tinytext1;
DECLARE a_mediumtext1 TYPE OF mediumtext1;
DECLARE a_longtext1 TYPE OF longtext1;
DECLARE a_time3 TYPE OF time3;
DECLARE a_datetime4 TYPE OF datetime4;
DECLARE a_timestamp5 TYPE OF timestamp5;
DECLARE a_date0 TYPE OF date0;
DECLARE aa_int11 TYPE OF a_int11;
DECLARE aa_dec103 TYPE OF a_dec103;
DECLARE aa_flt0 TYPE OF a_flt0;
DECLARE aa_dbl0 TYPE OF a_dbl0;
DECLARE aa_bit3 TYPE OF a_bit3;
DECLARE aa_enum0 TYPE OF a_enum0;
DECLARE aa_varchar10 TYPE OF a_varchar10;
DECLARE aa_text1 TYPE OF a_text1;
DECLARE aa_tinytext1 TYPE OF a_tinytext1;
DECLARE aa_mediumtext1 TYPE OF a_mediumtext1;
DECLARE aa_longtext1 TYPE OF a_longtext1;
DECLARE aa_time3 TYPE OF a_time3;
DECLARE aa_datetime4 TYPE OF a_datetime4;
DECLARE aa_timestamp5 TYPE OF a_timestamp5;
DECLARE aa_date0 TYPE OF a_date0;
CREATE TABLE t1 AS
SELECT a_int11,a_dec103,a_flt0,a_dbl0,a_bit3,
a_enum0,a_varchar10,
a_text1,a_tinytext1,a_mediumtext1,a_longtext1,
a_time3,a_datetime4,a_timestamp5,a_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS
SELECT aa_int11,aa_dec103,aa_flt0,aa_dbl0,aa_bit3,
aa_enum0,aa_varchar10,
aa_text1,aa_tinytext1,aa_mediumtext1,aa_longtext1,
aa_time3,aa_datetime4,aa_timestamp5,aa_date0;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
DELIMITER ;$$
...@@ -1484,3 +1484,23 @@ BEGIN NOT ATOMIC ...@@ -1484,3 +1484,23 @@ BEGIN NOT ATOMIC
END; END;
$$ $$
DELIMITER ;$$ DELIMITER ;$$
--echo #
--echo # MDEV-14139 Anchored data types for variables
--echo #
DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE row1 ROW(int11 INT,text1 TEXT);
DECLARE a_row1 TYPE OF row1;
DECLARE aa_row1 TYPE OF a_row1;
CREATE TABLE t1 AS SELECT a_row1.int11 AS int11, a_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 AS SELECT aa_row1.int11 AS int11, aa_row1.text1 AS text1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
DELIMITER ;$$
...@@ -4061,6 +4061,23 @@ class Column_definition: public Sql_alloc, ...@@ -4061,6 +4061,23 @@ class Column_definition: public Sql_alloc,
|| unireg_check == Field::TIMESTAMP_DNUN_FIELD; || unireg_check == Field::TIMESTAMP_DNUN_FIELD;
} }
void set_type(const Column_definition &other)
{
set_handler(other.type_handler());
length= other.length;
char_length= other.char_length;
decimals= other.decimals;
flags= other.flags;
pack_length= other.pack_length;
key_length= other.key_length;
unireg_check= other.unireg_check;
interval= other.interval;
charset= other.charset;
srid= other.srid;
geom_type= other.geom_type;
pack_flag= other.pack_flag;
}
// Replace the entire value by another definition // Replace the entire value by another definition
void set_column_definition(const Column_definition *def) void set_column_definition(const Column_definition *def)
{ {
...@@ -4127,12 +4144,14 @@ class Spvar_definition: public Column_definition ...@@ -4127,12 +4144,14 @@ class Spvar_definition: public Column_definition
class Qualified_column_ident *m_column_type_ref; // for %TYPE class Qualified_column_ident *m_column_type_ref; // for %TYPE
class Table_ident *m_table_rowtype_ref; // for table%ROWTYPE class Table_ident *m_table_rowtype_ref; // for table%ROWTYPE
bool m_cursor_rowtype_ref; // for cursor%ROWTYPE bool m_cursor_rowtype_ref; // for cursor%ROWTYPE
uint m_cursor_rowtype_offset; // for cursor%ROWTYPE
Row_definition_list *m_row_field_definitions; // for ROW Row_definition_list *m_row_field_definitions; // for ROW
public: public:
Spvar_definition() Spvar_definition()
:m_column_type_ref(NULL), :m_column_type_ref(NULL),
m_table_rowtype_ref(NULL), m_table_rowtype_ref(NULL),
m_cursor_rowtype_ref(false), m_cursor_rowtype_ref(false),
m_cursor_rowtype_offset(0),
m_row_field_definitions(NULL) m_row_field_definitions(NULL)
{ } { }
Spvar_definition(THD *thd, Field *field) Spvar_definition(THD *thd, Field *field)
...@@ -4140,6 +4159,7 @@ class Spvar_definition: public Column_definition ...@@ -4140,6 +4159,7 @@ class Spvar_definition: public Column_definition
m_column_type_ref(NULL), m_column_type_ref(NULL),
m_table_rowtype_ref(NULL), m_table_rowtype_ref(NULL),
m_cursor_rowtype_ref(false), m_cursor_rowtype_ref(false),
m_cursor_rowtype_offset(0),
m_row_field_definitions(NULL) m_row_field_definitions(NULL)
{ } { }
const Type_handler *type_handler() const const Type_handler *type_handler() const
...@@ -4168,9 +4188,15 @@ class Spvar_definition: public Column_definition ...@@ -4168,9 +4188,15 @@ class Spvar_definition: public Column_definition
{ {
m_table_rowtype_ref= ref; m_table_rowtype_ref= ref;
} }
void set_cursor_rowtype_ref(bool ref)
uint cursor_rowtype_offset() const
{
return m_cursor_rowtype_offset;
}
void set_cursor_rowtype_ref(bool ref, uint offset)
{ {
m_cursor_rowtype_ref= ref; m_cursor_rowtype_ref= ref;
m_cursor_rowtype_offset= offset;
} }
/* /*
......
This diff is collapsed.
...@@ -3195,26 +3195,34 @@ struct LEX: public Query_tables_list ...@@ -3195,26 +3195,34 @@ struct LEX: public Query_tables_list
void sp_variable_declarations_init(THD *thd, int nvars); void sp_variable_declarations_init(THD *thd, int nvars);
bool sp_variable_declarations_finalize(THD *thd, int nvars, bool sp_variable_declarations_finalize(THD *thd, int nvars,
const Column_definition *cdef, const Column_definition *cdef,
Row_definition_list *row,
Item *def); Item *def);
bool sp_variable_declarations_finalize(THD *thd, int nvars, bool sp_variable_declarations_set_default(THD *thd, int nvars, Item *def);
const Column_definition *cdef,
Item *def)
{
return sp_variable_declarations_finalize(thd, nvars, cdef, NULL, def);
}
bool sp_variable_declarations_row_finalize(THD *thd, int nvars, bool sp_variable_declarations_row_finalize(THD *thd, int nvars,
Row_definition_list *row, Row_definition_list *row,
Item *def) Item *def);
{
return sp_variable_declarations_finalize(thd, nvars, NULL, row, def);
}
bool sp_variable_declarations_with_ref_finalize(THD *thd, int nvars, bool sp_variable_declarations_with_ref_finalize(THD *thd, int nvars,
Qualified_column_ident *col, Qualified_column_ident *col,
Item *def); Item *def);
bool sp_variable_declarations_rowtype_finalize(THD *thd, int nvars, bool sp_variable_declarations_rowtype_finalize(THD *thd, int nvars,
Qualified_column_ident *, Qualified_column_ident *,
Item *def); Item *def);
bool sp_variable_declarations_cursor_rowtype_finalize(THD *thd, int nvars,
uint offset,
Item *def);
bool sp_variable_declarations_table_rowtype_finalize(THD *thd, int nvars,
const LEX_CSTRING &db,
const LEX_CSTRING &table,
Item *def);
bool sp_variable_declarations_column_type_finalize(THD *thd, int nvars,
Qualified_column_ident *ref,
Item *def);
bool sp_variable_declarations_vartype_finalize(THD *thd, int nvars,
const LEX_CSTRING &name,
Item *def);
bool sp_variable_declarations_copy_type_finalize(THD *thd, int nvars,
const Column_definition &ref,
Row_definition_list *fields,
Item *def);
bool sp_handler_declaration_init(THD *thd, int type); bool sp_handler_declaration_init(THD *thd, int type);
bool sp_handler_declaration_finalize(THD *thd, int type); bool sp_handler_declaration_finalize(THD *thd, int type);
......
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