mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-16117 SP with a single FOR statement creates but further fails to load
The code in the "sp_tail" rule in sql_yacc.yy always used YYLIP->get_cpp_tok_start() as the start of the body, and did not check for possible lookahead which happens for keywords "FOR", "VALUES" and "WITH" for LALR(2) resolution in Lex_input_stream::lex_token(). In case of the lookahead token presence, get_tok_start_prev() should have been used instead of get_cpp_tok_start() as the beginning of the SP body. Change summary: This patch hides the implementation of the lookahead token completely inside Lex_input_stream. The users of Lex_input_stream now just get token-by-token transparently and should not care about lookahead any more. Now external users of Lex_input_stream are not aware of the lookahead token at all. Change details: - Moving Lex_input_stream::has_lookahead() into the "private" section. - Removing Lex_input_stream::get_tok_start_prev() and Lex_input_stream::get_cpp_start_prev(). - Fixing the external code to call get_tok_start() and get_cpp_tok_start() in all places where get_tok_start_prev() and get_cpp_start_prev() where used. - Adding a test for has_lookahead() right inside get_tok_start() and get_cpp_tok_start(). If there is a lookahead token, these methods now return the position of the previous token automatically: const char *get_tok_start() { return has_lookahead() ? m_tok_start_prev : m_tok_start; } const char *get_cpp_tok_start() { return has_lookahead() ? m_cpp_tok_start_prev : m_cpp_tok_start; } - Fixing the internal code inside Lex_input_stream methods to use m_tok_start and m_cpp_tok_start directly, instead of calling get_tok_start() and get_cpp_tok_start(), to make sure to access to the *current* token position (independently of a lookahead token presence).
This commit is contained in:
@ -292,3 +292,53 @@ SELECT a, a+0;
|
||||
END;
|
||||
$$
|
||||
ERROR 22007: Illegal set 'a,b' value found during parsing
|
||||
#
|
||||
# Start of 10.3 tests
|
||||
#
|
||||
#
|
||||
# MDEV-16117 SP with a single FOR statement creates but further fails to load
|
||||
#
|
||||
CREATE PROCEDURE p1()
|
||||
FOR i IN 1..10 DO
|
||||
set @x = 5;
|
||||
END FOR;
|
||||
$$
|
||||
CALL p1;
|
||||
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='p1';
|
||||
body
|
||||
FOR i IN 1..10 DO
|
||||
set @x = 5;
|
||||
END FOR
|
||||
DROP PROCEDURE p1;
|
||||
CREATE PROCEDURE p1() WITH t1 AS (SELECT 1) SELECT 1;
|
||||
$$
|
||||
CALL p1;
|
||||
1
|
||||
1
|
||||
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='p1';
|
||||
body
|
||||
WITH t1 AS (SELECT 1) SELECT 1
|
||||
DROP PROCEDURE p1;
|
||||
CREATE PROCEDURE p1() VALUES (1);
|
||||
$$
|
||||
CALL p1;
|
||||
1
|
||||
1
|
||||
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='p1';
|
||||
body
|
||||
VALUES (1)
|
||||
DROP PROCEDURE p1;
|
||||
CREATE FUNCTION f1() RETURNS INT
|
||||
FOR i IN 1..10 DO
|
||||
RETURN 1;
|
||||
END FOR;
|
||||
$$
|
||||
SELECT f1();
|
||||
f1()
|
||||
1
|
||||
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='f1';
|
||||
body
|
||||
FOR i IN 1..10 DO
|
||||
RETURN 1;
|
||||
END FOR
|
||||
DROP FUNCTION f1;
|
||||
|
Reference in New Issue
Block a user