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 15: ELSIF vs ELSEIF

Also, moving tests for Oracle keywords in sql_mode=DEFAULT
from "parser.test" to a better place "keywords.test".
  • Loading branch information
Alexander Barkov committed Apr 5, 2017
1 parent a83d0ae commit 6cd24d1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/r/keywords.result
Expand Up @@ -331,3 +331,18 @@ DROP TABLE OTHERS;
#
CREATE TABLE immediate (immediate int);
DROP TABLE immediate;
#
# MDEV-10142 Pluggable parser
# Testing keywords that were added into lex.h for Oracle compatibility
# that are not reserved keywords in MariaDB
#
CREATE TABLE clob (clob int);
DROP TABLE clob;
CREATE TABLE elsif (elsif INT);
DROP TABLE elsif;
CREATE TABLE exception (exception INT);
DROP TABLE exception;
CREATE TABLE raw (raw int);
DROP TABLE raw;
CREATE TABLE varchar2 (varchar2 int);
DROP TABLE varchar2;
14 changes: 14 additions & 0 deletions mysql-test/suite/compat/oracle/r/sp.result
Expand Up @@ -326,6 +326,20 @@ CREATE TABLE begin (begin INT);
DROP TABLE begin;
CREATE TABLE end (end INT);
DROP TABLE end;
# Testing ELSIF
CREATE FUNCTION f1(a INT) RETURN CLOB
AS
BEGIN
IF a=1 THEN RETURN 'a is 1';
ELSIF a=2 THEN RETURN 'a is 2';
ELSE RETURN 'a is unknown';
END IF;
END;
/
SELECT f1(2) FROM DUAL;
f1(2)
a is 2
DROP FUNCTION f1;
# Testing top-level declarations
CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10))
AS
Expand Down
16 changes: 16 additions & 0 deletions mysql-test/suite/compat/oracle/t/sp.test
Expand Up @@ -342,6 +342,22 @@ DROP TABLE begin;
CREATE TABLE end (end INT);
DROP TABLE end;

--echo # Testing ELSIF
DELIMITER /;
CREATE FUNCTION f1(a INT) RETURN CLOB
AS
BEGIN
IF a=1 THEN RETURN 'a is 1';
ELSIF a=2 THEN RETURN 'a is 2';
ELSE RETURN 'a is unknown';
END IF;
END;
/
DELIMITER ;/
SELECT f1(2) FROM DUAL;
DROP FUNCTION f1;



--echo # Testing top-level declarations
DELIMITER /;
Expand Down
21 changes: 21 additions & 0 deletions mysql-test/t/keywords.test
Expand Up @@ -220,3 +220,24 @@ DROP TABLE OTHERS;

CREATE TABLE immediate (immediate int);
DROP TABLE immediate;

--echo #
--echo # MDEV-10142 Pluggable parser
--echo # Testing keywords that were added into lex.h for Oracle compatibility
--echo # that are not reserved keywords in MariaDB
--echo #

CREATE TABLE clob (clob int);
DROP TABLE clob;

CREATE TABLE elsif (elsif INT);
DROP TABLE elsif;

CREATE TABLE exception (exception INT);
DROP TABLE exception;

CREATE TABLE raw (raw int);
DROP TABLE raw;

CREATE TABLE varchar2 (varchar2 int);
DROP TABLE varchar2;
1 change: 1 addition & 0 deletions sql/lex.h
Expand Up @@ -203,6 +203,7 @@ static SYMBOL symbols[] = {
{ "EACH", SYM(EACH_SYM)},
{ "ELSE", SYM(ELSE)},
{ "ELSEIF", SYM(ELSEIF_SYM)},
{ "ELSIF", SYM(ELSIF_SYM)},
{ "ENABLE", SYM(ENABLE_SYM)},
{ "ENCLOSED", SYM(ENCLOSED)},
{ "END", SYM(END)},
Expand Down
2 changes: 2 additions & 0 deletions sql/sql_yacc.yy
Expand Up @@ -1068,6 +1068,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token EACH_SYM /* SQL-2003-R */
%token ELSE /* SQL-2003-R */
%token ELSEIF_SYM
%token ELSIF_SYM /* Oracle, reserved in PL/SQL*/
%token ENABLE_SYM
%token ENCLOSED
%token END /* SQL-2003-R */
Expand Down Expand Up @@ -14340,6 +14341,7 @@ keyword_sp:
| DUMPFILE {}
| DUPLICATE_SYM {}
| DYNAMIC_SYM {}
| ELSIF_SYM {}
| ENDS_SYM {}
| ENUM {}
| ENGINE_SYM {}
Expand Down
3 changes: 2 additions & 1 deletion sql/sql_yacc_ora.yy
Expand Up @@ -442,6 +442,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token EACH_SYM /* SQL-2003-R */
%token ELSE /* SQL-2003-R */
%token ELSEIF_SYM
%token ELSIF_SYM /* Oracle, reserved in PL/SQL*/
%token ENABLE_SYM
%token ENCLOSED
%token END /* SQL-2003-R */
Expand Down Expand Up @@ -3131,7 +3132,7 @@ sp_if:

sp_elseifs:
/* Empty */
| ELSEIF_SYM sp_if
| ELSIF_SYM sp_if
| ELSE sp_proc_stmts1
;

Expand Down

0 comments on commit 6cd24d1

Please sign in to comment.