diff options
author | unknown <pem@mysql.comhem.se> | 2003-11-13 19:34:56 +0100 |
---|---|---|
committer | unknown <pem@mysql.comhem.se> | 2003-11-13 19:34:56 +0100 |
commit | c9232c60e2ec287932158b6d820352dd98e85fd7 (patch) | |
tree | df91989d7134f7e1e4a3a6c110312d910b30c970 /mysql-test | |
parent | 4696bb41b4cce563ffff8d7b6c32576214109113 (diff) | |
download | mariadb-git-c9232c60e2ec287932158b6d820352dd98e85fd7.tar.gz |
Various bug fixes:
- Duplicate parameters/variables, conditions and cursors (not allowed).
- ITERATE in labelled BEGIN-END (not allowed).
- Missing SQLSTATE [VALUE] keywords in CONDITION/HANDLER declaration (added).
- Empty BEGIN-END (now allowed).
- End label (now optional).
include/mysqld_error.h:
New error code for duplicate things (vars et al) in SPs.
mysql-test/r/sp-error.result:
New error tests for ITERATE in begin-end block and duplicate variables,
conditions and cursors.
mysql-test/r/sp.result:
New tests for empty begin-end blocks, overriding local variables outside scope
only, leave a begin-end block, and SQLSTATE [VALUE] words for CONDITION/HANDLER
declarations.
mysql-test/t/sp-error.test:
New error tests for ITERATE in begin-end block and duplicate variables,
conditions and cursors.
mysql-test/t/sp.test:
New tests for empty begin-end blocks, overriding local variables outside scope
only, leave a begin-end block, and SQLSTATE [VALUE] words for CONDITION/HANDLER
declarations.
sql/lex.h:
New SQLSTATE keyword.
sql/share/czech/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/danish/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/dutch/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/english/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/estonian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/french/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/german/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/greek/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/hungarian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/italian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/japanese/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/korean/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/norwegian-ny/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/norwegian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/polish/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/portuguese/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/romanian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/russian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/serbian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/slovak/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/spanish/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/swedish/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/share/ukrainian/errmsg.txt:
New error message for duplicate things (vars et al) in SPs.
sql/sp_pcontext.cc:
Keep track on scope limits for error checking of duplicate variables,
conditions and cursors.
sql/sp_pcontext.h:
Keep track on scope limits for error checking of duplicate variables,
conditions and cursors.
Also need to flag BEGIN labels to check for illegal ITERATEs.
sql/sql_yacc.yy:
End-labels in SPs loop and begin-end blocks are now optional.
SQLSTATE [VALUE] added to syntax for sqlstates.
Check for duplicate variable, condition and cursor declarations, but
only in the same scope.
Empty BEGIN-END statements now allowed.
Check if ITERATE is referring to a BEGIN label.
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) |