Commit 3d8aed6d authored by unknown's avatar unknown
Browse files

Fixed BUG#8757: Stored Procedures: Scope of Begin and End Statements do not work properly.


mysql-test/r/sp.result:
  New test case for BUG#8757.
mysql-test/t/sp.test:
  New test case for BUG#8757.
sql/sp_pcontext.cc:
  Return the correct scope offset to cursors during parsing.
parent b67253a1
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -2174,6 +2174,36 @@ end if;
select plus;
end|
drop procedure bug6857|
drop procedure if exists bug8757|
create procedure bug8757()
begin
declare x int;
declare c1 cursor for select data from t1 limit 1;
begin
declare y int;
declare c2 cursor for select i from t2 limit 1;
open c2;
fetch c2 into y;
close c2;
select 2,y;
end;
open c1;
fetch c1 into x;
close c1;
select 1,x;
end|
delete from t1|
delete from t2|
insert into t1 values ("x", 1)|
insert into t2 values ("y", 2, 0.0)|
call bug8757()|
2	y
2	2
1	x
1	1
delete from t1|
delete from t2|
drop procedure bug8757|
drop table if exists fac|
create table fac (n int unsigned not null primary key, f bigint unsigned)|
drop procedure if exists ifac|
+37 −0
Original line number Diff line number Diff line
@@ -2676,6 +2676,43 @@ end|

drop procedure bug6857|

#
# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not
#           work properly.
--disable_warnings
drop procedure if exists bug8757|
--enable_warnings
create procedure bug8757()
begin
  declare x int;
  declare c1 cursor for select data from t1 limit 1;

  begin
    declare y int;
    declare c2 cursor for select i from t2 limit 1;

    open c2;
    fetch c2 into y;
    close c2;
    select 2,y;
  end;
  open c1;
  fetch c1 into x;
  close c1;
  select 1,x;
end|

delete from t1|
delete from t2|
insert into t1 values ("x", 1)|
insert into t2 values ("y", 2, 0.0)|

call bug8757()|

delete from t1|
delete from t2|
drop procedure bug8757|


#
# Some "real" examples
+1 −1
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ sp_pcontext::find_cursor(LEX_STRING *name, uint *poff, my_bool scoped)
		     (const uchar *)name->str, name->length,
		     (const uchar *)n.str, n.length) == 0)
    {
      *poff= i;
      *poff= m_coffset + i;
      return TRUE;
    }
  }