`processlist_info` longtext CHARACTER SET utf8 DEFAULT NULL,
`processlist_info_binary` blob DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
DROP PROCEDURE p1;
#
# TYPE OF + Table structure change
# Data type for both a0 and a1 is chosen in the very beginning
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a0 TYPE OF t1.a;
ALTER TABLE t1 MODIFY a VARCHAR(10); -- This does not affect a1
BEGIN
DECLARE a1 TYPE OF t1.a;
CREATE TABLE t2 AS SELECT a0, a1;
SHOW CREATE TABLE t2;
DROP TABLE t2;
END;
END
$$
CREATE TABLE t1 (a INT);
CALL p1;
Table Create Table
t2 CREATE TABLE `t2` (
`a0` int(11) DEFAULT NULL,
`a1` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
DROP PROCEDURE p1;
#
# TYPE OF in parameters
#
CREATE TABLE t1 (a VARCHAR(10));
CREATE DATABASE test1;
CREATE TABLE test1.t1 (b SMALLINT);
CREATE PROCEDURE p1(a TYPE OF t1.a, b TYPE OF test1.t1.b)
BEGIN
CREATE TABLE t2 AS SELECT a, b;
END;
$$
CALL p1('test', 123);
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` varchar(10) DEFAULT NULL,
`b` smallint(6) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
a b
test 123
DROP TABLE t2;
DROP PROCEDURE p1;
DROP TABLE test1.t1;
DROP DATABASE test1;
DROP TABLE t1;
#
# TYPE OF in a stored function variables and arguments
#
CREATE TABLE t1 (a INT);
CREATE FUNCTION f1 (prm TYPE OF t1.a) RETURNS INT
BEGIN
DECLARE a TYPE OF t1.a DEFAULT prm;
RETURN a;
END;
$$
SELECT f1(20);
f1(20)
20
DROP FUNCTION f1;
DROP TABLE t1;
#
# TYPE OF in function RETURN clause is not supported yet
#
CREATE FUNCTION f1() RETURN TYPE OF t1.a
BEGIN
RETURN 0;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'RETURN TYPE OF t1.a
BEGIN
RETURN 0;
END' at line 1
#
# Using TYPE OF variables as FETCH targets
#
CREATE TABLE t1 (a INT, b VARCHAR(10),c DATETIME(3));
INSERT INTO t1 VALUES (1,'b1','2001-01-01 10:20:30.123');
INSERT INTO t1 VALUES (2,'b2','2001-01-02 10:20:30.123');
CREATE TABLE t2 LIKE t1;
CREATE PROCEDURE p1()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE v_a TYPE OF t1.a;
DECLARE v_b TYPE OF t1.b;
DECLARE v_c TYPE OF t1.c;
DECLARE c CURSOR FOR SELECT a,b,c FROM t1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=TRUE;
OPEN c;
read_loop: LOOP
FETCH c INTO v_a, v_b, v_c;
IF done THEN
LEAVE read_loop;
END IF;
INSERT INTO t2 (a,b,c) VALUES (v_a, v_b, v_c);
END LOOP;
CLOSE c;
END;
$$
CALL p1();
SELECT * FROM t2;
a b c
1 b1 2001-01-01 10:20:30.123
2 b2 2001-01-02 10:20:30.123
DROP TABLE t2;
DROP PROCEDURE p1;
DROP TABLE t1;
#
# Using TYPE OF variables as SELECT INTO targets
#
CREATE TABLE t1 (a INT, b VARCHAR(10),c DATETIME(3));
INSERT INTO t1 VALUES (1,'b1','2001-01-01 10:20:30.123');
CREATE PROCEDURE p1()
BEGIN
DECLARE v_a TYPE OF t1.a;
DECLARE v_b TYPE OF t1.b;
DECLARE v_c TYPE OF t1.c;
SELECT * FROM t1 INTO v_a, v_b, v_c;
SELECT v_a, v_b, v_c;
END;
$$
CALL p1();
v_a v_b v_c
1 b1 2001-01-01 10:20:30.123
DROP PROCEDURE p1;
DROP TABLE t1;
#
# End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types