#At file:///home/malff/BZR-TREE/mysql-6.0-36510-bt/
2763 Marc Alff 2008-08-13
Bug#36510 (Stored Procedures: mysql_error_code 0 should be illegal)
This fix is a follow up on 8759.
DECLARE HANDLER can catch exceptions using several syntaxes:
- by SQLSTATE (SQL Standard)
- by error number (MySQL)
Catching succesful completion by error number, aka catching error 0,
is illegal, and is now prevented.
Also, the SQL standard defines the completion condition as a class of
SQLSTATE, so that any state of class '00' and any subclass is a completion
condition. Such completion conditions (for example, '00123') can not be
caught by an exception handler in SQL.
modified:
mysql-test/r/sp-error.result
mysql-test/t/sp-error.test
sql/sp_pcontext.cc
sql/sql_yacc.yy
=== modified file 'mysql-test/r/sp-error.result'
--- a/mysql-test/r/sp-error.result 2008-07-03 19:42:27 +0000
+++ b/mysql-test/r/sp-error.result 2008-08-13 21:52:18 +0000
@@ -1624,6 +1624,29 @@ begin
declare continue handler for sqlstate '00000' set @x=0;
end$$
ERROR 42000: Bad SQLSTATE: '00000'
+drop procedure if exists proc_36510;
+create procedure proc_36510()
+begin
+declare should_be_illegal condition for sqlstate '00123';
+declare continue handler for should_be_illegal set @x=0;
+end$$
+ERROR 42000: Bad SQLSTATE: '00123'
+create procedure proc_36510()
+begin
+declare continue handler for sqlstate '00123' set @x=0;
+end$$
+ERROR 42000: Bad SQLSTATE: '00123'
+create procedure proc_36510()
+begin
+declare should_be_illegal condition for 0;
+declare continue handler for should_be_illegal set @x=0;
+end$$
+ERROR HY000: Incorrect CONDITION value: '0'
+create procedure proc_36510()
+begin
+declare continue handler for 0 set @x=0;
+end$$
+ERROR HY000: Incorrect CONDITION value: '0'
drop procedure if exists p1;
set @old_recursion_depth = @@max_sp_recursion_depth;
set @@max_sp_recursion_depth = 255;
=== modified file 'mysql-test/t/sp-error.test'
--- a/mysql-test/t/sp-error.test 2008-07-03 19:42:27 +0000
+++ b/mysql-test/t/sp-error.test 2008-08-13 21:52:18 +0000
@@ -2392,6 +2392,42 @@ end$$
delimiter ;$$
+#
+# Bug#36510 (Stored Procedures: mysql_error_code 0 should be illegal)
+#
+
+--disable_warnings
+drop procedure if exists proc_36510;
+--enable_warnings
+
+delimiter $$;
+
+--error ER_SP_BAD_SQLSTATE
+create procedure proc_36510()
+begin
+ declare should_be_illegal condition for sqlstate '00123';
+ declare continue handler for should_be_illegal set @x=0;
+end$$
+
+--error ER_SP_BAD_SQLSTATE
+create procedure proc_36510()
+begin
+ declare continue handler for sqlstate '00123' set @x=0;
+end$$
+
+--error ER_WRONG_VALUE
+create procedure proc_36510()
+begin
+ declare should_be_illegal condition for 0;
+ declare continue handler for should_be_illegal set @x=0;
+end$$
+
+--error ER_WRONG_VALUE
+create procedure proc_36510()
+begin
+ declare continue handler for 0 set @x=0;
+end$$
+delimiter ;$$
#
# Bug#15192: "fatal errors" are caught by handlers in stored procedures
=== modified file 'sql/sp_pcontext.cc'
--- a/sql/sp_pcontext.cc 2008-04-09 00:56:49 +0000
+++ b/sql/sp_pcontext.cc 2008-08-13 21:52:18 +0000
@@ -51,7 +51,8 @@ sp_cond_check(LEX_STRING *sqlstate)
(c < 'A' || 'Z' < c))
return FALSE;
}
- if (strcmp(sqlstate->str, "00000") == 0)
+ /* SQLSTATE class '00' : completion condition */
+ if (strncmp(sqlstate->str, "00", 2) == 0)
return FALSE;
return TRUE;
}
=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy 2008-08-13 18:09:46 +0000
+++ b/sql/sql_yacc.yy 2008-08-13 21:52:18 +0000
@@ -2635,6 +2635,11 @@ sp_hcond_element:
sp_cond:
ulong_num
{ /* mysql errno */
+ if ($1 == 0)
+ {
+ my_error(ER_WRONG_VALUE, MYF(0), "CONDITION", "0");
+ MYSQL_YYABORT;
+ }
$$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
if ($$ == NULL)
MYSQL_YYABORT;
| Thread |
|---|
| • bzr commit into mysql-6.0-bugteam branch (marc.alff:2763) Bug#36510 | Marc Alff | 13 Aug |