mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
MDEV-16311 Server crash when using a NAME_CONST() with a CURSOR
Problem:
The problem was most likely introduced by a fix for MDEV-11597
(commit 5f0c31f928
) which removed
the assignment "killed= KILL_BAD_DATA" from THD::raise_condition().
Before MDEV-11597, sp_head::execute() tested thd->killed after
looping through the SP instructions and exited with an error
if thd->killed is set. After MDEV-11597, sp_head::execute()
stopped to notice errors and set the OK status on top of the
error status, which crashed on assert.
Fix:
Making sp_cursor::fetch() return -1 if server_side_cursor->fetch(1)
left an error in the diagnostics area. This makes the statement
"err_status= i->execute(thd, &ip)" in sp_head::execute() set the
error code and correctly break the SP instruction loop and
return on error without setting the OK status.
This commit is contained in:
parent
8662015c90
commit
23ced2f846
3 changed files with 45 additions and 0 deletions
|
@ -8365,3 +8365,20 @@ ERROR HY000: Window function is allowed only in SELECT list and ORDER BY clause
|
|||
CALL p1(SUM(1));
|
||||
ERROR HY000: Invalid use of group function
|
||||
DROP PROCEDURE p1;
|
||||
#
|
||||
# MDEV-16311 Server crash when using a NAME_CONST() with a CURSOR
|
||||
#
|
||||
SET sql_mode=STRICT_ALL_TABLES;
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES (10);
|
||||
BEGIN NOT ATOMIC
|
||||
DECLARE a INT;
|
||||
DECLARE c CURSOR FOR SELECT NAME_CONST('x','y') FROM t1;
|
||||
OPEN c;
|
||||
FETCH c INTO a;
|
||||
CLOSE c;
|
||||
END;
|
||||
$$
|
||||
ERROR 22007: Incorrect integer value: 'y' for column 'a' at row 1
|
||||
DROP TABLE t1;
|
||||
SET sql_mode=DEFAULT;
|
||||
|
|
|
@ -9879,3 +9879,25 @@ CALL p1(ROW_NUMBER() OVER ());
|
|||
--error ER_INVALID_GROUP_FUNC_USE
|
||||
CALL p1(SUM(1));
|
||||
DROP PROCEDURE p1;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-16311 Server crash when using a NAME_CONST() with a CURSOR
|
||||
--echo #
|
||||
|
||||
SET sql_mode=STRICT_ALL_TABLES;
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES (10);
|
||||
DELIMITER $$;
|
||||
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
|
||||
BEGIN NOT ATOMIC
|
||||
DECLARE a INT;
|
||||
DECLARE c CURSOR FOR SELECT NAME_CONST('x','y') FROM t1;
|
||||
OPEN c;
|
||||
FETCH c INTO a;
|
||||
CLOSE c;
|
||||
END;
|
||||
$$
|
||||
DELIMITER ;$$
|
||||
DROP TABLE t1;
|
||||
SET sql_mode=DEFAULT;
|
||||
|
|
|
@ -509,9 +509,15 @@ int sp_cursor::fetch(THD *thd, List<sp_variable> *vars)
|
|||
|
||||
result.set_spvar_list(vars);
|
||||
|
||||
DBUG_ASSERT(!thd->is_error());
|
||||
|
||||
/* Attempt to fetch one row */
|
||||
if (server_side_cursor->is_open())
|
||||
{
|
||||
server_side_cursor->fetch(1);
|
||||
if (thd->is_error())
|
||||
return -1; // e.g. data type conversion failed
|
||||
}
|
||||
|
||||
/*
|
||||
If the cursor was pointing after the last row, the fetch will
|
||||
|
|
Loading…
Add table
Reference in a new issue