MDEV-10411 Providing compatibility for basic PL/SQL constructs

Part 16: CURSOR declaration
This commit is contained in:
Alexander Barkov 2016-08-19 13:01:35 +04:00
commit ed19ed6a4b
3 changed files with 47 additions and 2 deletions

View file

@ -656,3 +656,24 @@ SELECT f1() FROM DUAL;
f1()
5
DROP FUNCTION f1;
# Testing CURSOR declaration
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
CREATE FUNCTION f1 RETURN INT
AS
v_a INT:=10;
CURSOR c IS SELECT a FROM t1;
BEGIN
OPEN c;
FETCH c INTO v_a;
CLOSE c;
RETURN v_a;
EXCEPTION
WHEN OTHERS THEN RETURN -1;
END;
/
SELECT f1() FROM DUAL;
f1()
1
DROP FUNCTION f1;
DROP TABLE t1;

View file

@ -711,3 +711,27 @@ END;
DELIMITER ;/
SELECT f1() FROM DUAL;
DROP FUNCTION f1;
--echo # Testing CURSOR declaration
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
DELIMITER /;
CREATE FUNCTION f1 RETURN INT
AS
v_a INT:=10;
CURSOR c IS SELECT a FROM t1;
BEGIN
OPEN c;
FETCH c INTO v_a;
CLOSE c;
RETURN v_a;
EXCEPTION
WHEN OTHERS THEN RETURN -1;
END;
/
DELIMITER ;/
SELECT f1() FROM DUAL;
DROP FUNCTION f1;
DROP TABLE t1;

View file

@ -2397,9 +2397,9 @@ sp_decl_body:
$$.vars= $$.conds= $$.curs= 0;
$$.hndlrs= 1;
}
| ident_directly_assignable CURSOR_SYM FOR_SYM sp_cursor_stmt
| CURSOR_SYM ident_directly_assignable IS sp_cursor_stmt
{
if (Lex->sp_declare_cursor(thd, $1, $4))
if (Lex->sp_declare_cursor(thd, $2, $4))
MYSQL_YYABORT;
$$.vars= $$.conds= $$.hndlrs= 0;
$$.curs= 1;