mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-10411 Providing compatibility for basic PL/SQL constructs
Part 9: EXCEPTION handlers - Adding exception handler syntax: WHEN exception_name THEN statement - Adding EXCEPTION section intoi the top BEGIN..END SP block. Note, currently EXCEPTION goes in the beginning of the top BEGIN..END SP block. TODO: - add EXCEPTION section into inner blocks - move EXCEPTION to the end of the block
This commit is contained in:
@ -350,3 +350,23 @@ i
|
|||||||
4
|
4
|
||||||
i
|
i
|
||||||
3
|
3
|
||||||
|
# Testing exceptions
|
||||||
|
CREATE TABLE t1 (c1 INT);
|
||||||
|
CREATE PROCEDURE sp1 (p1 IN VARCHAR2(20), p2 OUT VARCHAR2(30))
|
||||||
|
IS
|
||||||
|
v1 INT;
|
||||||
|
BEGIN
|
||||||
|
EXCEPTION WHEN NOT FOUND THEN
|
||||||
|
BEGIN
|
||||||
|
p2 := 'def';
|
||||||
|
END;
|
||||||
|
SELECT c1 INTO v1 FROM t1;
|
||||||
|
p2 := p1;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
CALL sp1('abc', @a);
|
||||||
|
SELECT @a;
|
||||||
|
@a
|
||||||
|
def
|
||||||
|
DROP PROCEDURE sp1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
@ -377,3 +377,31 @@ BEGIN NOT ATOMIC
|
|||||||
END
|
END
|
||||||
/
|
/
|
||||||
DELIMITER ;/
|
DELIMITER ;/
|
||||||
|
|
||||||
|
|
||||||
|
--echo # Testing exceptions
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 INT);
|
||||||
|
|
||||||
|
DELIMITER /;
|
||||||
|
|
||||||
|
CREATE PROCEDURE sp1 (p1 IN VARCHAR2(20), p2 OUT VARCHAR2(30))
|
||||||
|
IS
|
||||||
|
v1 INT;
|
||||||
|
BEGIN
|
||||||
|
EXCEPTION WHEN NOT FOUND THEN
|
||||||
|
BEGIN
|
||||||
|
p2 := 'def';
|
||||||
|
END;
|
||||||
|
SELECT c1 INTO v1 FROM t1;
|
||||||
|
p2 := p1;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
|
||||||
|
DELIMITER ;/
|
||||||
|
|
||||||
|
CALL sp1('abc', @a);
|
||||||
|
SELECT @a;
|
||||||
|
|
||||||
|
DROP PROCEDURE sp1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
@ -222,6 +222,7 @@ static SYMBOL symbols[] = {
|
|||||||
{ "EXCHANGE", SYM(EXCHANGE_SYM)},
|
{ "EXCHANGE", SYM(EXCHANGE_SYM)},
|
||||||
{ "EXCLUDE", SYM(EXCLUDE_SYM)},
|
{ "EXCLUDE", SYM(EXCLUDE_SYM)},
|
||||||
{ "EXECUTE", SYM(EXECUTE_SYM)},
|
{ "EXECUTE", SYM(EXECUTE_SYM)},
|
||||||
|
{ "EXCEPTION", SYM(EXCEPTION_SYM)},
|
||||||
{ "EXISTS", SYM(EXISTS)},
|
{ "EXISTS", SYM(EXISTS)},
|
||||||
{ "EXIT", SYM(EXIT_SYM)},
|
{ "EXIT", SYM(EXIT_SYM)},
|
||||||
{ "EXPANSION", SYM(EXPANSION_SYM)},
|
{ "EXPANSION", SYM(EXPANSION_SYM)},
|
||||||
|
@ -1150,6 +1150,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
|||||||
%token EXCEPT_SYM /* SQL-2003-R */
|
%token EXCEPT_SYM /* SQL-2003-R */
|
||||||
%token EXCLUDE_SYM /* SQL-2011-N */
|
%token EXCLUDE_SYM /* SQL-2011-N */
|
||||||
%token EXECUTE_SYM /* SQL-2003-R */
|
%token EXECUTE_SYM /* SQL-2003-R */
|
||||||
|
%token EXCEPTION_SYM /* SQL-2003-N */
|
||||||
%token EXISTS /* SQL-2003-R */
|
%token EXISTS /* SQL-2003-R */
|
||||||
%token EXIT_SYM
|
%token EXIT_SYM
|
||||||
%token EXPANSION_SYM
|
%token EXPANSION_SYM
|
||||||
@ -14471,6 +14472,7 @@ keyword_sp:
|
|||||||
| EVENT_SYM {}
|
| EVENT_SYM {}
|
||||||
| EVENTS_SYM {}
|
| EVENTS_SYM {}
|
||||||
| EVERY_SYM {}
|
| EVERY_SYM {}
|
||||||
|
| EXCEPTION_SYM {}
|
||||||
| EXCHANGE_SYM {}
|
| EXCHANGE_SYM {}
|
||||||
| EXPANSION_SYM {}
|
| EXPANSION_SYM {}
|
||||||
| EXPORT_SYM {}
|
| EXPORT_SYM {}
|
||||||
|
@ -525,6 +525,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
|||||||
%token EXCEPT_SYM /* SQL-2003-R */
|
%token EXCEPT_SYM /* SQL-2003-R */
|
||||||
%token EXCLUDE_SYM /* SQL-2011-N */
|
%token EXCLUDE_SYM /* SQL-2011-N */
|
||||||
%token EXECUTE_SYM /* SQL-2003-R */
|
%token EXECUTE_SYM /* SQL-2003-R */
|
||||||
|
%token EXCEPTION_SYM /* SQL-2003-N */
|
||||||
%token EXISTS /* SQL-2003-R */
|
%token EXISTS /* SQL-2003-R */
|
||||||
%token EXIT_SYM
|
%token EXIT_SYM
|
||||||
%token EXPANSION_SYM
|
%token EXPANSION_SYM
|
||||||
@ -1330,6 +1331,7 @@ END_OF_INPUT
|
|||||||
%type <num> sp_decl_idents sp_handler_type sp_hcond_list
|
%type <num> sp_decl_idents sp_handler_type sp_hcond_list
|
||||||
%type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value
|
%type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value
|
||||||
%type <spblock> sp_decl_body sp_decl_body_list opt_sp_decl_body_list
|
%type <spblock> sp_decl_body sp_decl_body_list opt_sp_decl_body_list
|
||||||
|
%type <num> opt_exception_clause exception_handlers
|
||||||
%type <lex> sp_cursor_stmt
|
%type <lex> sp_cursor_stmt
|
||||||
%type <spname> sp_name
|
%type <spname> sp_name
|
||||||
%type <spvar> sp_param_name sp_param_name_and_type
|
%type <spvar> sp_param_name sp_param_name_and_type
|
||||||
@ -2523,7 +2525,7 @@ sp_hcond:
|
|||||||
if ($$ == NULL)
|
if ($$ == NULL)
|
||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
}
|
}
|
||||||
| SQLEXCEPTION_SYM /* All other SQLSTATEs */
|
| OTHERS_SYM /* All other SQLSTATEs */
|
||||||
{
|
{
|
||||||
$$= new (thd->mem_root) sp_condition_value(sp_condition_value::EXCEPTION);
|
$$= new (thd->mem_root) sp_condition_value(sp_condition_value::EXCEPTION);
|
||||||
if ($$ == NULL)
|
if ($$ == NULL)
|
||||||
@ -3432,6 +3434,10 @@ sp_body:
|
|||||||
}
|
}
|
||||||
opt_sp_decl_body_list
|
opt_sp_decl_body_list
|
||||||
BEGIN_SYM
|
BEGIN_SYM
|
||||||
|
opt_exception_clause
|
||||||
|
{
|
||||||
|
$2.hndlrs+= $4;
|
||||||
|
}
|
||||||
sp_proc_stmts
|
sp_proc_stmts
|
||||||
END
|
END
|
||||||
{
|
{
|
||||||
@ -3455,6 +3461,31 @@ sp_unlabeled_block_not_atomic:
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
opt_exception_clause:
|
||||||
|
/* Empty */ { $$= 0; }
|
||||||
|
| EXCEPTION_SYM exception_handlers { $$= $2; }
|
||||||
|
;
|
||||||
|
|
||||||
|
exception_handlers:
|
||||||
|
exception_handler ';' { $$= 1; }
|
||||||
|
| exception_handlers exception_handler ';' { $$= $1 + 1; }
|
||||||
|
;
|
||||||
|
|
||||||
|
exception_handler:
|
||||||
|
WHEN_SYM
|
||||||
|
{
|
||||||
|
if (Lex->sp_handler_declaration_init(thd, sp_handler::EXIT))
|
||||||
|
MYSQL_YYABORT;
|
||||||
|
}
|
||||||
|
sp_hcond_list
|
||||||
|
THEN_SYM
|
||||||
|
sp_proc_stmt
|
||||||
|
{
|
||||||
|
if (Lex->sp_handler_declaration_finalize(thd, sp_handler::EXIT))
|
||||||
|
MYSQL_YYABORT;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
loop_body:
|
loop_body:
|
||||||
sp_proc_stmts1 END LOOP_SYM
|
sp_proc_stmts1 END LOOP_SYM
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user