summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-08-17 20:20:58 +0200
committerunknown <pem@mysql.comhem.se>2004-08-17 20:20:58 +0200
commit9b5a6f7228850479abe0e4e2439dcf6b27a87136 (patch)
tree0a14fd07bbceeceb892fb762e8f9af5e74153b89 /mysql-test
parentf43fe31e571bb5e127d5e0ca4ad6680a15104aa7 (diff)
downloadmariadb-git-9b5a6f7228850479abe0e4e2439dcf6b27a87136.tar.gz
WL#2002: Implement stored procedure GOTO.
Mostly done, it works, but the temporary LABEL syntax still to be fixed. mysql-test/r/sp-error.result: New test case for WL#2002 (GOTO). mysql-test/r/sp.result: New test case for WL#2002 (GOTO). (Also corrected another test) mysql-test/t/sp-error.test: New test case for WL#2002 (GOTO). mysql-test/t/sp.test: New test case for WL#2002 (GOTO). (Also corrected another test) sql/lex.h: New symbol GOTO. Also a temporary symbol LABEL, which hopefully will go away soon. sql/sp_head.cc: Fixed backpatching to cope with free GOTO labels an hpop and cpop instructions. Also optimized away pointless jump instructions. sql/sp_head.h: Fixed backpatching to cope with free GOTO labels an hpop and cpop instructions. We now sometimes generate hpop/cpop 0 instructions but the optimizer removes them. sql/sp_pcontext.cc: Added free GOTO labels, and support for coping with jumps out of blocks with handlers or cursors. sql/sp_pcontext.h: Added free GOTO labels, and support for coping with jumps out of blocks with handlers or cursors. sql/sql_yacc.yy: Added GOTO and LABEL, and adjusted backpatching accordingly. Also fixed LEAVE out of blocks. The LABEL syntax will go away soon, hopefully.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/sp-error.result5
-rw-r--r--mysql-test/r/sp.result89
-rw-r--r--mysql-test/t/sp-error.test7
-rw-r--r--mysql-test/t/sp.test63
4 files changed, 157 insertions, 7 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index 02aaa646646..14e2090579b 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -63,6 +63,11 @@ iterate foo;
end|
ERROR 42000: ITERATE with no matching label: foo
create procedure foo()
+begin
+goto foo;
+end|
+ERROR 42000: GOTO with no matching label: foo
+create procedure foo()
foo: loop
foo: loop
set @x=2;
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index a7f6d2a1b2f..9b2e16e3fe9 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -398,6 +398,87 @@ id data
i 3
delete from t1|
drop procedure i|
+create procedure j()
+begin
+declare y int;
+label a;
+select * from t1;
+select count(*) into y from t1;
+if y > 2 then
+goto b;
+end if;
+insert into t1 values ("j", y);
+goto a;
+label b;
+end|
+call j()|
+id data
+id data
+j 0
+id data
+j 0
+j 1
+id data
+j 0
+j 1
+j 2
+drop procedure j|
+create procedure k(a int)
+begin
+declare x int default 0;
+declare continue handler for sqlstate '42S98' set x = 1;
+label a;
+select * from t1;
+b:
+while x < 2 do
+begin
+declare continue handler for sqlstate '42S99' set x = 2;
+if a = 0 then
+set x = x + 1;
+iterate b;
+elseif a = 1 then
+leave b;
+elseif a = 2 then
+set a = 1;
+goto a;
+end if;
+end;
+end while b;
+select * from t1;
+end|
+call k(0)|
+id data
+j 0
+j 1
+j 2
+id data
+j 0
+j 1
+j 2
+call k(1)|
+id data
+j 0
+j 1
+j 2
+id data
+j 0
+j 1
+j 2
+call k(2)|
+id data
+j 0
+j 1
+j 2
+id data
+j 0
+j 1
+j 2
+id data
+j 0
+j 1
+j 2
+drop procedure k|
+delete from t1|
insert into t1 values ("foo", 3), ("bar", 19)|
insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)|
create procedure sel1()
@@ -1487,7 +1568,7 @@ Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
File Position Binlog_Do_DB Binlog_Ignore_DB
-master-bin.000001 22185
+master-bin.000001 22451
Database Table In_use Name_locked
Privilege Context Comment
Alter Tables To alter the table
@@ -1541,7 +1622,7 @@ Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
File Position Binlog_Do_DB Binlog_Ignore_DB
-master-bin.000001 22185
+master-bin.000001 22451
Database Table In_use Name_locked
Privilege Context Comment
Alter Tables To alter the table
@@ -1580,10 +1661,10 @@ show processlist;
end|
call bug4902_2()|
Id User Host db Command Time State Info
-# root localhost test Query 0 NULL call bug4902_2()
+# root localhost test Query # NULL call bug4902_2()
call bug4902_2()|
Id User Host db Command Time State Info
-# root localhost test Query 0 NULL call bug4902_2()
+# root localhost test Query # NULL call bug4902_2()
drop procedure bug4902_2|
drop table if exists t3|
create procedure bug4904()
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index ecba664dfca..2c2dd10c676 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -82,7 +82,7 @@ drop procedure if exists foo|
--error 1304
show create procedure foo|
-# LEAVE/ITERATE with no match
+# LEAVE/ITERATE/GOTO with no match
--error 1307
create procedure foo()
foo: loop
@@ -98,6 +98,11 @@ create procedure foo()
foo: begin
iterate foo;
end|
+--error 1307
+create procedure foo()
+begin
+ goto foo;
+end|
# Redefining label
--error 1308
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 3913afed735..265223fd930 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -468,6 +468,65 @@ delete from t1|
drop procedure i|
+# The non-standard GOTO, for compatibility
+#
+# QQQ The "label" syntax is temporary.
+# QQQ This is no nearly enough, more tests are needed
+#
+create procedure j()
+begin
+ declare y int;
+
+label a;
+ select * from t1;
+ select count(*) into y from t1;
+ if y > 2 then
+ goto b;
+ end if;
+ insert into t1 values ("j", y);
+ goto a;
+label b;
+end|
+
+call j()|
+
+drop procedure j|
+
+# With dummy handlers, just to test restore of contexts with jumps
+create procedure k(a int)
+begin
+ declare x int default 0;
+ declare continue handler for sqlstate '42S98' set x = 1;
+
+label a;
+ select * from t1;
+b:
+ while x < 2 do
+ begin
+ declare continue handler for sqlstate '42S99' set x = 2;
+
+ if a = 0 then
+ set x = x + 1;
+ iterate b;
+ elseif a = 1 then
+ leave b;
+ elseif a = 2 then
+ set a = 1;
+ goto a;
+ end if;
+ end;
+ end while b;
+
+ select * from t1;
+end|
+
+call k(0)|
+call k(1)|
+call k(2)|
+
+drop procedure k|
+delete from t1|
+
# SELECT with one of more result set sent back to the clinet
insert into t1 values ("foo", 3), ("bar", 19)|
insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)|
@@ -1725,9 +1784,9 @@ create procedure bug4902_2()
begin
show processlist;
end|
---replace_column 1 #
+--replace_column 1 # 6 #
call bug4902_2()|
---replace_column 1 #
+--replace_column 1 # 6 #
call bug4902_2()|
drop procedure bug4902_2|