Skip to content
Permalink
Browse files
MDEV-28963 Incompatible data type assignment through SP vars is not c…
…onsistent with columns
  • Loading branch information
abarkov committed Jun 27, 2022
1 parent c4bfb61 commit 4a7e337
Show file tree
Hide file tree
Showing 26 changed files with 1,801 additions and 29 deletions.
@@ -10,6 +10,9 @@ SET @target_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
AND TABLE_NAME='t1'
AND TABLE_SCHEMA='test');

let $source_type= `(SELECT @source_type)`;
let $target_type= `(SELECT @target_type)`;

CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 ADD id INT NOT NULL PRIMARY KEY FIRST;
INSERT INTO t2 VALUES (1,DEFAULT,DEFAULT);
@@ -134,4 +137,122 @@ EXECUTE IMMEDIATE @alter;

DROP TABLE t3;
DROP TABLE t2;

#
# MDEV-28963 Incompatible data type assignment through SP vars is not consistent with columns
#

#
# SP local variables
#
DELIMITER $$;
eval CREATE PROCEDURE p1()
BEGIN
DECLARE src $source_type DEFAULT NULL;
DECLARE dst $target_type DEFAULT NULL;
SET dst=src;
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1;
DROP PROCEDURE p1;

#
# SP IN parameters
#

--eval CREATE FUNCTION f1(a $target_type) RETURNS INT RETURN NULL;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT f1((SELECT source FROM t1 ORDER BY source LIMIT 1));
DROP FUNCTION f1;

--eval CREATE PROCEDURE p1(a $target_type) BEGIN END;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1((SELECT source FROM t1 ORDER BY source LIMIT 1));
DROP PROCEDURE p1;

#
# SP OUT parameters
#

DELIMITER $$;
eval CREATE PROCEDURE p1(OUT dst $target_type)
BEGIN
DECLARE src $source_type DEFAULT NULL;
SET dst=src;
END;
$$
eval CREATE PROCEDURE p2()
BEGIN
DECLARE dst $target_type DEFAULT NULL;
CALL p1(dst);
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p2();
SHOW WARNINGS;
DROP PROCEDURE p2;
DROP PROCEDURE p1;


#
# SF RETURN
#

DELIMITER $$;
eval CREATE FUNCTION f1() RETURNS $target_type
BEGIN
DECLARE rc $source_type DEFAULT NULL;
RETURN rc;
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT f1();
DROP FUNCTION f1;

#
# Cursor IN parameters
#

DELIMITER $$;
eval CREATE PROCEDURE p1()
BEGIN
DECLARE src $source_type DEFAULT NULL;
DECLARE cur1 CURSOR(t $target_type) FOR SELECT * FROM t1 WHERE target=t;
OPEN cur1(src);
CLOSE cur1;
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1();
DROP PROCEDURE p1;

#
# FETCH
#

CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES ();

DELIMITER $$;
eval CREATE PROCEDURE p1()
BEGIN
DECLARE dst $target_type DEFAULT NULL;
DECLARE cur2 CURSOR FOR SELECT source FROM t2 ORDER BY source LIMIT 1;
OPEN cur2;
FETCH cur2 INTO dst;
CLOSE cur2;
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1();
DROP PROCEDURE p1;

DROP TABLE t2;

--echo # End of type_store_assignment_incompatible.inc
@@ -226,7 +226,7 @@ Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function
SELECT * FROM v1;
ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
UPDATE t2 SET f = f + 10;
ERROR 42S22: Unknown column 'd' in 'OLD'
ERROR 42S22: Unknown column 'd' in 'NEW'
CALL sp1();
ERROR 42S22: Unknown column 'd' in 'field list'
DROP TRIGGER trg1;
@@ -20,7 +20,7 @@ RETURN a;
END;
$$
SELECT f1(ROW(10,20));
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
DROP FUNCTION f1;
#
# ROW as an SP parameter
@@ -236,7 +236,7 @@ SELECT f1(a);
END;
$$
CALL p1();
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
DROP PROCEDURE p1;
DROP FUNCTION f1;
#
@@ -286,7 +286,7 @@ RETURN rec;
END;
$$
SELECT f1(10);
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
DROP FUNCTION f1;
#
# Using the entire ROW in SELECT..CREATE
@@ -27,7 +27,7 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT f1(ROW(10,20));
DROP FUNCTION f1;

@@ -307,7 +307,7 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1();
DROP PROCEDURE p1;
DROP FUNCTION f1;
@@ -393,7 +393,7 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT f1(10);
DROP FUNCTION f1;

@@ -1026,11 +1026,11 @@ BEGIN
SELECT arg;
END|
CALL p1((1, 2));
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
CALL p1((SELECT * FROM t1 LIMIT 1));
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
DROP PROCEDURE p1;
DROP TABLE t1;

@@ -1221,13 +1221,13 @@ BEGIN
END|
delimiter ;|

--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1((1, 2));

--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1((SELECT * FROM t1 LIMIT 1));

--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));

#
@@ -255,7 +255,7 @@ return i+1|
call sub1("sub1a", (select 7))|
call sub1("sub1b", (select max(i) from t2))|
call sub1("sub1c", (select i,d from t2 limit 1))|
ERROR 21000: Operand should contain 1 column(s)
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
call sub1("sub1d", (select 1 from (select 1) a))|
call sub2("sub2")|
select * from t1 order by id|
@@ -386,7 +386,7 @@ create function sub3(i int) returns int deterministic

call sub1("sub1a", (select 7))|
call sub1("sub1b", (select max(i) from t2))|
--error ER_OPERAND_COLUMNS
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
call sub1("sub1c", (select i,d from t2 limit 1))|
call sub1("sub1d", (select 1 from (select 1) a))|
call sub2("sub2")|

0 comments on commit 4a7e337

Please sign in to comment.