summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/sp-error.result25
-rw-r--r--mysql-test/r/sp.result57
-rw-r--r--mysql-test/t/sp-error.test29
-rw-r--r--mysql-test/t/sp.test70
4 files changed, 181 insertions, 0 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index 95fe8edf321..d839b8a3af8 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -96,3 +96,28 @@ select f(1, 2);
ERROR HY000: Wrong number of arguments for FUNCTION f, expected 1, got 2
drop procedure p;
drop function f;
+create procedure p(val int, out res int)
+begin
+declare x int default 0;
+declare continue handler for foo set x = 1;
+insert into test.t1 values (val);
+if (x) then
+set res = 0;
+else
+set res = 1;
+end if;
+end;
+ERROR HY000: Undefined CONDITION: foo
+create procedure p(val int, out res int)
+begin
+declare x int default 0;
+declare foo condition for 1146;
+declare continue handler for bar set x = 1;
+insert into test.t1 values (val);
+if (x) then
+set res = 0;
+else
+set res = 1;
+end if;
+end;
+ERROR HY000: Undefined CONDITION: bar
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index c08d252cfe3..42f720c7791 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -443,6 +443,63 @@ drop function inc;
drop function mul;
drop function append;
drop function fun;
+create procedure hndlr1(val int)
+begin
+declare x int default 0;
+declare foo condition for 1146;
+declare continue handler for foo set x = 1;
+insert into test.t666 values ("hndlr1", val); # Non-existing table
+if (x) then
+insert into test.t1 values ("hndlr1", val); # This instead then
+end if;
+end;
+call hndlr1(42);
+select * from t1;
+id data
+hndlr1 42
+delete from t1;
+drop procedure hndlr1;
+create procedure hndlr2(val int)
+begin
+declare x int default 0;
+begin
+declare exit handler for '42S02' set x = 1;
+insert into test.t666 values ("hndlr2", val); # Non-existing table
+end;
+insert into test.t1 values ("hndlr2", x);
+end;
+call hndlr2(42);
+select * from t1;
+id data
+hndlr2 1
+delete from t1;
+drop procedure hndlr2;
+create procedure hndlr3(val int)
+begin
+declare x int default 0;
+declare continue handler for sqlexception # Any error
+begin
+declare z int;
+set z = 2 * val;
+set x = 1;
+end;
+if val < 10 then
+begin
+declare y int;
+set y = val + 10;
+insert into test.t666 values ("hndlr3", y); # Non-existing table
+if x then
+insert into test.t1 values ("hndlr3", y);
+end if;
+end;
+end if;
+end;
+call hndlr3(3);
+select * from t1;
+id data
+hndlr3 13
+delete from t1;
+drop procedure hndlr3;
drop table if exists fac;
create table fac (n int unsigned not null primary key, f bigint unsigned);
create procedure ifac(n int unsigned)
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index 01e05246d3e..5d46c39b601 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -142,4 +142,33 @@ select f(1, 2)|
drop procedure p|
drop function f|
+--error 1289
+create procedure p(val int, out res int)
+begin
+ declare x int default 0;
+ declare continue handler for foo set x = 1;
+
+ insert into test.t1 values (val);
+ if (x) then
+ set res = 0;
+ else
+ set res = 1;
+ end if;
+end|
+
+--error 1289
+create procedure p(val int, out res int)
+begin
+ declare x int default 0;
+ declare foo condition for 1146;
+ declare continue handler for bar set x = 1;
+
+ insert into test.t1 values (val);
+ if (x) then
+ set res = 0;
+ else
+ set res = 1;
+ end if;
+end|
+
delimiter ;|
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 61519c52929..3450b47b4e5 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -520,6 +520,76 @@ drop function fun|
#
+# CONDITIONs and HANDLERs
+#
+
+create procedure hndlr1(val int)
+begin
+ declare x int default 0;
+ declare foo condition for 1146;
+ declare continue handler for foo set x = 1;
+
+ insert into test.t666 values ("hndlr1", val); # Non-existing table
+ if (x) then
+ insert into test.t1 values ("hndlr1", val); # This instead then
+ end if;
+end|
+
+call hndlr1(42)|
+select * from t1|
+delete from t1|
+drop procedure hndlr1|
+
+create procedure hndlr2(val int)
+begin
+ declare x int default 0;
+
+ begin
+ declare exit handler for '42S02' set x = 1;
+
+ insert into test.t666 values ("hndlr2", val); # Non-existing table
+ end;
+
+ insert into test.t1 values ("hndlr2", x);
+end|
+
+call hndlr2(42)|
+select * from t1|
+delete from t1|
+drop procedure hndlr2|
+
+
+create procedure hndlr3(val int)
+begin
+ declare x int default 0;
+ declare continue handler for sqlexception # Any error
+ begin
+ declare z int;
+
+ set z = 2 * val;
+ set x = 1;
+ end;
+
+ if val < 10 then
+ begin
+ declare y int;
+
+ set y = val + 10;
+ insert into test.t666 values ("hndlr3", y); # Non-existing table
+ if x then
+ insert into test.t1 values ("hndlr3", y);
+ end if;
+ end;
+ end if;
+end|
+
+call hndlr3(3)|
+select * from t1|
+delete from t1|
+drop procedure hndlr3|
+
+
+#
# Some "real" examples
#