diff options
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/sp-error.result | 82 | ||||
-rw-r--r-- | mysql-test/r/sp.result | 27 | ||||
-rw-r--r-- | mysql-test/t/sp-error.test | 106 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 31 |
4 files changed, 246 insertions, 0 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index d90aef7f609..ef8b2ac1552 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -138,3 +138,85 @@ end; select f(10); ERROR HY000: FUNCTION f ended without RETURN drop function f; +create procedure p() +begin +declare c cursor for insert into test.t1 values ("foo", 42); +open c; +close c; +end; +ERROR HY000: Cursor statement must be a SELECT +create procedure p() +begin +declare x int; +declare c cursor for select * into x from test.t limit 1; +open c; +close c; +end; +ERROR HY000: Cursor SELECT must not have INTO +create procedure p() +begin +declare c cursor for select * from test.t; +open cc; +close c; +end; +ERROR HY000: Undefined CURSOR: cc +drop table if exists t1; +create table t1 (val int); +create procedure p() +begin +declare c cursor for select * from test.t1; +open c; +open c; +close c; +end; +call p(); +ERROR HY000: Cursor is already open +drop procedure p; +create procedure p() +begin +declare c cursor for select * from test.t1; +open c; +close c; +close c; +end; +call p(); +ERROR HY000: Cursor is not open +drop procedure p; +drop table t1; +drop table if exists t1; +create table t1 (val int, x float); +insert into t1 values (42, 3.1), (19, 1.2); +create procedure p() +begin +declare c cursor for select * from t1; +declare x int; +open c; +fetch c into x, y; +close c; +end; +ERROR HY000: Undeclared variable: y +create procedure p() +begin +declare c cursor for select * from t1; +declare x int; +open c; +fetch c into x; +close c; +end; +call p(); +ERROR HY000: Wrong number of FETCH variables +drop procedure p; +create procedure p() +begin +declare c cursor for select * from t1; +declare x int; +declare y float; +declare z int; +open c; +fetch c into x, y, z; +close c; +end; +call p(); +ERROR HY000: Wrong number of FETCH variables +drop procedure p; +drop table t1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index c8652b25b2e..3339c93a0be 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -500,6 +500,33 @@ id data hndlr3 13 delete from t1; drop procedure hndlr3; +create procedure cur1() +begin +declare done int default 0; +declare continue handler for 1305 set done = 1; +declare c cursor for select * from test.t2; +declare a char(16); +declare b int; +declare c double; +open c; +repeat +fetch c into a, b, c; +if not done then +insert into test.t1 values (a, b+c); +end if; +until done end repeat; +close c; +end; +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14); +call cur1(); +select * from t1; +id data +foo 40 +bar 15 +zap 663 +delete from t1; +delete from t2; +drop procedure cur1; create procedure bug822(a_id char(16), a_data int) begin declare n int; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index ba2805bfb0c..c075e96cc78 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -194,4 +194,110 @@ select f(10)| drop function f| +--error 1298 +create procedure p() +begin + declare c cursor for insert into test.t1 values ("foo", 42); + + open c; + close c; +end| + +--error 1299 +create procedure p() +begin + declare x int; + declare c cursor for select * into x from test.t limit 1; + + open c; + close c; +end| + +--error 1300 +create procedure p() +begin + declare c cursor for select * from test.t; + + open cc; + close c; +end| + +--disable_warnings +drop table if exists t1| +--enable_warnings +create table t1 (val int)| + +create procedure p() +begin + declare c cursor for select * from test.t1; + + open c; + open c; + close c; +end| +--error 1301 +call p()| +drop procedure p| + +create procedure p() +begin + declare c cursor for select * from test.t1; + + open c; + close c; + close c; +end| +--error 1302 +call p()| +drop procedure p| + +drop table t1| + +--disable_warnings +drop table if exists t1| +--enable_warnings +create table t1 (val int, x float)| +insert into t1 values (42, 3.1), (19, 1.2)| + +--error 1303 +create procedure p() +begin + declare c cursor for select * from t1; + declare x int; + + open c; + fetch c into x, y; + close c; +end| + +create procedure p() +begin + declare c cursor for select * from t1; + declare x int; + + open c; + fetch c into x; + close c; +end| +--error 1304 +call p()| +drop procedure p| + +create procedure p() +begin + declare c cursor for select * from t1; + declare x int; + declare y float; + declare z int; + + open c; + fetch c into x, y, z; + close c; +end| +--error 1304 +call p()| +drop procedure p| + +drop table t1| + delimiter ;| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 43deb12b379..724180c65bf 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -588,7 +588,38 @@ select * from t1| delete from t1| drop procedure hndlr3| +# +# Cursors +# +create procedure cur1() +begin + declare done int default 0; + declare continue handler for 1305 set done = 1; + declare c cursor for select * from test.t2; + declare a char(16); + declare b int; + declare c double; + + open c; + repeat + fetch c into a, b, c; + if not done then + insert into test.t1 values (a, b+c); + end if; + until done end repeat; + close c; +end| +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| +call cur1()| +select * from t1| +delete from t1| +delete from t2| +drop procedure cur1| + +# +# BUG#822 +# create procedure bug822(a_id char(16), a_data int) begin declare n int; |