MDEV-26836: ROW_NUMBER differs from the number in the error message upon

ER_WARN_DATA_OUT_OF_RANGE

Analysis: value for row_number is hard coded into push_warning_printf() to 1.
Fix: make push_warning_printf() use m_current_row_for_warning instead of 1.
This commit is contained in:
Rucha Deodhar 2021-10-15 15:52:16 +05:30
parent a6cf8b34a8
commit 9ab0d07e10
8 changed files with 45 additions and 13 deletions

View file

@ -1671,3 +1671,21 @@ SELECT @rnum, @msg, @err;
@rnum @msg @err
3 Data truncated for column 'a' at row 3 1265
DROP TABLE t1;
#
# ROW_NUMBER differs from the number in the error message upon
# ER_WARN_DATA_OUT_OF_RANGE
#
CREATE TABLE t (a INT);
INSERT INTO t VALUES (1),(2);
SELECT CAST(a AS DECIMAL(2,2)) AS f FROM t;
f
0.99
0.99
Warnings:
Warning 1264 Out of range value for column 'f' at row 1
Warning 1264 Out of range value for column 'f' at row 2
GET DIAGNOSTICS CONDITION 2 @n= ROW_NUMBER, @m = MESSAGE_TEXT;
SELECT @n, @m;
@n @m
2 Out of range value for column 'f' at row 2
DROP TABLE t;

View file

@ -1552,3 +1552,16 @@ GET DIAGNOSTICS CONDITION 2 @rnum = ROW_NUMBER, @msg = MESSAGE_TEXT, @err = MYSQ
SELECT @rnum, @msg, @err;
DROP TABLE t1;
--echo #
--echo # ROW_NUMBER differs from the number in the error message upon
--echo # ER_WARN_DATA_OUT_OF_RANGE
--echo #
CREATE TABLE t (a INT);
INSERT INTO t VALUES (1),(2);
SELECT CAST(a AS DECIMAL(2,2)) AS f FROM t;
GET DIAGNOSTICS CONDITION 2 @n= ROW_NUMBER, @m = MESSAGE_TEXT;
SELECT @n, @m;
DROP TABLE t;

View file

@ -1152,13 +1152,13 @@ CAST(str AS DECIMAL(38,0))
Level Code Message
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1292 Truncated incorrect DECIMAL value: '1e111111111111111111111'
Warning 1264 Out of range value for column 'CAST(str AS DECIMAL(38,0))' at row 1
Warning 1264 Out of range value for column 'CAST(str AS DECIMAL(38,0))' at row 2
CAST(CONCAT(str,'garbage') AS DECIMAL(38,0))
99999999999999999999999999999999999999
Level Code Message
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1292 Truncated incorrect DECIMAL value: '1e111111111111111111111garbage'
Warning 1264 Out of range value for column 'CAST(CONCAT(str,'garbage') AS DECIMAL(38,0))' at row 1
Warning 1264 Out of range value for column 'CAST(CONCAT(str,'garbage') AS DECIMAL(38,0))' at row 2
DROP TABLE t1;
#
# End of 10.2 tests

View file

@ -1458,8 +1458,8 @@ cast(a as DECIMAL(3,2))
9.99
Warnings:
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 2
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 3
select cast(a as DECIMAL(3,2)), count(*)
from (select 11.1233 as a
UNION select 11.1234
@ -1470,8 +1470,8 @@ cast(a as DECIMAL(3,2)) count(*)
Warnings:
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 2
Warning 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 3
create table t1 (s varchar(100));
insert into t1 values (0.00000000010000000000000000364321973154977415791655470655996396089904010295867919921875);
drop table t1;

View file

@ -3322,9 +3322,9 @@ NULL NULL 1
-3333.33 -3333.3333 30
Warnings:
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 1
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 2
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 1
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 3
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_double` as decimal(37,2)) AS `CAST(my_double AS DECIMAL(37,2))`,`t1_values`.`my_double` AS `my_double`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci

View file

@ -3323,9 +3323,9 @@ NULL NULL 1
-3333.33 -3333.3333 30
Warnings:
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 1
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 2
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 1
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 3
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_double` as decimal(37,2)) AS `CAST(my_double AS DECIMAL(37,2))`,`t1_values`.`my_double` AS `my_double`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci

View file

@ -3323,9 +3323,9 @@ NULL NULL 1
-3333.33 -3333.3333 30
Warnings:
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 1
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 2
Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 1
Warning 1264 Out of range value for column 'CAST(my_double AS DECIMAL(37,2))' at row 3
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_double` as decimal(37,2)) AS `CAST(my_double AS DECIMAL(37,2))`,`t1_values`.`my_double` AS `my_double`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci

View file

@ -1004,7 +1004,8 @@ err:
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_DATA_OUT_OF_RANGE,
ER_THD(thd, ER_WARN_DATA_OUT_OF_RANGE),
name.str, 1L);
name.str,
thd->get_stmt_da()->current_row_for_warning());
return dec;
}