Skip to content

Commit

Permalink
MDEV-10411 Providing compatibility for basic PL/SQL constructs
Browse files Browse the repository at this point in the history
Part 16: CURSOR declaration
  • Loading branch information
Alexander Barkov committed Apr 5, 2017
1 parent 6cd24d1 commit ed19ed6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
21 changes: 21 additions & 0 deletions mysql-test/suite/compat/oracle/r/sp.result
Expand Up @@ -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;
24 changes: 24 additions & 0 deletions mysql-test/suite/compat/oracle/t/sp.test
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions sql/sql_yacc_ora.yy
Expand Up @@ -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;
Expand Down

0 comments on commit ed19ed6

Please sign in to comment.