1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-36390: Minor refactoring of the method get_expr_query at the classes sp_instr_cpush/sp_instr_cursor_copy_struct

Duplicated code from methods
  sp_instr_cpush::get_expr_query
  sp_instr_cursor_copy_struct::get_expr_query
were extracted to the standalone function get_cursor_query

Additionally, added correct parsing of a cursor definition with
a new line or TAB instead of the space immediately after FOR/IS.
This commit is contained in:
Dmitry Shulga
2025-03-27 18:02:37 +07:00
committed by Alexander Barkov
parent 7b3e02e1aa
commit c76d17a917
3 changed files with 211 additions and 20 deletions

View File

@@ -2795,5 +2795,96 @@ SELECT f1();
DROP FUNCTION f1;
DROP TABLE t1;
--echo #
--echo # MDEV-36390: Minor refactoring of the method get_expr_query at the classes sp_instr_cpush/sp_instr_cursor_copy_struct
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
--delimiter $
CREATE OR REPLACE PROCEDURE p1()
BEGIN
DECLARE va INT;
# Check that the TAB character after the clause FOR is skipped and
# the body of cursor is remembered correctly for subsequent re-parsing
DECLARE cur CURSOR FOR SELECT a FROM t1;
OPEN cur;
FETCH cur INTO va;
SELECT va;
CLOSE cur;
END;
$
CREATE OR REPLACE PROCEDURE p2()
BEGIN
DECLARE va INT;
# Check that the newline character after the clause FOR is skipped and
# the body of cursor is remembered correctly for subsequent re-parsing
DECLARE cur CURSOR FOR
SELECT a FROM t1;
OPEN cur;
FETCH cur INTO va;
SELECT va;
CLOSE cur;
END;
$
CREATE OR REPLACE PROCEDURE p3()
BEGIN
DECLARE va INT;
# Check that C-style comment and the newline character after
# the clause FOR is skipped and the body of cursor is remembered
# correctly for subsequent re-parsing
DECLARE cur CURSOR FOR /* Explicit comment */
SELECT a FROM t1;
OPEN cur;
FETCH cur INTO va;
SELECT va;
CLOSE cur;
END;
$
CREATE OR REPLACE PROCEDURE p4()
BEGIN
DECLARE va INT;
# Check that SQL-style comment and the newline character after
# the clause FOR is skipped and the body of cursor is remembered
# correctly for subsequent re-parsing
DECLARE cur CURSOR FOR -- Explicit comment
SELECT a FROM t1;
OPEN cur;
FETCH cur INTO va;
SELECT va;
CLOSE cur;
END;
$
--delimiter ;
CALL p1();
CALL p2();
CALL p3();
CALL p4();
ALTER TABLE t1 COMMENT 'The Comment 1';
--echo # The following statements will run re-parsing of
--echo # cursor declaration statements inside the stored
--echo # procedures p1, p2, p3, p4.
CALL p1();
CALL p2();
CALL p3();
CALL p4();
--echo # Clean up
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP PROCEDURE p3;
DROP PROCEDURE p4;
DROP TABLE t1;
SET sql_mode = default;
--enable_ps2_protocol