diff options
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/sp-error.result | 31 | ||||
-rw-r--r-- | mysql-test/r/sp.result | 37 | ||||
-rw-r--r-- | mysql-test/t/sp-error.test | 32 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 47 |
4 files changed, 141 insertions, 6 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 4cd1c4c961c..2ece3e61d1d 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -47,6 +47,11 @@ iterate bar; end loop; ERROR HY000: ITERATE with no matching label: bar create procedure foo() +foo: begin +iterate foo; +end; +ERROR HY000: ITERATE with no matching label: foo +create procedure foo() foo: loop foo: loop set @x=2; @@ -219,4 +224,30 @@ end; call p(); ERROR HY000: Wrong number of FETCH variables drop procedure p; +create procedure p(in x int, x char(10)) +begin +end; +ERROR HY000: Duplicate parameter: x +create function p(x int, x char(10)) +begin +end; +ERROR HY000: Duplicate parameter: x +create procedure p() +begin +declare x float; +declare x int; +end; +ERROR HY000: Duplicate parameter: x +create procedure p() +begin +declare c condition for 1064; +declare c condition for 1065; +end; +ERROR HY000: Duplicate condition: c +create procedure p() +begin +declare c cursor for select * from t1; +declare c cursor for select field from t1; +end; +ERROR HY000: Duplicate cursor: c drop table t1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index c5cd1c6a1b9..4f66dafbe81 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -36,6 +36,20 @@ select * from t1; id data bar 666 delete from t1; +create procedure empty() +begin +end; +call empty(); +drop procedure empty; +create procedure scope(a int, b float) +begin +declare b int; +declare c float; +begin +declare c int; +end; +end; +drop procedure scope; create procedure two(x1 char(16), x2 char(16), y int) begin insert into test.t1 values (x1, y); @@ -256,7 +270,7 @@ insert into test.t1 values ("d", x); set x = x-1; leave hmm; insert into test.t1 values ("x", x); -end while hmm; +end while; call d(3); select * from t1; id data @@ -335,6 +349,21 @@ h1 1 h? 17 delete from t1; drop procedure h; +create procedure i(x int) +foo: +begin +if x = 0 then +leave foo; +end if; +insert into test.t1 values ("i", x); +end foo; +call i(0); +call i(3); +select * from t1; +id data +i 3 +delete from t1; +drop procedure i; create procedure into_test(x char(16), y int) begin insert into test.t1 values (x, y); @@ -461,6 +490,8 @@ create procedure hndlr1(val int) begin declare x int default 0; declare foo condition for 1146; +declare bar condition for sqlstate '42S98'; # Just for testing syntax +declare zip condition for sqlstate value '42S99'; # Just for testing syntax declare continue handler for foo set x = 1; insert into test.t666 values ("hndlr1", val); # Non-existing table if (x) then @@ -477,7 +508,7 @@ create procedure hndlr2(val int) begin declare x int default 0; begin -declare exit handler for '42S02' set x = 1; +declare exit handler for sqlstate '42S02' set x = 1; insert into test.t666 values ("hndlr2", val); # Non-existing table end; insert into test.t1 values ("hndlr2", x); @@ -744,7 +775,7 @@ end if; set s = s+1; end; end if; -end loop again; +end loop; end; create procedure ip(m int unsigned) begin diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 7c541029452..09a1e196786 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -74,6 +74,11 @@ create procedure foo() foo: loop iterate bar; end loop| +--error 1285 +create procedure foo() +foo: begin + iterate foo; +end| # Redefining label --error 1286 @@ -298,6 +303,33 @@ end| call p()| drop procedure p| +--error 1307 +create procedure p(in x int, x char(10)) +begin +end| +--error 1307 +create function p(x int, x char(10)) +begin +end| +--error 1307 +create procedure p() +begin + declare x float; + declare x int; +end| +--error 1307 +create procedure p() +begin + declare c condition for 1064; + declare c condition for 1065; +end| +--error 1307 +create procedure p() +begin + declare c cursor for select * from t1; + declare c cursor for select field from t1; +end| + drop table t1| delimiter ;| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 83fabcce34e..b9f62d4fb0a 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -59,6 +59,28 @@ delete from t1; # Now for multiple statements... delimiter |; +# Empty statement +create procedure empty() +begin +end| + +call empty()| +drop procedure empty| + +# Scope test. This is legal (warnings might be possible in the future, +# but for the time being, we just accept it). +create procedure scope(a int, b float) +begin + declare b int; + declare c float; + + begin + declare c int; + end; +end| + +drop procedure scope| + # Two statements. create procedure two(x1 char(16), x2 char(16), y int) begin @@ -313,7 +335,7 @@ hmm: while x > 0 do set x = x-1; leave hmm; insert into test.t1 values ("x", x); -end while hmm| +end while| call d(3)| select * from t1| @@ -393,6 +415,23 @@ delete from t1| drop procedure h| +# It's actually possible to LEAVE a BEGIN-END block +create procedure i(x int) +foo: +begin + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("i", x); +end foo| + +call i(0)| +call i(3)| +select * from t1| +delete from t1| +drop procedure i| + + # SELECT INTO local variables create procedure into_test(x char(16), y int) begin @@ -543,6 +582,8 @@ create procedure hndlr1(val int) begin declare x int default 0; declare foo condition for 1146; + declare bar condition for sqlstate '42S98'; # Just for testing syntax + declare zip condition for sqlstate value '42S99'; # Just for testing syntax declare continue handler for foo set x = 1; insert into test.t666 values ("hndlr1", val); # Non-existing table @@ -561,7 +602,7 @@ begin declare x int default 0; begin - declare exit handler for '42S02' set x = 1; + declare exit handler for sqlstate '42S02' set x = 1; insert into test.t666 values ("hndlr2", val); # Non-existing table end; @@ -864,7 +905,7 @@ begin set s = s+1; end; end if; - end loop again; + end loop; end| create procedure ip(m int unsigned) |