mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fix for BUG#1495: Evaluate items before setting a local variable with SELECT INTO.
Also copy and restore order_list and group_list for selects in SPs. mysql-test/r/sp.result: Test for BUG#1495, and an additional cursor test. mysql-test/t/sp.test: Test for BUG#1495, and an additional cursor test. sql/sp_head.cc: Fix BUG#1495: renamed eval_func_item() into sp_eval_func_item() and made it non-static. Also need to copy and restore order_list and group_list pointers before and after execution of a substatement. (Which means these must always be properly initialized for all queries.) sql/sp_rcontext.cc: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO). sql/sp_rcontext.h: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO). sql/sql_class.cc: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO). sql/sql_class.h: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO); need type for this. sql/sql_parse.cc: order_list and group_list must be initialized in select_lex for all queries, to make SP sub statement execution work. sql/sql_yacc.yy: Type needed for setting local variables. sql/table.h: Need a copy of the Item* pointer when executing sub-statements in SPs. (Since it's modified and must be restored afterwards.)
This commit is contained in:
@ -524,9 +524,44 @@ id data
|
||||
foo 40
|
||||
bar 15
|
||||
zap 663
|
||||
drop procedure cur1;
|
||||
create table t3 ( s char(16), i int );
|
||||
create procedure cur2()
|
||||
begin
|
||||
declare done int default 0;
|
||||
declare continue handler for 1305 set done = 1;
|
||||
declare c1 cursor for select id,data from test.t1;
|
||||
declare c2 cursor for select i from test.t2;
|
||||
open c1;
|
||||
open c2;
|
||||
repeat
|
||||
begin
|
||||
declare a char(16);
|
||||
declare b,c int;
|
||||
fetch c1 into a, b;
|
||||
fetch c2 into c;
|
||||
if not done then
|
||||
if b < c then
|
||||
insert into test.t3 values (a, b);
|
||||
else
|
||||
insert into test.t3 values (a, c);
|
||||
end if;
|
||||
end if;
|
||||
end;
|
||||
until done end repeat;
|
||||
close c1;
|
||||
close c2;
|
||||
end;
|
||||
call cur2();
|
||||
select * from t3;
|
||||
s i
|
||||
foo 40
|
||||
bar 3
|
||||
zap 663
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
drop procedure cur1;
|
||||
drop table t3;
|
||||
drop procedure cur2;
|
||||
create procedure bug822(a_id char(16), a_data int)
|
||||
begin
|
||||
declare n int;
|
||||
@ -544,6 +579,28 @@ foo 42
|
||||
bar 666
|
||||
delete from t1;
|
||||
drop procedure bug822;
|
||||
create procedure bug1495()
|
||||
begin
|
||||
declare x int;
|
||||
select data into x from t1 order by id limit 1;
|
||||
if x > 10 then
|
||||
insert into t1 values ("less", x-10);
|
||||
else
|
||||
insert into t1 values ("more", x+10);
|
||||
end if;
|
||||
end;
|
||||
insert into t1 values ('foo', 12);
|
||||
call bug1495();
|
||||
delete from t1 where id='foo';
|
||||
insert into t1 values ('bar', 7);
|
||||
call bug1495();
|
||||
delete from t1 where id='bar';
|
||||
select * from t1;
|
||||
id data
|
||||
less 2
|
||||
more 17
|
||||
delete from t1;
|
||||
drop procedure bug1495;
|
||||
drop table if exists fac;
|
||||
create table fac (n int unsigned not null primary key, f bigint unsigned);
|
||||
create procedure ifac(n int unsigned)
|
||||
|
@ -613,9 +613,45 @@ end|
|
||||
insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)|
|
||||
call cur1()|
|
||||
select * from t1|
|
||||
drop procedure cur1|
|
||||
|
||||
create table t3 ( s char(16), i int )|
|
||||
|
||||
create procedure cur2()
|
||||
begin
|
||||
declare done int default 0;
|
||||
declare continue handler for 1305 set done = 1;
|
||||
declare c1 cursor for select id,data from test.t1;
|
||||
declare c2 cursor for select i from test.t2;
|
||||
|
||||
open c1;
|
||||
open c2;
|
||||
repeat
|
||||
begin
|
||||
declare a char(16);
|
||||
declare b,c int;
|
||||
|
||||
fetch c1 into a, b;
|
||||
fetch c2 into c;
|
||||
if not done then
|
||||
if b < c then
|
||||
insert into test.t3 values (a, b);
|
||||
else
|
||||
insert into test.t3 values (a, c);
|
||||
end if;
|
||||
end if;
|
||||
end;
|
||||
until done end repeat;
|
||||
close c1;
|
||||
close c2;
|
||||
end|
|
||||
|
||||
call cur2()|
|
||||
select * from t3|
|
||||
delete from t1|
|
||||
delete from t2|
|
||||
drop procedure cur1|
|
||||
drop table t3|
|
||||
drop procedure cur2|
|
||||
|
||||
#
|
||||
# BUG#822
|
||||
@ -636,6 +672,31 @@ select * from t1|
|
||||
delete from t1|
|
||||
drop procedure bug822|
|
||||
|
||||
#
|
||||
# BUG#1495
|
||||
#
|
||||
create procedure bug1495()
|
||||
begin
|
||||
declare x int;
|
||||
|
||||
select data into x from t1 order by id limit 1;
|
||||
if x > 10 then
|
||||
insert into t1 values ("less", x-10);
|
||||
else
|
||||
insert into t1 values ("more", x+10);
|
||||
end if;
|
||||
end|
|
||||
|
||||
insert into t1 values ('foo', 12)|
|
||||
call bug1495()|
|
||||
delete from t1 where id='foo'|
|
||||
insert into t1 values ('bar', 7)|
|
||||
call bug1495()|
|
||||
delete from t1 where id='bar'|
|
||||
select * from t1|
|
||||
delete from t1|
|
||||
drop procedure bug1495|
|
||||
|
||||
|
||||
#
|
||||
# Some "real" examples
|
||||
|
Reference in New Issue
Block a user