Skip to content

Commit 4a7e337

Browse files
committed
MDEV-28963 Incompatible data type assignment through SP vars is not consistent with columns
1 parent c4bfb61 commit 4a7e337

26 files changed

+1801
-29
lines changed

mysql-test/include/type_mix_incompatible.inc

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ SET @target_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
1010
AND TABLE_NAME='t1'
1111
AND TABLE_SCHEMA='test');
1212

13+
let $source_type= `(SELECT @source_type)`;
14+
let $target_type= `(SELECT @target_type)`;
15+
1316
CREATE TABLE t2 LIKE t1;
1417
ALTER TABLE t2 ADD id INT NOT NULL PRIMARY KEY FIRST;
1518
INSERT INTO t2 VALUES (1,DEFAULT,DEFAULT);
@@ -134,4 +137,122 @@ EXECUTE IMMEDIATE @alter;
134137

135138
DROP TABLE t3;
136139
DROP TABLE t2;
140+
141+
#
142+
# MDEV-28963 Incompatible data type assignment through SP vars is not consistent with columns
143+
#
144+
145+
#
146+
# SP local variables
147+
#
148+
DELIMITER $$;
149+
eval CREATE PROCEDURE p1()
150+
BEGIN
151+
DECLARE src $source_type DEFAULT NULL;
152+
DECLARE dst $target_type DEFAULT NULL;
153+
SET dst=src;
154+
END;
155+
$$
156+
DELIMITER ;$$
157+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
158+
CALL p1;
159+
DROP PROCEDURE p1;
160+
161+
#
162+
# SP IN parameters
163+
#
164+
165+
--eval CREATE FUNCTION f1(a $target_type) RETURNS INT RETURN NULL;
166+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
167+
SELECT f1((SELECT source FROM t1 ORDER BY source LIMIT 1));
168+
DROP FUNCTION f1;
169+
170+
--eval CREATE PROCEDURE p1(a $target_type) BEGIN END;
171+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
172+
CALL p1((SELECT source FROM t1 ORDER BY source LIMIT 1));
173+
DROP PROCEDURE p1;
174+
175+
#
176+
# SP OUT parameters
177+
#
178+
179+
DELIMITER $$;
180+
eval CREATE PROCEDURE p1(OUT dst $target_type)
181+
BEGIN
182+
DECLARE src $source_type DEFAULT NULL;
183+
SET dst=src;
184+
END;
185+
$$
186+
eval CREATE PROCEDURE p2()
187+
BEGIN
188+
DECLARE dst $target_type DEFAULT NULL;
189+
CALL p1(dst);
190+
END;
191+
$$
192+
DELIMITER ;$$
193+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
194+
CALL p2();
195+
SHOW WARNINGS;
196+
DROP PROCEDURE p2;
197+
DROP PROCEDURE p1;
198+
199+
200+
#
201+
# SF RETURN
202+
#
203+
204+
DELIMITER $$;
205+
eval CREATE FUNCTION f1() RETURNS $target_type
206+
BEGIN
207+
DECLARE rc $source_type DEFAULT NULL;
208+
RETURN rc;
209+
END;
210+
$$
211+
DELIMITER ;$$
212+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
213+
SELECT f1();
214+
DROP FUNCTION f1;
215+
216+
#
217+
# Cursor IN parameters
218+
#
219+
220+
DELIMITER $$;
221+
eval CREATE PROCEDURE p1()
222+
BEGIN
223+
DECLARE src $source_type DEFAULT NULL;
224+
DECLARE cur1 CURSOR(t $target_type) FOR SELECT * FROM t1 WHERE target=t;
225+
OPEN cur1(src);
226+
CLOSE cur1;
227+
END;
228+
$$
229+
DELIMITER ;$$
230+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
231+
CALL p1();
232+
DROP PROCEDURE p1;
233+
234+
#
235+
# FETCH
236+
#
237+
238+
CREATE TABLE t2 LIKE t1;
239+
INSERT INTO t2 VALUES ();
240+
241+
DELIMITER $$;
242+
eval CREATE PROCEDURE p1()
243+
BEGIN
244+
DECLARE dst $target_type DEFAULT NULL;
245+
DECLARE cur2 CURSOR FOR SELECT source FROM t2 ORDER BY source LIMIT 1;
246+
OPEN cur2;
247+
FETCH cur2 INTO dst;
248+
CLOSE cur2;
249+
END;
250+
$$
251+
DELIMITER ;$$
252+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
253+
CALL p1();
254+
DROP PROCEDURE p1;
255+
256+
DROP TABLE t2;
257+
137258
--echo # End of type_store_assignment_incompatible.inc

mysql-test/main/alter_table_combinations.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function
226226
SELECT * FROM v1;
227227
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
228228
UPDATE t2 SET f = f + 10;
229-
ERROR 42S22: Unknown column 'd' in 'OLD'
229+
ERROR 42S22: Unknown column 'd' in 'NEW'
230230
CALL sp1();
231231
ERROR 42S22: Unknown column 'd' in 'field list'
232232
DROP TRIGGER trg1;

mysql-test/main/sp-row.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RETURN a;
2020
END;
2121
$$
2222
SELECT f1(ROW(10,20));
23-
ERROR 21000: Operand should contain 1 column(s)
23+
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
2424
DROP FUNCTION f1;
2525
#
2626
# ROW as an SP parameter
@@ -236,7 +236,7 @@ SELECT f1(a);
236236
END;
237237
$$
238238
CALL p1();
239-
ERROR 21000: Operand should contain 1 column(s)
239+
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
240240
DROP PROCEDURE p1;
241241
DROP FUNCTION f1;
242242
#
@@ -286,7 +286,7 @@ RETURN rec;
286286
END;
287287
$$
288288
SELECT f1(10);
289-
ERROR 21000: Operand should contain 1 column(s)
289+
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
290290
DROP FUNCTION f1;
291291
#
292292
# Using the entire ROW in SELECT..CREATE

mysql-test/main/sp-row.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ BEGIN
2727
END;
2828
$$
2929
DELIMITER ;$$
30-
--error ER_OPERAND_COLUMNS
30+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
3131
SELECT f1(ROW(10,20));
3232
DROP FUNCTION f1;
3333

@@ -307,7 +307,7 @@ BEGIN
307307
END;
308308
$$
309309
DELIMITER ;$$
310-
--error ER_OPERAND_COLUMNS
310+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
311311
CALL p1();
312312
DROP PROCEDURE p1;
313313
DROP FUNCTION f1;
@@ -393,7 +393,7 @@ BEGIN
393393
END;
394394
$$
395395
DELIMITER ;$$
396-
--error ER_OPERAND_COLUMNS
396+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
397397
SELECT f1(10);
398398
DROP FUNCTION f1;
399399

mysql-test/main/sp-vars.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,11 @@ BEGIN
10261026
SELECT arg;
10271027
END|
10281028
CALL p1((1, 2));
1029-
ERROR 21000: Operand should contain 1 column(s)
1029+
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
10301030
CALL p1((SELECT * FROM t1 LIMIT 1));
1031-
ERROR 21000: Operand should contain 1 column(s)
1031+
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
10321032
CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));
1033-
ERROR 21000: Operand should contain 1 column(s)
1033+
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
10341034
DROP PROCEDURE p1;
10351035
DROP TABLE t1;
10361036

mysql-test/main/sp-vars.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,13 @@ BEGIN
12211221
END|
12221222
delimiter ;|
12231223

1224-
--error ER_OPERAND_COLUMNS
1224+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
12251225
CALL p1((1, 2));
12261226

1227-
--error ER_OPERAND_COLUMNS
1227+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
12281228
CALL p1((SELECT * FROM t1 LIMIT 1));
12291229

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

12331233
#

mysql-test/main/sp.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ return i+1|
255255
call sub1("sub1a", (select 7))|
256256
call sub1("sub1b", (select max(i) from t2))|
257257
call sub1("sub1c", (select i,d from t2 limit 1))|
258-
ERROR 21000: Operand should contain 1 column(s)
258+
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
259259
call sub1("sub1d", (select 1 from (select 1) a))|
260260
call sub2("sub2")|
261261
select * from t1 order by id|

mysql-test/main/sp.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ create function sub3(i int) returns int deterministic
386386

387387
call sub1("sub1a", (select 7))|
388388
call sub1("sub1b", (select max(i) from t2))|
389-
--error ER_OPERAND_COLUMNS
389+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
390390
call sub1("sub1c", (select i,d from t2 limit 1))|
391391
call sub1("sub1d", (select 1 from (select 1) a))|
392392
call sub2("sub2")|

0 commit comments

Comments
 (0)