Commit 45b5e513 authored by unknown's avatar unknown

Merge mysql.com:/usr/local/bk/mysql-5.0

into mysql.com:/home/pem/work/mysql-5.0

parents 05dfca24 25f8623f
......@@ -1250,268 +1250,562 @@ drop view v1|
drop view v2|
delete from t1 |
delete from t2 |
drop procedure if exists bug822|
create procedure bug822(a_id char(16), a_data int)
drop table if exists fac|
create table fac (n int unsigned not null primary key, f bigint unsigned)|
drop procedure if exists ifac|
create procedure ifac(n int unsigned)
begin
declare n int;
select count(*) into n from t1 where id = a_id and data = a_data;
if n = 0 then
insert into t1 (id, data) values (a_id, a_data);
declare i int unsigned default 1;
if n > 20 then
set n = 20; # bigint overflow otherwise
end if;
end|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
select * from t1|
id data
foo 42
bar 666
delete from t1|
drop procedure bug822|
drop procedure if exists bug1495|
create procedure bug1495()
while i <= n do
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;
insert into test.fac values (i, fac(i));
set i = i + 1;
end;
end while;
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 procedure if exists bug1547|
create procedure bug1547(s char(16))
call ifac(20)|
select * from fac|
n f
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800
11 39916800
12 479001600
13 6227020800
14 87178291200
15 1307674368000
16 20922789888000
17 355687428096000
18 6402373705728000
19 121645100408832000
20 2432902008176640000
drop table fac|
show function status like '%f%'|
Db Name Type Definer Modified Created Security_type Comment
test fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
drop procedure ifac|
drop function fac|
show function status like '%f%'|
Db Name Type Definer Modified Created Security_type Comment
drop table if exists primes|
create table primes (
i int unsigned not null primary key,
p bigint unsigned not null
)|
insert into primes values
( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13),
( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31),
(10, 37), (11, 41), (12, 43), (13, 47), (14, 53),
(15, 59), (16, 61), (17, 67), (18, 71), (19, 73),
(20, 79), (21, 83), (22, 89), (23, 97), (24, 101),
(25, 103), (26, 107), (27, 109), (28, 113), (29, 127),
(30, 131), (31, 137), (32, 139), (33, 149), (34, 151),
(35, 157), (36, 163), (37, 167), (38, 173), (39, 179),
(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)|
drop procedure if exists opp|
create procedure opp(n bigint unsigned, out pp bool)
begin
declare x int;
select data into x from t1 where s = id limit 1;
if x > 10 then
insert into t1 values ("less", x-10);
declare r double;
declare b, s bigint unsigned default 0;
set r = sqrt(n);
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
insert into t1 values ("more", x+10);
begin
declare p bigint unsigned;
select t.p into p from test.primes t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
end if;
if mod(n, b+p) = 0 then
set pp = 0;
leave again;
end if;
set s = s+1;
end;
end if;
end loop;
end|
insert into t1 values ("foo", 12), ("bar", 7)|
call bug1547("foo")|
call bug1547("bar")|
select * from t1|
id data
foo 12
bar 7
less 2
more 17
delete from t1|
drop procedure bug1547|
drop table if exists t70|
create table t70 (s1 int,s2 int)|
insert into t70 values (1,2)|
drop procedure if exists bug1656|
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70|
call bug1656(@1, @2)|
select @1, @2|
@1 @2
2 NULL
drop table t70|
drop procedure bug1656|
drop table if exists t3|
create table t3(a int)|
drop procedure if exists bug1862|
create procedure bug1862()
drop procedure if exists ip|
create procedure ip(m int unsigned)
begin
insert into t3 values(2);
flush tables;
end|
call bug1862()|
call bug1862()|
select * from t3|
a
2
2
drop table t3|
drop procedure bug1862|
drop procedure if exists bug1874|
create procedure bug1874()
declare p bigint unsigned;
declare i int unsigned;
set i=45, p=201;
while i < m do
begin
declare x int;
declare y double;
select max(data) into x from t1;
insert into t2 values ("max", x, 0);
select min(data) into x from t1;
insert into t2 values ("min", x, 0);
select sum(data) into x from t1;
insert into t2 values ("sum", x, 0);
select avg(data) into y from t1;
insert into t2 values ("avg", 0, y);
declare pp bool default 0;
call opp(p, pp);
if pp then
insert into test.primes values (i, p);
set i = i+1;
end if;
set p = p+2;
end;
end while;
end|
insert into t1 (data) values (3), (1), (5), (9), (4)|
call bug1874()|
select * from t2|
s i d
max 9 0
min 1 0
sum 22 0
avg 0 4.4
delete from t1|
delete from t2|
drop procedure bug1874|
drop procedure if exists bug2260|
create procedure bug2260()
show create procedure opp|
Procedure sql_mode Create Procedure
opp CREATE PROCEDURE `test`.`opp`(n bigint unsigned, out pp bool)
begin
declare v1 int;
declare c1 cursor for select data from t1;
declare continue handler for not found set @x2 = 1;
open c1;
fetch c1 into v1;
set @x2 = 2;
close c1;
end|
call bug2260()|
select @x2|
@x2
2
drop procedure bug2260|
drop procedure if exists bug2227|
create procedure bug2227(x int)
declare r double;
declare b, s bigint unsigned default 0;
set r = sqrt(n);
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
begin
declare y float default 2.6;
declare z char(16) default "zzz";
select 1.3, x, y, 42, z;
end|
call bug2227(9)|
1.3 x y 42 z
1.3 9 2.6 42 zzz
drop procedure bug2227|
drop function if exists bug2674|
create function bug2674() returns int
return @@sort_buffer_size|
set @osbs = @@sort_buffer_size|
set @@sort_buffer_size = 262000|
select bug2674()|
bug2674()
262000
drop function bug2674|
set @@sort_buffer_size = @osbs|
drop procedure if exists bug3259_1 |
create procedure bug3259_1 () begin end|
drop procedure if exists BUG3259_2 |
create procedure BUG3259_2 () begin end|
drop procedure if exists Bug3259_3 |
create procedure Bug3259_3 () begin end|
call BUG3259_1()|
call BUG3259_1()|
call bug3259_2()|
call Bug3259_2()|
call bug3259_3()|
call bUG3259_3()|
drop procedure bUg3259_1|
drop procedure BuG3259_2|
drop procedure BUG3259_3|
drop function if exists bug2772|
create function bug2772() returns char(10) character set latin2
return 'a'|
select bug2772()|
bug2772()
a
drop function bug2772|
drop procedure if exists bug2776_1|
create procedure bug2776_1(out x int)
declare p bigint unsigned;
select t.p into p from test.primes t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
end if;
if mod(n, b+p) = 0 then
set pp = 0;
leave again;
end if;
set s = s+1;
end;
end if;
end loop;
end
show procedure status like '%p%'|
Db Name Type Definer Modified Created Security_type Comment
test ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
call ip(200)|
select * from primes where i=45 or i=100 or i=199|
i p
45 211
100 557
199 1229
drop table primes|
drop procedure opp|
drop procedure ip|
show procedure status like '%p%'|
Db Name Type Definer Modified Created Security_type Comment
drop table if exists fib|
create table fib ( f bigint unsigned not null )|
insert into fib values (1), (1)|
drop procedure if exists fib|
create procedure fib(n int unsigned)
begin
declare v int;
set v = default;
set x = v;
if n > 0 then
begin
declare x, y bigint unsigned;
declare c cursor for select f from fib order by f desc limit 2;
open c;
fetch c into y;
fetch c into x;
close c;
insert into fib values (x+y);
call fib(n-1);
end;
end if;
end|
drop procedure if exists bug2776_2|
create procedure bug2776_2(out x int)
call fib(20)|
select * from fib order by f asc|
f
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
drop table fib|
drop procedure fib|
drop procedure if exists bar|
create procedure bar(x char(16), y int)
comment "111111111111" sql security invoker
insert into test.t1 values (x, y)|
show procedure status like 'bar'|
Db Name Type Definer Modified Created Security_type Comment
test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER 111111111111
alter procedure bar comment "2222222222" sql security definer|
alter procedure bar comment "3333333333"|
alter procedure bar|
show create procedure bar|
Procedure sql_mode Create Procedure
bar CREATE PROCEDURE `test`.`bar`(x char(16), y int)
COMMENT '3333333333'
insert into test.t1 values (x, y)
show procedure status like 'bar'|
Db Name Type Definer Modified Created Security_type Comment
test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 3333333333
drop procedure bar|
drop procedure if exists p1|
create procedure p1 ()
select (select s1 from t3) from t3|
create table t3 (s1 int)|
call p1()|
(select s1 from t3)
insert into t3 values (1)|
call p1()|
(select s1 from t3)
1
drop procedure p1|
drop table t3|
drop function if exists foo|
create function `foo` () returns int
return 5|
select `foo` ()|
`foo` ()
5
drop function `foo`|
drop function if exists t1max|
Warnings:
Note 1305 FUNCTION t1max does not exist
create function t1max() returns int
begin
declare v int default 42;
set v = default;
set x = v;
declare x int;
select max(data) into x from t1;
return x;
end|
set @x = 1|
call bug2776_1(@x)|
select @x|
@x
NULL
call bug2776_2(@x)|
select @x|
@x
42
drop procedure bug2776_1|
drop procedure bug2776_2|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
select t1max()|
t1max()
5
drop function t1max|
drop table if exists t3|
create table t3 (s1 smallint)|
insert into t3 values (123456789012)|
Warnings:
Warning 1264 Out of range value adjusted for column 's1' at row 1
drop procedure if exists bug2780|
create procedure bug2780()
create table t3 (
v char(16) not null primary key,
c int unsigned not null
)|
create function getcount(s char(16)) returns int
begin
declare exit handler for sqlwarning set @x = 1;
set @x = 0;
insert into t3 values (123456789012);
insert into t3 values (0);
declare x int;
select count(*) into x from t3 where v = s;
if x = 0 then
insert into t3 values (s, 1);
else
update t3 set c = c+1 where v = s;
end if;
return x;
end|
call bug2780()|
select @x|
@x
select * from t1 where data = getcount("bar")|
id data
zap 1
select * from t3|
v c
bar 4
select getcount("zip")|
getcount("zip")
0
select getcount("zip")|
getcount("zip")
1
select * from t3|
s1
32767
32767
drop procedure bug2780|
v c
bar 4
zip 2
select getcount(id) from t1 where data = 3|
getcount(id)
0
select getcount(id) from t1 where data = 5|
getcount(id)
1
select * from t3|
v c
bar 4
zip 3
foo 1
drop table t3|
create table t3 (content varchar(10) )|
insert into t3 values ("test1")|
insert into t3 values ("test2")|
create table t4 (f1 int, rc int, t3 int)|
drop procedure if exists bug1863|
create procedure bug1863(in1 int)
drop function getcount|
drop procedure if exists bug822|
create procedure bug822(a_id char(16), a_data int)
begin
declare ind int default 0;
declare t1 int;
declare t2 int;
declare t3 int;
declare rc int default 0;
declare continue handler for 1065 set rc = 1;
drop temporary table if exists temp_t1;
create temporary table temp_t1 (
f1 int auto_increment, f2 varchar(20), primary key (f1)
);
insert into temp_t1 (f2) select content from t3;
select f2 into t3 from temp_t1 where f1 = 10;
if (rc) then
insert into t4 values (1, rc, t3);
declare n int;
select count(*) into n from t1 where id = a_id and data = a_data;
if n = 0 then
insert into t1 (id, data) values (a_id, a_data);
end if;
insert into t4 values (2, rc, t3);
end|
call bug1863(10)|
call bug1863(10)|
select * from t4|
f1 rc t3
2 0 NULL
2 0 NULL
drop procedure bug1863|
drop temporary table temp_t1;
drop table t3, t4|
drop table if exists t3, t4|
create table t3 (
OrderID int not null,
MarketID int,
primary key (OrderID)
)|
delete from t1|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
select * from t1|
id data
foo 42
bar 666
delete from t1|
drop procedure bug822|
drop procedure if exists bug1495|
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 procedure if exists bug1547|
create procedure bug1547(s char(16))
begin
declare x int;
select data into x from t1 where s = 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), ("bar", 7)|
call bug1547("foo")|
call bug1547("bar")|
select * from t1|
id data
foo 12
bar 7
less 2
more 17
delete from t1|
drop procedure bug1547|
drop table if exists t70|
create table t70 (s1 int,s2 int)|
insert into t70 values (1,2)|
drop procedure if exists bug1656|
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70|
call bug1656(@1, @2)|
select @1, @2|
@1 @2
2 NULL
drop table t70|
drop procedure bug1656|
drop table if exists t3|
create table t3(a int)|
drop procedure if exists bug1862|
create procedure bug1862()
begin
insert into t3 values(2);
flush tables;
end|
call bug1862()|
call bug1862()|
select * from t3|
a
2
2
drop table t3|
drop procedure bug1862|
drop procedure if exists bug1874|
create procedure bug1874()
begin
declare x int;
declare y double;
select max(data) into x from t1;
insert into t2 values ("max", x, 0);
select min(data) into x from t1;
insert into t2 values ("min", x, 0);
select sum(data) into x from t1;
insert into t2 values ("sum", x, 0);
select avg(data) into y from t1;
insert into t2 values ("avg", 0, y);
end|
insert into t1 (data) values (3), (1), (5), (9), (4)|
call bug1874()|
select * from t2|
s i d
max 9 0
min 1 0
sum 22 0
avg 0 4.4
delete from t1|
delete from t2|
drop procedure bug1874|
drop procedure if exists bug2260|
create procedure bug2260()
begin
declare v1 int;
declare c1 cursor for select data from t1;
declare continue handler for not found set @x2 = 1;
open c1;
fetch c1 into v1;
set @x2 = 2;
close c1;
end|
call bug2260()|
select @x2|
@x2
2
drop procedure bug2260|
drop procedure if exists bug2227|
create procedure bug2227(x int)
begin
declare y float default 2.6;
declare z char(16) default "zzz";
select 1.3, x, y, 42, z;
end|
call bug2227(9)|
1.3 x y 42 z
1.3 9 2.6 42 zzz
drop procedure bug2227|
drop function if exists bug2674|
create function bug2674() returns int
return @@sort_buffer_size|
set @osbs = @@sort_buffer_size|
set @@sort_buffer_size = 262000|
select bug2674()|
bug2674()
262000
drop function bug2674|
set @@sort_buffer_size = @osbs|
drop procedure if exists bug3259_1 |
create procedure bug3259_1 () begin end|
drop procedure if exists BUG3259_2 |
create procedure BUG3259_2 () begin end|
drop procedure if exists Bug3259_3 |
create procedure Bug3259_3 () begin end|
call BUG3259_1()|
call BUG3259_1()|
call bug3259_2()|
call Bug3259_2()|
call bug3259_3()|
call bUG3259_3()|
drop procedure bUg3259_1|
drop procedure BuG3259_2|
drop procedure BUG3259_3|
drop function if exists bug2772|
create function bug2772() returns char(10) character set latin2
return 'a'|
select bug2772()|
bug2772()
a
drop function bug2772|
drop procedure if exists bug2776_1|
create procedure bug2776_1(out x int)
begin
declare v int;
set v = default;
set x = v;
end|
drop procedure if exists bug2776_2|
create procedure bug2776_2(out x int)
begin
declare v int default 42;
set v = default;
set x = v;
end|
set @x = 1|
call bug2776_1(@x)|
select @x|
@x
NULL
call bug2776_2(@x)|
select @x|
@x
42
drop procedure bug2776_1|
drop procedure bug2776_2|
drop table if exists t3|
create table t3 (s1 smallint)|
insert into t3 values (123456789012)|
Warnings:
Warning 1264 Out of range value adjusted for column 's1' at row 1
drop procedure if exists bug2780|
create procedure bug2780()
begin
declare exit handler for sqlwarning set @x = 1;
set @x = 0;
insert into t3 values (123456789012);
insert into t3 values (0);
end|
call bug2780()|
select @x|
@x
1
select * from t3|
s1
32767
32767
drop procedure bug2780|
drop table t3|
create table t3 (content varchar(10) )|
insert into t3 values ("test1")|
insert into t3 values ("test2")|
create table t4 (f1 int, rc int, t3 int)|
drop procedure if exists bug1863|
create procedure bug1863(in1 int)
begin
declare ind int default 0;
declare t1 int;
declare t2 int;
declare t3 int;
declare rc int default 0;
declare continue handler for 1065 set rc = 1;
drop temporary table if exists temp_t1;
create temporary table temp_t1 (
f1 int auto_increment, f2 varchar(20), primary key (f1)
);
insert into temp_t1 (f2) select content from t3;
select f2 into t3 from temp_t1 where f1 = 10;
if (rc) then
insert into t4 values (1, rc, t3);
end if;
insert into t4 values (2, rc, t3);
end|
call bug1863(10)|
call bug1863(10)|
select * from t4|
f1 rc t3
2 0 NULL
2 0 NULL
drop procedure bug1863|
drop temporary table temp_t1;
drop table t3, t4|
drop table if exists t3, t4|
create table t3 (
OrderID int not null,
MarketID int,
primary key (OrderID)
)|
create table t4 (
MarketID int not null,
Market varchar(60),
......@@ -2233,430 +2527,137 @@ abs(count(s1))
0
drop procedure bug6642|
insert into t3 values (0),(1)|
drop procedure if exists bug7013|
create procedure bug7013()
select s1,count(s1) from t3 group by s1 with rollup|
call bug7013()|
s1 count(s1)
0 1
1 1
NULL 2
call bug7013()|
s1 count(s1)
0 1
1 1
NULL 2
drop procedure bug7013|
drop table if exists t4|
create table t4 (
a mediumint(8) unsigned not null auto_increment,
b smallint(5) unsigned not null,
c char(32) not null,
primary key (a)
) engine=myisam default charset=latin1|
insert into t4 values (1, 2, 'oneword')|
insert into t4 values (2, 2, 'anotherword')|
drop procedure if exists bug7743|
create procedure bug7743 ( searchstring char(28) )
begin
declare var mediumint(8) unsigned;
select a into var from t4 where b = 2 and c = binary searchstring limit 1;
select var;
end|
call bug7743("oneword")|
var
1
call bug7743("OneWord")|
var
NULL
Warnings:
Warning 1329 No data to FETCH
call bug7743("anotherword")|
var
2
call bug7743("AnotherWord")|
var
NULL
Warnings:
Warning 1329 No data to FETCH
drop procedure bug7743|
drop table t4|
delete from t3|
insert into t3 values(1)|
drop procedure if exists bug7992_1|
Warnings:
Note 1305 PROCEDURE bug7992_1 does not exist
drop procedure if exists bug7992_2|
Warnings:
Note 1305 PROCEDURE bug7992_2 does not exist
create procedure bug7992_1()
begin
declare i int;
select max(s1)+1 into i from t3;
end|
create procedure bug7992_2()
insert into t3 (s1) select max(t4.s1)+1 from t3 as t4|
call bug7992_1()|
call bug7992_1()|
call bug7992_2()|
call bug7992_2()|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
drop table if exists t3|
create table t3 ( userid bigint(20) not null default 0 )|
drop procedure if exists bug8116|
create procedure bug8116(in _userid int)
select * from t3 where userid = _userid|
call bug8116(42)|
userid
call bug8116(42)|
userid
drop procedure bug8116|
drop table t3|
drop procedure if exists bug6857|
create procedure bug6857(counter int)
begin
declare t0, t1 int;
declare plus bool default 0;
set t0 = current_time();
while counter > 0 do
set counter = counter - 1;
end while;
set t1 = current_time();
if t1 > t0 then
set plus = 1;
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 procedure if exists bug8762|
drop procedure if exists bug8762; create procedure bug8762() begin end|
drop procedure if exists bug8762; create procedure bug8762() begin end|
drop procedure bug8762|
drop table if exists fac|
create table fac (n int unsigned not null primary key, f bigint unsigned)|
drop procedure if exists ifac|
create procedure ifac(n int unsigned)
begin
declare i int unsigned default 1;
if n > 20 then
set n = 20; # bigint overflow otherwise
end if;
while i <= n do
begin
insert into test.fac values (i, fac(i));
set i = i + 1;
end;
end while;
end|
call ifac(20)|
select * from fac|
n f
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800
11 39916800
12 479001600
13 6227020800
14 87178291200
15 1307674368000
16 20922789888000
17 355687428096000
18 6402373705728000
19 121645100408832000
20 2432902008176640000
drop table fac|
show function status like '%f%'|
Db Name Type Definer Modified Created Security_type Comment
test fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
drop procedure ifac|
drop function fac|
show function status like '%f%'|
Db Name Type Definer Modified Created Security_type Comment
drop table if exists primes|
create table primes (
i int unsigned not null primary key,
p bigint unsigned not null
)|
insert into primes values
( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13),
( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31),
(10, 37), (11, 41), (12, 43), (13, 47), (14, 53),
(15, 59), (16, 61), (17, 67), (18, 71), (19, 73),
(20, 79), (21, 83), (22, 89), (23, 97), (24, 101),
(25, 103), (26, 107), (27, 109), (28, 113), (29, 127),
(30, 131), (31, 137), (32, 139), (33, 149), (34, 151),
(35, 157), (36, 163), (37, 167), (38, 173), (39, 179),
(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)|
drop procedure if exists opp|
create procedure opp(n bigint unsigned, out pp bool)
begin
declare r double;
declare b, s bigint unsigned default 0;
set r = sqrt(n);
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
begin
declare p bigint unsigned;
select t.p into p from test.primes t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
end if;
if mod(n, b+p) = 0 then
set pp = 0;
leave again;
end if;
set s = s+1;
end;
end if;
end loop;
end|
drop procedure if exists ip|
create procedure ip(m int unsigned)
begin
declare p bigint unsigned;
declare i int unsigned;
set i=45, p=201;
while i < m do
begin
declare pp bool default 0;
call opp(p, pp);
if pp then
insert into test.primes values (i, p);
set i = i+1;
end if;
set p = p+2;
end;
end while;
end|
show create procedure opp|
Procedure sql_mode Create Procedure
opp CREATE PROCEDURE `test`.`opp`(n bigint unsigned, out pp bool)
begin
declare r double;
declare b, s bigint unsigned default 0;
set r = sqrt(n);
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
begin
declare p bigint unsigned;
select t.p into p from test.primes t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
end if;
if mod(n, b+p) = 0 then
set pp = 0;
leave again;
end if;
set s = s+1;
end;
end if;
end loop;
end
show procedure status like '%p%'|
Db Name Type Definer Modified Created Security_type Comment
test ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
call ip(200)|
select * from primes where i=45 or i=100 or i=199|
i p
45 211
100 557
199 1229
drop table primes|
drop procedure opp|
drop procedure ip|
show procedure status like '%p%'|
Db Name Type Definer Modified Created Security_type Comment
drop table if exists fib|
create table fib ( f bigint unsigned not null )|
insert into fib values (1), (1)|
drop procedure if exists fib|
create procedure fib(n int unsigned)
begin
if n > 0 then
drop procedure if exists bug7013|
create procedure bug7013()
select s1,count(s1) from t3 group by s1 with rollup|
call bug7013()|
s1 count(s1)
0 1
1 1
NULL 2
call bug7013()|
s1 count(s1)
0 1
1 1
NULL 2
drop procedure bug7013|
drop table if exists t4|
create table t4 (
a mediumint(8) unsigned not null auto_increment,
b smallint(5) unsigned not null,
c char(32) not null,
primary key (a)
) engine=myisam default charset=latin1|
insert into t4 values (1, 2, 'oneword')|
insert into t4 values (2, 2, 'anotherword')|
drop procedure if exists bug7743|
create procedure bug7743 ( searchstring char(28) )
begin
declare x, y bigint unsigned;
declare c cursor for select f from fib order by f desc limit 2;
open c;
fetch c into y;
fetch c into x;
close c;
insert into fib values (x+y);
call fib(n-1);
end;
end if;
declare var mediumint(8) unsigned;
select a into var from t4 where b = 2 and c = binary searchstring limit 1;
select var;
end|
call fib(20)|
select * from fib order by f asc|
f
1
call bug7743("oneword")|
var
1
call bug7743("OneWord")|
var
NULL
Warnings:
Warning 1329 No data to FETCH
call bug7743("anotherword")|
var
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
drop table fib|
drop procedure fib|
drop procedure if exists bar|
create procedure bar(x char(16), y int)
comment "111111111111" sql security invoker
insert into test.t1 values (x, y)|
show procedure status like 'bar'|
Db Name Type Definer Modified Created Security_type Comment
test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER 111111111111
alter procedure bar comment "2222222222" sql security definer|
alter procedure bar comment "3333333333"|
alter procedure bar|
show create procedure bar|
Procedure sql_mode Create Procedure
bar CREATE PROCEDURE `test`.`bar`(x char(16), y int)
COMMENT '3333333333'
insert into test.t1 values (x, y)
show procedure status like 'bar'|
Db Name Type Definer Modified Created Security_type Comment
test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 3333333333
drop procedure bar|
drop procedure if exists p1|
create procedure p1 ()
select (select s1 from t3) from t3|
create table t3 (s1 int)|
call p1()|
(select s1 from t3)
insert into t3 values (1)|
call p1()|
(select s1 from t3)
1
drop procedure p1|
drop table t3|
drop function if exists foo|
create function `foo` () returns int
return 5|
select `foo` ()|
`foo` ()
5
drop function `foo`|
drop function if exists t1max|
call bug7743("AnotherWord")|
var
NULL
Warnings:
Note 1305 FUNCTION t1max does not exist
create function t1max() returns int
Warning 1329 No data to FETCH
drop procedure bug7743|
drop table t4|
delete from t3|
insert into t3 values(1)|
drop procedure if exists bug7992_1|
Warnings:
Note 1305 PROCEDURE bug7992_1 does not exist
drop procedure if exists bug7992_2|
Warnings:
Note 1305 PROCEDURE bug7992_2 does not exist
create procedure bug7992_1()
begin
declare x int;
select max(data) into x from t1;
return x;
declare i int;
select max(s1)+1 into i from t3;
end|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
select t1max()|
t1max()
5
drop function t1max|
create procedure bug7992_2()
insert into t3 (s1) select max(t4.s1)+1 from t3 as t4|
call bug7992_1()|
call bug7992_1()|
call bug7992_2()|
call bug7992_2()|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
drop table if exists t3|
create table t3 (
v char(16) not null primary key,
c int unsigned not null
)|
create function getcount(s char(16)) returns int
create table t3 ( userid bigint(20) not null default 0 )|
drop procedure if exists bug8116|
create procedure bug8116(in _userid int)
select * from t3 where userid = _userid|
call bug8116(42)|
userid
call bug8116(42)|
userid
drop procedure bug8116|
drop table t3|
drop procedure if exists bug6857|
create procedure bug6857(counter int)
begin
declare x int;
select count(*) into x from t3 where v = s;
if x = 0 then
insert into t3 values (s, 1);
else
update t3 set c = c+1 where v = s;
declare t0, t1 int;
declare plus bool default 0;
set t0 = current_time();
while counter > 0 do
set counter = counter - 1;
end while;
set t1 = current_time();
if t1 > t0 then
set plus = 1;
end if;
return x;
select plus;
end|
select * from t1 where data = getcount("bar")|
id data
zap 1
select * from t3|
v c
bar 4
select getcount("zip")|
getcount("zip")
0
select getcount("zip")|
getcount("zip")
1
select * from t3|
v c
bar 4
zip 2
select getcount(id) from t1 where data = 3|
getcount(id)
0
select getcount(id) from t1 where data = 5|
getcount(id)
1
select * from t3|
v c
bar 4
zip 3
foo 1
drop table t3|
drop function getcount|
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 procedure if exists bug8762|
drop procedure if exists bug8762; create procedure bug8762() begin end|
drop procedure if exists bug8762; create procedure bug8762() begin end|
drop procedure bug8762|
drop function if exists bug5240|
create function bug5240 () returns int
begin
......@@ -2696,43 +2697,62 @@ call bug7992()|
call bug7992()|
drop procedure bug7992|
drop table t3|
drop table t1;
drop table t2;
CREATE TABLE t1 (
lpitnumber int(11) default NULL,
lrecordtype int(11) default NULL
);
CREATE TABLE t2 (
lbsiid int(11) NOT NULL default '0',
ltradingmodeid int(11) NOT NULL default '0',
ltradingareaid int(11) NOT NULL default '0',
csellingprice decimal(19,4) default NULL,
PRIMARY KEY (lbsiid,ltradingmodeid,ltradingareaid)
);
CREATE TABLE t3 (
lbsiid int(11) NOT NULL default '0',
ltradingareaid int(11) NOT NULL default '0',
PRIMARY KEY (lbsiid,ltradingareaid)
);
CREATE PROCEDURE bug8849()
create table t3 (
lpitnumber int(11) default null,
lrecordtype int(11) default null
)|
create table t4 (
lbsiid int(11) not null default '0',
ltradingmodeid int(11) not null default '0',
ltradingareaid int(11) not null default '0',
csellingprice decimal(19,4) default null,
primary key (lbsiid,ltradingmodeid,ltradingareaid)
)|
create table t5 (
lbsiid int(11) not null default '0',
ltradingareaid int(11) not null default '0',
primary key (lbsiid,ltradingareaid)
)|
drop procedure if exists bug8849|
create procedure bug8849()
begin
insert into t3
insert into t5
(
t3.lbsiid,
t3.ltradingareaid
t5.lbsiid,
t5.ltradingareaid
)
select distinct t1.lpitnumber, t2.ltradingareaid
select distinct t3.lpitnumber, t4.ltradingareaid
from
t2 join t1 on
t1.lpitnumber = t2.lbsiid
and t1.lrecordtype = 1
left join t2 as price01 on
price01.lbsiid = t2.lbsiid and
t4 join t3 on
t3.lpitnumber = t4.lbsiid
and t3.lrecordtype = 1
left join t4 as price01 on
price01.lbsiid = t4.lbsiid and
price01.ltradingmodeid = 1 and
t2.ltradingareaid = price01.ltradingareaid;
t4.ltradingareaid = price01.ltradingareaid;
end|
call bug8849()|
call bug8849()|
call bug8849()|
drop procedure bug8849|
drop tables t3,t4,t5|
drop procedure if exists bug8937|
create procedure bug8937()
begin
declare s,x,y,z int;
declare a float;
select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1;
select s,x,y,z;
select avg(data) into a from t1;
select a;
end|
call bug8849();
call bug8849();
call bug8849();
drop procedure bug8849;
drop tables t1,t2,t3;
delete from t1|
insert into t1 (data) values (1), (2), (3), (4), (6)|
call bug8937()|
s x y z
16 3 1 6
a
3.2000
drop procedure bug8937|
delete from t1|
drop table t1,t2;
......@@ -1474,130 +1474,410 @@ delete from t2 |
#
# Test cases for old bugs
# Some "real" examples
#
#
# BUG#822
#
# fac
--disable_warnings
drop procedure if exists bug822|
drop table if exists fac|
--enable_warnings
create procedure bug822(a_id char(16), a_data int)
create table fac (n int unsigned not null primary key, f bigint unsigned)|
--disable_warnings
drop procedure if exists ifac|
--enable_warnings
create procedure ifac(n int unsigned)
begin
declare n int;
select count(*) into n from t1 where id = a_id and data = a_data;
if n = 0 then
insert into t1 (id, data) values (a_id, a_data);
declare i int unsigned default 1;
if n > 20 then
set n = 20; # bigint overflow otherwise
end if;
while i <= n do
begin
insert into test.fac values (i, fac(i));
set i = i + 1;
end;
end while;
end|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
select * from t1|
delete from t1|
drop procedure bug822|
call ifac(20)|
select * from fac|
drop table fac|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show function status like '%f%'|
drop procedure ifac|
drop function fac|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show function status like '%f%'|
# primes
#
# BUG#1495
#
--disable_warnings
drop procedure if exists bug1495|
drop table if exists primes|
--enable_warnings
create procedure bug1495()
create table primes (
i int unsigned not null primary key,
p bigint unsigned not null
)|
insert into primes values
( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13),
( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31),
(10, 37), (11, 41), (12, 43), (13, 47), (14, 53),
(15, 59), (16, 61), (17, 67), (18, 71), (19, 73),
(20, 79), (21, 83), (22, 89), (23, 97), (24, 101),
(25, 103), (26, 107), (27, 109), (28, 113), (29, 127),
(30, 131), (31, 137), (32, 139), (33, 149), (34, 151),
(35, 157), (36, 163), (37, 167), (38, 173), (39, 179),
(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)|
--disable_warnings
drop procedure if exists opp|
--enable_warnings
create procedure opp(n bigint unsigned, out pp bool)
begin
declare x int;
declare r double;
declare b, s bigint unsigned default 0;
select data into x from t1 order by id limit 1;
if x > 10 then
insert into t1 values ("less", x-10);
set r = sqrt(n);
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
insert into t1 values ("more", x+10);
begin
declare p bigint unsigned;
select t.p into p from test.primes t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
end if;
if mod(n, b+p) = 0 then
set pp = 0;
leave again;
end if;
set s = s+1;
end;
end if;
end loop;
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|
#
# BUG#1547
#
--disable_warnings
drop procedure if exists bug1547|
drop procedure if exists ip|
--enable_warnings
create procedure bug1547(s char(16))
create procedure ip(m int unsigned)
begin
declare x int;
declare p bigint unsigned;
declare i int unsigned;
select data into x from t1 where s = id limit 1;
if x > 10 then
insert into t1 values ("less", x-10);
else
insert into t1 values ("more", x+10);
set i=45, p=201;
while i < m do
begin
declare pp bool default 0;
call opp(p, pp);
if pp then
insert into test.primes values (i, p);
set i = i+1;
end if;
set p = p+2;
end;
end while;
end|
show create procedure opp|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like '%p%'|
insert into t1 values ("foo", 12), ("bar", 7)|
call bug1547("foo")|
call bug1547("bar")|
select * from t1|
delete from t1|
drop procedure bug1547|
# This isn't the fastest way in the world to compute prime numbers, so
# don't be too ambitious. ;-)
call ip(200)|
# We don't want to select the entire table here, just pick a few
# examples.
# The expected result is:
# i p
# --- ----
# 45 211
# 100 557
# 199 1229
select * from primes where i=45 or i=100 or i=199|
drop table primes|
drop procedure opp|
drop procedure ip|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like '%p%'|
# Fibonacci, for recursion test. (Yet Another Numerical series :)
#
# BUG#1656
#
--disable_warnings
drop table if exists t70|
drop table if exists fib|
--enable_warnings
create table t70 (s1 int,s2 int)|
insert into t70 values (1,2)|
create table fib ( f bigint unsigned not null )|
insert into fib values (1), (1)|
# We deliberately do it the awkward way, fetching the last two
# values from the table, in order to exercise various statements
# and table accesses at each turn.
--disable_warnings
drop procedure if exists bug1656|
drop procedure if exists fib|
--enable_warnings
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70|
create procedure fib(n int unsigned)
begin
if n > 0 then
begin
declare x, y bigint unsigned;
declare c cursor for select f from fib order by f desc limit 2;
open c;
fetch c into y;
fetch c into x;
close c;
insert into fib values (x+y);
call fib(n-1);
end;
end if;
end|
call fib(20)|
select * from fib order by f asc|
drop table fib|
drop procedure fib|
call bug1656(@1, @2)|
select @1, @2|
drop table t70|
drop procedure bug1656|
#
# BUG#1862
# Comment & suid
#
--disable_warnings
drop table if exists t3|
drop procedure if exists bar|
--enable_warnings
create table t3(a int)|
create procedure bar(x char(16), y int)
comment "111111111111" sql security invoker
insert into test.t1 values (x, y)|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like 'bar'|
alter procedure bar comment "2222222222" sql security definer|
alter procedure bar comment "3333333333"|
alter procedure bar|
show create procedure bar|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like 'bar'|
drop procedure bar|
#
# rexecution
#
--disable_warnings
drop procedure if exists bug1862|
drop procedure if exists p1|
--enable_warnings
create procedure bug1862()
begin
insert into t3 values(2);
flush tables;
end|
create procedure p1 ()
select (select s1 from t3) from t3|
call bug1862()|
# the second call caused a segmentation
call bug1862()|
select * from t3|
create table t3 (s1 int)|
call p1()|
insert into t3 values (1)|
call p1()|
drop procedure p1|
drop table t3|
drop procedure bug1862|
#
# BUG#1874
# backticks
#
--disable_warnings
drop function if exists foo|
--enable_warnings
create function `foo` () returns int
return 5|
select `foo` ()|
drop function `foo`|
#
# Implicit LOCK/UNLOCK TABLES for table access in functions
#
--disable_warning
drop function if exists t1max|
--enable_warnings
create function t1max() returns int
begin
declare x int;
select max(data) into x from t1;
return x;
end|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
select t1max()|
drop function t1max|
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (
v char(16) not null primary key,
c int unsigned not null
)|
create function getcount(s char(16)) returns int
begin
declare x int;
select count(*) into x from t3 where v = s;
if x = 0 then
insert into t3 values (s, 1);
else
update t3 set c = c+1 where v = s;
end if;
return x;
end|
select * from t1 where data = getcount("bar")|
select * from t3|
select getcount("zip")|
select getcount("zip")|
select * from t3|
select getcount(id) from t1 where data = 3|
select getcount(id) from t1 where data = 5|
select * from t3|
drop table t3|
drop function getcount|
#
# Test cases for old bugs
#
#
# BUG#822
#
--disable_warnings
drop procedure if exists bug822|
--enable_warnings
create procedure bug822(a_id char(16), a_data int)
begin
declare n int;
select count(*) into n from t1 where id = a_id and data = a_data;
if n = 0 then
insert into t1 (id, data) values (a_id, a_data);
end if;
end|
delete from t1|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
select * from t1|
delete from t1|
drop procedure bug822|
#
# BUG#1495
#
--disable_warnings
drop procedure if exists bug1495|
--enable_warnings
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|
#
# BUG#1547
#
--disable_warnings
drop procedure if exists bug1547|
--enable_warnings
create procedure bug1547(s char(16))
begin
declare x int;
select data into x from t1 where s = 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), ("bar", 7)|
call bug1547("foo")|
call bug1547("bar")|
select * from t1|
delete from t1|
drop procedure bug1547|
#
# BUG#1656
#
--disable_warnings
drop table if exists t70|
--enable_warnings
create table t70 (s1 int,s2 int)|
insert into t70 values (1,2)|
--disable_warnings
drop procedure if exists bug1656|
--enable_warnings
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70|
call bug1656(@1, @2)|
select @1, @2|
drop table t70|
drop procedure bug1656|
#
# BUG#1862
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3(a int)|
--disable_warnings
drop procedure if exists bug1862|
--enable_warnings
create procedure bug1862()
begin
insert into t3 values(2);
flush tables;
end|
call bug1862()|
# the second call caused a segmentation
call bug1862()|
select * from t3|
drop table t3|
drop procedure bug1862|
#
# BUG#1874
#
--disable_warnings
drop procedure if exists bug1874|
......@@ -1790,1423 +2070,1145 @@ drop procedure BUG3259_3|
# BUG#2772
#
--disable_warnings
drop function if exists bug2772|
--enable_warnings
create function bug2772() returns char(10) character set latin2
return 'a'|
select bug2772()|
drop function bug2772|
#
# BUG#2776
#
--disable_warnings
drop procedure if exists bug2776_1|
--enable_warnings
create procedure bug2776_1(out x int)
begin
declare v int;
set v = default;
set x = v;
end|
--disable_warnings
drop procedure if exists bug2776_2|
--enable_warnings
create procedure bug2776_2(out x int)
begin
declare v int default 42;
set v = default;
set x = v;
end|
set @x = 1|
call bug2776_1(@x)|
select @x|
call bug2776_2(@x)|
select @x|
drop procedure bug2776_1|
drop procedure bug2776_2|
#
# BUG#2780
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (s1 smallint)|
insert into t3 values (123456789012)|
--disable_warnings
drop procedure if exists bug2780|
--enable_warnings
create procedure bug2780()
begin
declare exit handler for sqlwarning set @x = 1;
set @x = 0;
insert into t3 values (123456789012);
insert into t3 values (0);
end|
call bug2780()|
select @x|
select * from t3|
drop procedure bug2780|
drop table t3|
#
# BUG#1863
#
create table t3 (content varchar(10) )|
insert into t3 values ("test1")|
insert into t3 values ("test2")|
create table t4 (f1 int, rc int, t3 int)|
--disable_warnings
drop procedure if exists bug1863|
--enable_warnings
create procedure bug1863(in1 int)
begin
declare ind int default 0;
declare t1 int;
declare t2 int;
declare t3 int;
declare rc int default 0;
declare continue handler for 1065 set rc = 1;
drop temporary table if exists temp_t1;
create temporary table temp_t1 (
f1 int auto_increment, f2 varchar(20), primary key (f1)
);
insert into temp_t1 (f2) select content from t3;
select f2 into t3 from temp_t1 where f1 = 10;
if (rc) then
insert into t4 values (1, rc, t3);
end if;
insert into t4 values (2, rc, t3);
end|
call bug1863(10)|
call bug1863(10)|
select * from t4|
drop procedure bug1863|
drop temporary table temp_t1;
drop table t3, t4|
#
# BUG#2656
#
--disable_warnings
drop table if exists t3, t4|
--enable_warnings
create table t3 (
OrderID int not null,
MarketID int,
primary key (OrderID)
)|
create table t4 (
MarketID int not null,
Market varchar(60),
Status char(1),
primary key (MarketID)
)|
insert t3 (OrderID,MarketID) values (1,1)|
insert t3 (OrderID,MarketID) values (2,2)|
insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")|
insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")|
--disable_warnings
drop procedure if exists bug2656_1|
--enable_warnings
create procedure bug2656_1()
begin
select
m.Market
from t4 m JOIN t3 o
ON o.MarketID != 1 and o.MarketID = m.MarketID;
end |
--disable_warnings
drop procedure if exists bug2656_2|
--enable_warnings
create procedure bug2656_2()
begin
select
m.Market
from
t4 m, t3 o
where
m.MarketID != 1 and m.MarketID = o.MarketID;
end |
call bug2656_1()|
call bug2656_1()|
call bug2656_2()|
call bug2656_2()|
drop procedure bug2656_1|
drop procedure bug2656_2|
drop table t3, t4|
#
# BUG#3426
#
--disable_warnings
drop procedure if exists bug3426|
--enable_warnings
create procedure bug3426(in_time int unsigned, out x int)
begin
if in_time is null then
set @stamped_time=10;
set x=1;
else
set @stamped_time=in_time;
set x=2;
end if;
end|
call bug3426(1000, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
call bug3426(NULL, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
# Clear SP cache
alter procedure bug3426 sql security invoker|
call bug3426(NULL, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
call bug3426(1000, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
drop procedure bug3426|
#
# BUG#3448
#
--disable_warnings
drop table if exists t3, t4|
create table t3 (
a int primary key,
ach char(1)
) engine = innodb|
create table t4 (
b int primary key ,
bch char(1)
) engine = innodb|
--enable_warnings
insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')|
insert into t4 values (1 , 'bCh1' )|
--disable_warnings
drop procedure if exists bug3448|
--enable_warnings
create procedure bug3448()
select * from t3 inner join t4 on t3.a = t4.b|
select * from t3 inner join t4 on t3.a = t4.b|
call bug3448()|
call bug3448()|
drop procedure bug3448|
drop table t3, t4|
#
# BUG#3734
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (
id int unsigned auto_increment not null primary key,
title VARCHAR(200),
body text,
fulltext (title,body)
)|
insert into t3 (title,body) values
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...')|
--disable_warnings
drop procedure if exists bug3734 |
--enable_warnings
create procedure bug3734 (param1 varchar(100))
select * from t3 where match (title,body) against (param1)|
call bug3734('database')|
call bug3734('Security')|
drop procedure bug3734|
drop table t3|
#
# BUG#3863
#
--disable_warnings
drop procedure if exists bug3863|
--enable_warnings
create procedure bug3863()
begin
set @a = 0;
while @a < 5 do
set @a = @a + 1;
end while;
end|
call bug3863()|
select @a|
call bug3863()|
select @a|
drop procedure bug3863|
#
# BUG#2460
#
create table t3 (
id int(10) unsigned not null default 0,
rid int(10) unsigned not null default 0,
msg text not null,
primary key (id),
unique key rid (rid, id)
)|
--disable_warnings
drop procedure if exists bug2460_1|
--enable_warnings
create procedure bug2460_1(in v int)
begin
( select n0.id from t3 as n0 where n0.id = v )
union
( select n0.id from t3 as n0, t3 as n1
where n0.id = n1.rid and n1.id = v )
union
( select n0.id from t3 as n0, t3 as n1, t3 as n2
where n0.id = n1.rid and n1.id = n2.rid and n2.id = v );
end|
call bug2460_1(2)|
call bug2460_1(2)|
insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')|
call bug2460_1(2)|
call bug2460_1(2)|
--disable_warnings
drop procedure if exists bug2460_2|
--enable_warnings
create procedure bug2460_2()
begin
drop table if exists t3;
create temporary table t3 (s1 int);
insert into t3 select 1 union select 1;
end|
call bug2460_2()|
call bug2460_2()|
select * from t3|
drop procedure bug2460_1|
drop procedure bug2460_2|
drop table t3|
#
# BUG#2564
#
set @@sql_mode = ''|
--disable_warnings
drop procedure if exists bug2564_1|
--enable_warnings
create procedure bug2564_1()
comment 'Joe''s procedure'
insert into `t1` values ("foo", 1)|
set @@sql_mode = 'ANSI_QUOTES'|
--disable_warnings
drop procedure if exists bug2564_2|
--enable_warnings
create procedure bug2564_2()
insert into "t1" values ('foo', 1)|
delimiter $|
set @@sql_mode = ''$
--disable_warnings
drop function if exists bug2564_3$
--enable_warnings
create function bug2564_3(x int, y int) returns int
return x || y$
set @@sql_mode = 'ANSI'$
--disable_warnings
drop function if exists bug2564_4$
--enable_warnings
create function bug2564_4(x int, y int) returns int
return x || y$
delimiter |$
set @@sql_mode = ''|
show create procedure bug2564_1|
show create procedure bug2564_2|
show create function bug2564_3|
show create function bug2564_4|
drop procedure bug2564_1|
drop procedure bug2564_2|
drop function bug2564_3|
drop function bug2564_4|
#
# BUG#3132
#
--disable_warnings
drop function if exists bug3132|
--enable_warnings
create function bug3132(s char(20)) returns char(50)
return concat('Hello, ', s, '!')|
select bug3132('Bob') union all select bug3132('Judy')|
drop function bug3132|
#
# BUG#3843
#
--disable_warnings
drop procedure if exists bug3843|
drop function if exists bug2772|
--enable_warnings
create procedure bug3843()
analyze table t1|
# Testing for packets out of order
call bug3843()|
call bug3843()|
select 1+2|
create function bug2772() returns char(10) character set latin2
return 'a'|
drop procedure bug3843|
select bug2772()|
drop function bug2772|
#
# BUG#3368
# BUG#2776
#
--disable_warnings
drop table if exists t3|
drop procedure if exists bug2776_1|
--enable_warnings
create table t3 ( s1 char(10) )|
insert into t3 values ('a'), ('b')|
create procedure bug2776_1(out x int)
begin
declare v int;
set v = default;
set x = v;
end|
--disable_warnings
drop procedure if exists bug3368|
drop procedure if exists bug2776_2|
--enable_warnings
create procedure bug3368(v char(10))
create procedure bug2776_2(out x int)
begin
select group_concat(v) from t3;
declare v int default 42;
set v = default;
set x = v;
end|
call bug3368('x')|
call bug3368('yz')|
drop procedure bug3368|
drop table t3|
set @x = 1|
call bug2776_1(@x)|
select @x|
call bug2776_2(@x)|
select @x|
drop procedure bug2776_1|
drop procedure bug2776_2|
#
# BUG#4579
# BUG#2780
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (f1 int, f2 int)|
insert into t3 values (1,1)|
create table t3 (s1 smallint)|
insert into t3 values (123456789012)|
--disable_warnings
drop procedure if exists bug4579_1|
drop procedure if exists bug2780|
--enable_warnings
create procedure bug4579_1 ()
create procedure bug2780()
begin
declare sf1 int;
declare exit handler for sqlwarning set @x = 1;
select f1 into sf1 from t3 where f1=1 and f2=1;
update t3 set f2 = f2 + 1 where f1=1 and f2=1;
call bug4579_2();
set @x = 0;
insert into t3 values (123456789012);
insert into t3 values (0);
end|
call bug2780()|
select @x|
select * from t3|
drop procedure bug2780|
drop table t3|
#
# BUG#1863
#
create table t3 (content varchar(10) )|
insert into t3 values ("test1")|
insert into t3 values ("test2")|
create table t4 (f1 int, rc int, t3 int)|
--disable_warnings
drop procedure if exists bug4579_2|
drop procedure if exists bug1863|
--enable_warnings
create procedure bug4579_2 ()
create procedure bug1863(in1 int)
begin
end|
call bug4579_1()|
call bug4579_1()|
call bug4579_1()|
declare ind int default 0;
declare t1 int;
declare t2 int;
declare t3 int;
drop procedure bug4579_1|
drop procedure bug4579_2|
drop table t3|
declare rc int default 0;
declare continue handler for 1065 set rc = 1;
drop temporary table if exists temp_t1;
create temporary table temp_t1 (
f1 int auto_increment, f2 varchar(20), primary key (f1)
);
insert into temp_t1 (f2) select content from t3;
select f2 into t3 from temp_t1 where f1 = 10;
if (rc) then
insert into t4 values (1, rc, t3);
end if;
insert into t4 values (2, rc, t3);
end|
call bug1863(10)|
call bug1863(10)|
select * from t4|
drop procedure bug1863|
drop temporary table temp_t1;
drop table t3, t4|
#
# BUG#4726
# BUG#2656
#
--disable_warnings
drop table if exists t3|
drop table if exists t3, t4|
--enable_warnings
create table t3 (f1 int, f2 int, f3 int)|
insert into t3 values (1,1,1)|
create table t3 (
OrderID int not null,
MarketID int,
primary key (OrderID)
)|
create table t4 (
MarketID int not null,
Market varchar(60),
Status char(1),
primary key (MarketID)
)|
insert t3 (OrderID,MarketID) values (1,1)|
insert t3 (OrderID,MarketID) values (2,2)|
insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")|
insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")|
--disable_warnings
drop procedure if exists bug4726|
drop procedure if exists bug2656_1|
--enable_warnings
create procedure bug4726()
create procedure bug2656_1()
begin
declare tmp_o_id INT;
declare tmp_d_id INT default 1;
select
m.Market
from t4 m JOIN t3 o
ON o.MarketID != 1 and o.MarketID = m.MarketID;
end |
while tmp_d_id <= 2 do
begin
select f1 into tmp_o_id from t3 where f2=1 and f3=1;
set tmp_d_id = tmp_d_id + 1;
end;
end while;
end|
--disable_warnings
drop procedure if exists bug2656_2|
--enable_warnings
create procedure bug2656_2()
begin
select
m.Market
from
t4 m, t3 o
where
m.MarketID != 1 and m.MarketID = o.MarketID;
call bug4726()|
call bug4726()|
call bug4726()|
end |
drop procedure bug4726|
drop table t3|
call bug2656_1()|
call bug2656_1()|
call bug2656_2()|
call bug2656_2()|
drop procedure bug2656_1|
drop procedure bug2656_2|
drop table t3, t4|
#
# BUG#4318
#
#QQ Don't know if HANDLER commands can work with SPs, or at all...
#--disable_warnings
#drop table if exists t3|
#--enable_warnings
#
#create table t3 (s1 int)|
#insert into t3 values (3), (4)|
#
#--disable_warnings
#drop procedure if exists bug4318|
#--enable_warnings
#create procedure bug4318()
# handler t3 read next|
#
#handler t3 open|
## Expect no results, as tables are closed, but there shouldn't be any errors
#call bug4318()|
#call bug4318()|
#handler t3 close|
#
#drop procedure bug4318|
#drop table t3|
#
# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error
#
# Added tests for most other show commands we could find too.
# (Skipping those already tested, and the ones depending on optional handlers.)
#
# Note: This will return a large number of results of different formats,
# which makes it impossible to filter with --replace_column.
# It's possible that some of these are not deterministic across
# platforms. If so, just remove the offending command.
# BUG#3426
#
--disable_warnings
drop procedure if exists bug4902|
drop procedure if exists bug3426|
--enable_warnings
create procedure bug4902()
create procedure bug3426(in_time int unsigned, out x int)
begin
show charset like 'foo';
show collation like 'foo';
show column types;
show create table t1;
show create database test;
show databases like 'foo';
show errors;
show columns from t1;
show grants for 'root'@'localhost';
show keys from t1;
show open tables like 'foo';
show privileges;
show status like 'foo';
show tables like 'foo';
show variables like 'foo';
show warnings;
if in_time is null then
set @stamped_time=10;
set x=1;
else
set @stamped_time=in_time;
set x=2;
end if;
end|
#show binlog events;
#show storage engines;
#show master status;
#show slave hosts;
#show slave status;
call bug4902()|
call bug4902()|
drop procedure bug4902|
call bug3426(1000, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
call bug3426(NULL, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
# Clear SP cache
alter procedure bug3426 sql security invoker|
call bug3426(NULL, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
call bug3426(1000, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
# We need separate SP for SHOW PROCESSLIST since we want use replace_column
--disable_warnings
drop procedure if exists bug4902_2|
--enable_warnings
create procedure bug4902_2()
begin
show processlist;
end|
--replace_column 1 # 6 #
call bug4902_2()|
--replace_column 1 # 6 #
call bug4902_2()|
drop procedure bug4902_2|
drop procedure bug3426|
#
# BUG#4904
# BUG#3448
#
--disable_warnings
drop table if exists t3|
drop table if exists t3, t4|
create table t3 (
a int primary key,
ach char(1)
) engine = innodb|
create table t4 (
b int primary key ,
bch char(1)
) engine = innodb|
--enable_warnings
insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')|
insert into t4 values (1 , 'bCh1' )|
--disable_warnings
drop procedure if exists bug4904|
drop procedure if exists bug3448|
--enable_warnings
create procedure bug4904()
begin
declare continue handler for sqlstate 'HY000' begin end;
create table t2 as select * from t3;
end|
create procedure bug3448()
select * from t3 inner join t4 on t3.a = t4.b|
-- error 1146
call bug4904()|
select * from t3 inner join t4 on t3.a = t4.b|
call bug3448()|
call bug3448()|
drop procedure bug4904|
drop procedure bug3448|
drop table t3, t4|
create table t3 (s1 char character set latin1, s2 char character set latin2)|
#
# BUG#3734
#
--disable_warnings
drop procedure if exists bug4904|
drop table if exists t3|
--enable_warnings
create procedure bug4904 ()
begin
declare continue handler for sqlstate 'HY000' begin end;
create table t3 (
id int unsigned auto_increment not null primary key,
title VARCHAR(200),
body text,
fulltext (title,body)
)|
select s1 from t3 union select s2 from t3;
end|
insert into t3 (title,body) values
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...')|
call bug4904()|
--disable_warnings
drop procedure if exists bug3734 |
--enable_warnings
create procedure bug3734 (param1 varchar(100))
select * from t3 where match (title,body) against (param1)|
drop procedure bug4904|
call bug3734('database')|
call bug3734('Security')|
drop procedure bug3734|
drop table t3|
#
# BUG#336
# BUG#3863
#
--disable_warnings
drop procedure if exists bug336|
drop procedure if exists bug3863|
--enable_warnings
create procedure bug336(out y int)
create procedure bug3863()
begin
declare x int;
set x = (select sum(t.data) from test.t1 t);
set y = x;
set @a = 0;
while @a < 5 do
set @a = @a + 1;
end while;
end|
insert into t1 values ("a", 2), ("b", 3)|
call bug336(@y)|
select @y|
delete from t1|
drop procedure bug336|
call bug3863()|
select @a|
call bug3863()|
select @a|
drop procedure bug3863|
#
# BUG#3157
# BUG#2460
#
create table t3 (
id int(10) unsigned not null default 0,
rid int(10) unsigned not null default 0,
msg text not null,
primary key (id),
unique key rid (rid, id)
)|
--disable_warnings
drop procedure if exists bug3157|
drop procedure if exists bug2460_1|
--enable_warnings
create procedure bug3157()
create procedure bug2460_1(in v int)
begin
if exists(select * from t1) then
set @n= @n + 1;
end if;
if (select count(*) from t1) then
set @n= @n + 1;
end if;
( select n0.id from t3 as n0 where n0.id = v )
union
( select n0.id from t3 as n0, t3 as n1
where n0.id = n1.rid and n1.id = v )
union
( select n0.id from t3 as n0, t3 as n1, t3 as n2
where n0.id = n1.rid and n1.id = n2.rid and n2.id = v );
end|
set @n = 0|
insert into t1 values ("a", 1)|
call bug3157()|
select @n|
delete from t1|
drop procedure bug3157|
call bug2460_1(2)|
call bug2460_1(2)|
insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')|
call bug2460_1(2)|
call bug2460_1(2)|
#
# BUG#5251: mysql changes creation time of a procedure/function when altering
#
--disable_warnings
drop procedure if exists bug5251|
drop procedure if exists bug2460_2|
--enable_warnings
create procedure bug5251()
create procedure bug2460_2()
begin
drop table if exists t3;
create temporary table t3 (s1 int);
insert into t3 select 1 union select 1;
end|
select created into @c1 from mysql.proc
where db='test' and name='bug5251'|
--sleep 2
alter procedure bug5251 comment 'foobar'|
select count(*) from mysql.proc
where db='test' and name='bug5251' and created = @c1|
call bug2460_2()|
call bug2460_2()|
select * from t3|
drop procedure bug2460_1|
drop procedure bug2460_2|
drop table t3|
drop procedure bug5251|
#
# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE
# BUG#2564
#
set @@sql_mode = ''|
--disable_warnings
drop procedure if exists bug5251|
drop procedure if exists bug2564_1|
--enable_warnings
create procedure bug5251()
checksum table t1|
call bug5251()|
call bug5251()|
drop procedure bug5251|
create procedure bug2564_1()
comment 'Joe''s procedure'
insert into `t1` values ("foo", 1)|
#
# BUG#5287: Stored procedure crash if leave outside loop
#
set @@sql_mode = 'ANSI_QUOTES'|
--disable_warnings
drop procedure if exists bug5287|
drop procedure if exists bug2564_2|
--enable_warnings
create procedure bug5287(param1 int)
label1:
begin
declare c cursor for select 5;
loop
if param1 >= 0 then
leave label1;
end if;
end loop;
end|
call bug5287(1)|
drop procedure bug5287|
create procedure bug2564_2()
insert into "t1" values ('foo', 1)|
#
# BUG#5307: Stored procedure allows statement after BEGIN ... END
#
delimiter $|
set @@sql_mode = ''$
--disable_warnings
drop procedure if exists bug5307|
drop function if exists bug2564_3$
--enable_warnings
create procedure bug5307()
begin
end; set @x = 3|
call bug5307()|
select @x|
drop procedure bug5307|
create function bug2564_3(x int, y int) returns int
return x || y$
#
# BUG#5258: Stored procedure modified date is 0000-00-00
# (This was a design flaw)
set @@sql_mode = 'ANSI'$
--disable_warnings
drop procedure if exists bug5258|
drop function if exists bug2564_4$
--enable_warnings
create procedure bug5258()
begin
end|
create function bug2564_4(x int, y int) returns int
return x || y$
delimiter |$
set @@sql_mode = ''|
show create procedure bug2564_1|
show create procedure bug2564_2|
show create function bug2564_3|
show create function bug2564_4|
drop procedure bug2564_1|
drop procedure bug2564_2|
drop function bug2564_3|
drop function bug2564_4|
#
# BUG#3132
#
--disable_warnings
drop procedure if exists bug5258_aux|
drop function if exists bug3132|
--enable_warnings
create procedure bug5258_aux()
begin
declare c, m char(19);
select created,modified into c,m from mysql.proc where name = 'bug5258';
if c = m then
select 'Ok';
else
select c, m;
end if;
end|
call bug5258_aux()|
create function bug3132(s char(20)) returns char(50)
return concat('Hello, ', s, '!')|
drop procedure bug5258|
drop procedure bug5258_aux|
select bug3132('Bob') union all select bug3132('Judy')|
drop function bug3132|
#
# BUG#4487: Stored procedure connection aborted if uninitialized char
# BUG#3843
#
--disable_warnings
drop function if exists bug4487|
drop procedure if exists bug3843|
--enable_warnings
create function bug4487() returns char
begin
declare v char;
return v;
end|
create procedure bug3843()
analyze table t1|
select bug4487()|
drop function bug4487|
# Testing for packets out of order
call bug3843()|
call bug3843()|
select 1+2|
drop procedure bug3843|
#
# BUG#4941: Stored procedure crash fetching null value into variable.
# BUG#3368
#
--disable_warnings
drop procedure if exists bug4941|
drop table if exists t3|
--enable_warnings
create table t3 ( s1 char(10) )|
insert into t3 values ('a'), ('b')|
--disable_warnings
drop procedure if exists bug4941|
drop procedure if exists bug3368|
--enable_warnings
create procedure bug4941(out x int)
create procedure bug3368(v char(10))
begin
declare c cursor for select i from t2 limit 1;
open c;
fetch c into x;
close c;
select group_concat(v) from t3;
end|
insert into t2 values (null, null, null)|
set @x = 42|
call bug4941(@x)|
select @x|
delete from t1|
drop procedure bug4941|
call bug3368('x')|
call bug3368('yz')|
drop procedure bug3368|
drop table t3|
#
# BUG#3583: query cache doesn't work for stored procedures
# BUG#4579
#
--disable_warnings
drop procedure if exists bug3583|
drop table if exists t3|
--enable_warnings
create table t3 (f1 int, f2 int)|
insert into t3 values (1,1)|
--disable_warnings
drop procedure if exists bug3583|
drop procedure if exists bug4579_1|
--enable_warnings
create procedure bug3583()
create procedure bug4579_1 ()
begin
declare c int;
declare sf1 int;
select * from t1;
select count(*) into c from t1;
select c;
select f1 into sf1 from t3 where f1=1 and f2=1;
update t3 set f2 = f2 + 1 where f1=1 and f2=1;
call bug4579_2();
end|
insert into t1 values ("x", 3), ("y", 5)|
set @x = @@query_cache_size|
set global query_cache_size = 10*1024*1024|
--disable_warnings
drop procedure if exists bug4579_2|
--enable_warnings
create procedure bug4579_2 ()
begin
end|
flush status|
flush query cache|
show status like 'Qcache_hits'|
call bug3583()|
show status like 'Qcache_hits'|
call bug3583()|
call bug3583()|
show status like 'Qcache_hits'|
call bug4579_1()|
call bug4579_1()|
call bug4579_1()|
drop procedure bug4579_1|
drop procedure bug4579_2|
drop table t3|
set global query_cache_size = @x|
flush status|
flush query cache|
delete from t1|
drop procedure bug3583|
#
# BUG#4905: Stored procedure doesn't clear for "Rows affected"
# BUG#4726
#
--disable_warnings
drop table if exists t3|
drop procedure if exists bug4905|
--enable_warnings
create table t3 (s1 int,primary key (s1))|
create table t3 (f1 int, f2 int, f3 int)|
insert into t3 values (1,1,1)|
--disable_warnings
drop procedure if exists bug4905|
drop procedure if exists bug4726|
--enable_warnings
create procedure bug4905()
create procedure bug4726()
begin
declare v int;
declare continue handler for sqlstate '23000' set v = 5;
declare tmp_o_id INT;
declare tmp_d_id INT default 1;
insert into t3 values (1);
while tmp_d_id <= 2 do
begin
select f1 into tmp_o_id from t3 where f2=1 and f3=1;
set tmp_d_id = tmp_d_id + 1;
end;
end while;
end|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
select * from t3|
call bug4726()|
call bug4726()|
call bug4726()|
drop procedure bug4905|
drop procedure bug4726|
drop table t3|
#
# BUG#6022: Stored procedure shutdown problem with self-calling function.
# BUG#4318
#
#QQ Don't know if HANDLER commands can work with SPs, or at all...
#--disable_warnings
#drop table if exists t3|
#--enable_warnings
#
#create table t3 (s1 int)|
#insert into t3 values (3), (4)|
#
#--disable_warnings
#drop procedure if exists bug4318|
#--enable_warnings
#create procedure bug4318()
# handler t3 read next|
#
#handler t3 open|
## Expect no results, as tables are closed, but there shouldn't be any errors
#call bug4318()|
#call bug4318()|
#handler t3 close|
#
#drop procedure bug4318|
#drop table t3|
#
# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error
#
# Added tests for most other show commands we could find too.
# (Skipping those already tested, and the ones depending on optional handlers.)
#
# Note: This will return a large number of results of different formats,
# which makes it impossible to filter with --replace_column.
# It's possible that some of these are not deterministic across
# platforms. If so, just remove the offending command.
#
--disable_warnings
drop function if exists bug6022|
drop procedure if exists bug4902|
--enable_warnings
create procedure bug4902()
begin
show charset like 'foo';
show collation like 'foo';
show column types;
show create table t1;
show create database test;
show databases like 'foo';
show errors;
show columns from t1;
show grants for 'root'@'localhost';
show keys from t1;
show open tables like 'foo';
show privileges;
show status like 'foo';
show tables like 'foo';
show variables like 'foo';
show warnings;
end|
#show binlog events;
#show storage engines;
#show master status;
#show slave hosts;
#show slave status;
call bug4902()|
call bug4902()|
drop procedure bug4902|
# We need separate SP for SHOW PROCESSLIST since we want use replace_column
--disable_warnings
drop function if exists bug6022|
drop procedure if exists bug4902_2|
--enable_warnings
create function bug6022(x int) returns int
create procedure bug4902_2()
begin
if x < 0 then
return 0;
else
return bug6022(x-1);
end if;
show processlist;
end|
select bug6022(5)|
drop function bug6022|
--replace_column 1 # 6 #
call bug4902_2()|
--replace_column 1 # 6 #
call bug4902_2()|
drop procedure bug4902_2|
#
# BUG#6029: Stored procedure specific handlers should have priority
# BUG#4904
#
--disable_warnings
drop procedure if exists bug6029|
drop table if exists t3|
--enable_warnings
--disable_warnings
drop procedure if exists bug4904|
--enable_warnings
create procedure bug4904()
begin
declare continue handler for sqlstate 'HY000' begin end;
create table t2 as select * from t3;
end|
-- error 1146
call bug4904()|
drop procedure bug4904|
create table t3 (s1 char character set latin1, s2 char character set latin2)|
--disable_warnings
drop procedure if exists bug6029|
drop procedure if exists bug4904|
--enable_warnings
create procedure bug6029()
create procedure bug4904 ()
begin
declare exit handler for 1136 select '1136';
declare exit handler for sqlstate '23000' select 'sqlstate 23000';
declare continue handler for sqlexception select 'sqlexception';
declare continue handler for sqlstate 'HY000' begin end;
insert into t3 values (1);
insert into t3 values (1,2);
select s1 from t3 union select s2 from t3;
end|
create table t3 (s1 int, primary key (s1))|
insert into t3 values (1)|
call bug6029()|
delete from t3|
call bug6029()|
call bug4904()|
drop procedure bug6029|
drop procedure bug4904|
drop table t3|
#
# BUG#8540: Local variable overrides an alias
# BUG#336
#
--disable_warnings
drop procedure if exists bug8540|
drop procedure if exists bug336|
--enable_warnings
create procedure bug8540()
create procedure bug336(out y int)
begin
declare x int default 1;
select x as y, x+0 as z;
declare x int;
set x = (select sum(t.data) from test.t1 t);
set y = x;
end|
call bug8540()|
drop procedure bug8540|
insert into t1 values ("a", 2), ("b", 3)|
call bug336(@y)|
select @y|
delete from t1|
drop procedure bug336|
#
# BUG#6642: Stored procedure crash if expression with set function
# BUG#3157
#
--disable_warnings
drop table if exists t3|
drop procedure if exists bug3157|
--enable_warnings
create table t3 (s1 int)|
create procedure bug3157()
begin
if exists(select * from t1) then
set @n= @n + 1;
end if;
if (select count(*) from t1) then
set @n= @n + 1;
end if;
end|
set @n = 0|
insert into t1 values ("a", 1)|
call bug3157()|
select @n|
delete from t1|
drop procedure bug3157|
#
# BUG#5251: mysql changes creation time of a procedure/function when altering
#
--disable_warnings
drop procedure if exists bug6642|
drop procedure if exists bug5251|
--enable_warnings
create procedure bug5251()
begin
end|
create procedure bug6642()
select abs(count(s1)) from t3|
select created into @c1 from mysql.proc
where db='test' and name='bug5251'|
--sleep 2
alter procedure bug5251 comment 'foobar'|
select count(*) from mysql.proc
where db='test' and name='bug5251' and created = @c1|
call bug6642()|
call bug6642()|
drop procedure bug6642|
drop procedure bug5251|
#
# BUG#7013: Stored procedure crash if group by ... with rollup
# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE
#
insert into t3 values (0),(1)|
--disable_warnings
drop procedure if exists bug7013|
drop procedure if exists bug5251|
--enable_warnings
create procedure bug7013()
select s1,count(s1) from t3 group by s1 with rollup|
call bug7013()|
call bug7013()|
drop procedure bug7013|
create procedure bug5251()
checksum table t1|
call bug5251()|
call bug5251()|
drop procedure bug5251|
#
# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure
# BUG#5287: Stored procedure crash if leave outside loop
#
--disable_warnings
drop table if exists t4|
drop procedure if exists bug5287|
--enable_warnings
create table t4 (
a mediumint(8) unsigned not null auto_increment,
b smallint(5) unsigned not null,
c char(32) not null,
primary key (a)
) engine=myisam default charset=latin1|
insert into t4 values (1, 2, 'oneword')|
insert into t4 values (2, 2, 'anotherword')|
create procedure bug5287(param1 int)
label1:
begin
declare c cursor for select 5;
--disable_warnings
drop procedure if exists bug7743|
--enable_warnings
create procedure bug7743 ( searchstring char(28) )
begin
declare var mediumint(8) unsigned;
select a into var from t4 where b = 2 and c = binary searchstring limit 1;
select var;
loop
if param1 >= 0 then
leave label1;
end if;
end loop;
end|
call bug5287(1)|
drop procedure bug5287|
call bug7743("oneword")|
call bug7743("OneWord")|
call bug7743("anotherword")|
call bug7743("AnotherWord")|
drop procedure bug7743|
drop table t4|
#
# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes
# the server
# BUG#5307: Stored procedure allows statement after BEGIN ... END
#
delete from t3|
insert into t3 values(1)|
drop procedure if exists bug7992_1|
drop procedure if exists bug7992_2|
create procedure bug7992_1()
--disable_warnings
drop procedure if exists bug5307|
--enable_warnings
create procedure bug5307()
begin
declare i int;
select max(s1)+1 into i from t3;
end|
create procedure bug7992_2()
insert into t3 (s1) select max(t4.s1)+1 from t3 as t4|
call bug7992_1()|
call bug7992_1()|
call bug7992_2()|
call bug7992_2()|
end; set @x = 3|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
call bug5307()|
select @x|
drop procedure bug5307|
#
# BUG#8116: calling simple stored procedure twice in a row results
# in server crash
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 ( userid bigint(20) not null default 0 )|
# BUG#5258: Stored procedure modified date is 0000-00-00
# (This was a design flaw)
--disable_warnings
drop procedure if exists bug8116|
drop procedure if exists bug5258|
--enable_warnings
create procedure bug8116(in _userid int)
select * from t3 where userid = _userid|
call bug8116(42)|
call bug8116(42)|
drop procedure bug8116|
drop table t3|
create procedure bug5258()
begin
end|
#
# BUG#6857: current_time() in STORED PROCEDURES
#
--disable_warnings
drop procedure if exists bug6857|
drop procedure if exists bug5258_aux|
--enable_warnings
create procedure bug6857(counter int)
create procedure bug5258_aux()
begin
declare t0, t1 int;
declare plus bool default 0;
declare c, m char(19);
set t0 = current_time();
while counter > 0 do
set counter = counter - 1;
end while;
set t1 = current_time();
if t1 > t0 then
set plus = 1;
select created,modified into c,m from mysql.proc where name = 'bug5258';
if c = m then
select 'Ok';
else
select c, m;
end if;
select plus;
end|
# QQ: This is currently disabled. Not only does it slow down a normal test
# run, it makes running with valgrind (or similar tools) extremely
# painful.
# Make sure this takes at least one second on all machines in all builds.
# 30000 makes it about 3 seconds on an old 1.1GHz linux.
#call bug6857(300000)|
call bug5258_aux()|
drop procedure bug6857|
drop procedure bug5258|
drop procedure bug5258_aux|
#
# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not
# work properly.
# BUG#4487: Stored procedure connection aborted if uninitialized char
#
--disable_warnings
drop procedure if exists bug8757|
drop function if exists bug4487|
--enable_warnings
create procedure bug8757()
create function bug4487() returns char
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|
declare v char;
return v;
end|
select bug4487()|
drop function bug4487|
#
# BUG#8762: Stored Procedures: Inconsistent behavior
# of DROP PROCEDURE IF EXISTS statement.
# BUG#4941: Stored procedure crash fetching null value into variable.
#
--disable_warnings
drop procedure if exists bug8762|
drop procedure if exists bug4941|
--enable_warnings
# Doesn't exist
drop procedure if exists bug8762; create procedure bug8762() begin end|
# Does exist
drop procedure if exists bug8762; create procedure bug8762() begin end|
drop procedure bug8762|
--disable_warnings
drop procedure if exists bug4941|
--enable_warnings
create procedure bug4941(out x int)
begin
declare c cursor for select i from t2 limit 1;
open c;
fetch c into x;
close c;
end|
insert into t2 values (null, null, null)|
set @x = 42|
call bug4941(@x)|
select @x|
delete from t1|
drop procedure bug4941|
#
# Some "real" examples
# BUG#3583: query cache doesn't work for stored procedures
#
# fac
--disable_warnings
drop table if exists fac|
drop procedure if exists bug3583|
--enable_warnings
create table fac (n int unsigned not null primary key, f bigint unsigned)|
--disable_warnings
drop procedure if exists ifac|
drop procedure if exists bug3583|
--enable_warnings
create procedure ifac(n int unsigned)
create procedure bug3583()
begin
declare i int unsigned default 1;
declare c int;
if n > 20 then
set n = 20; # bigint overflow otherwise
end if;
while i <= n do
begin
insert into test.fac values (i, fac(i));
set i = i + 1;
end;
end while;
select * from t1;
select count(*) into c from t1;
select c;
end|
call ifac(20)|
select * from fac|
drop table fac|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show function status like '%f%'|
drop procedure ifac|
drop function fac|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show function status like '%f%'|
insert into t1 values ("x", 3), ("y", 5)|
set @x = @@query_cache_size|
set global query_cache_size = 10*1024*1024|
flush status|
flush query cache|
show status like 'Qcache_hits'|
call bug3583()|
show status like 'Qcache_hits'|
call bug3583()|
call bug3583()|
show status like 'Qcache_hits'|
# primes
set global query_cache_size = @x|
flush status|
flush query cache|
delete from t1|
drop procedure bug3583|
#
# BUG#4905: Stored procedure doesn't clear for "Rows affected"
#
--disable_warnings
drop table if exists primes|
drop table if exists t3|
drop procedure if exists bug4905|
--enable_warnings
create table primes (
i int unsigned not null primary key,
p bigint unsigned not null
)|
insert into primes values
( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13),
( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31),
(10, 37), (11, 41), (12, 43), (13, 47), (14, 53),
(15, 59), (16, 61), (17, 67), (18, 71), (19, 73),
(20, 79), (21, 83), (22, 89), (23, 97), (24, 101),
(25, 103), (26, 107), (27, 109), (28, 113), (29, 127),
(30, 131), (31, 137), (32, 139), (33, 149), (34, 151),
(35, 157), (36, 163), (37, 167), (38, 173), (39, 179),
(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)|
create table t3 (s1 int,primary key (s1))|
--disable_warnings
drop procedure if exists opp|
drop procedure if exists bug4905|
--enable_warnings
create procedure opp(n bigint unsigned, out pp bool)
create procedure bug4905()
begin
declare r double;
declare b, s bigint unsigned default 0;
declare v int;
declare continue handler for sqlstate '23000' set v = 5;
set r = sqrt(n);
insert into t3 values (1);
end|
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
begin
declare p bigint unsigned;
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
select * from t3|
select t.p into p from test.primes t where t.i = s;
if b+p > r then
set pp = 1;
leave again;
end if;
if mod(n, b+p) = 0 then
set pp = 0;
leave again;
end if;
set s = s+1;
end;
end if;
end loop;
end|
drop procedure bug4905|
drop table t3|
#
# BUG#6022: Stored procedure shutdown problem with self-calling function.
#
--disable_warnings
drop procedure if exists ip|
drop function if exists bug6022|
--enable_warnings
create procedure ip(m int unsigned)
begin
declare p bigint unsigned;
declare i int unsigned;
set i=45, p=201;
while i < m do
begin
declare pp bool default 0;
call opp(p, pp);
if pp then
insert into test.primes values (i, p);
set i = i+1;
--disable_warnings
drop function if exists bug6022|
--enable_warnings
create function bug6022(x int) returns int
begin
if x < 0 then
return 0;
else
return bug6022(x-1);
end if;
set p = p+2;
end;
end while;
end|
show create procedure opp|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like '%p%'|
# This isn't the fastest way in the world to compute prime numbers, so
# don't be too ambitious. ;-)
call ip(200)|
# We don't want to select the entire table here, just pick a few
# examples.
# The expected result is:
# i p
# --- ----
# 45 211
# 100 557
# 199 1229
select * from primes where i=45 or i=100 or i=199|
drop table primes|
drop procedure opp|
drop procedure ip|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like '%p%'|
select bug6022(5)|
drop function bug6022|
# Fibonacci, for recursion test. (Yet Another Numerical series :)
#
# BUG#6029: Stored procedure specific handlers should have priority
#
--disable_warnings
drop procedure if exists bug6029|
--enable_warnings
--disable_warnings
drop table if exists fib|
drop procedure if exists bug6029|
--enable_warnings
create table fib ( f bigint unsigned not null )|
create procedure bug6029()
begin
declare exit handler for 1136 select '1136';
declare exit handler for sqlstate '23000' select 'sqlstate 23000';
declare continue handler for sqlexception select 'sqlexception';
insert into fib values (1), (1)|
insert into t3 values (1);
insert into t3 values (1,2);
end|
# We deliberately do it the awkward way, fetching the last two
# values from the table, in order to exercise various statements
# and table accesses at each turn.
create table t3 (s1 int, primary key (s1))|
insert into t3 values (1)|
call bug6029()|
delete from t3|
call bug6029()|
drop procedure bug6029|
drop table t3|
#
# BUG#8540: Local variable overrides an alias
#
--disable_warnings
drop procedure if exists fib|
drop procedure if exists bug8540|
--enable_warnings
create procedure fib(n int unsigned)
begin
if n > 0 then
begin
declare x, y bigint unsigned;
declare c cursor for select f from fib order by f desc limit 2;
open c;
fetch c into y;
fetch c into x;
close c;
insert into fib values (x+y);
call fib(n-1);
end;
end if;
create procedure bug8540()
begin
declare x int default 1;
select x as y, x+0 as z;
end|
call fib(20)|
call bug8540()|
drop procedure bug8540|
select * from fib order by f asc|
drop table fib|
drop procedure fib|
#
# BUG#6642: Stored procedure crash if expression with set function
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (s1 int)|
--disable_warnings
drop procedure if exists bug6642|
--enable_warnings
create procedure bug6642()
select abs(count(s1)) from t3|
call bug6642()|
call bug6642()|
drop procedure bug6642|
#
# Comment & suid
# BUG#7013: Stored procedure crash if group by ... with rollup
#
insert into t3 values (0),(1)|
--disable_warnings
drop procedure if exists bar|
drop procedure if exists bug7013|
--enable_warnings
create procedure bar(x char(16), y int)
comment "111111111111" sql security invoker
insert into test.t1 values (x, y)|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like 'bar'|
alter procedure bar comment "2222222222" sql security definer|
alter procedure bar comment "3333333333"|
alter procedure bar|
show create procedure bar|
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
show procedure status like 'bar'|
drop procedure bar|
create procedure bug7013()
select s1,count(s1) from t3 group by s1 with rollup|
call bug7013()|
call bug7013()|
drop procedure bug7013|
#
# rexecution
# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure
#
--disable_warnings
drop procedure if exists p1|
drop table if exists t4|
--enable_warnings
create procedure p1 ()
select (select s1 from t3) from t3|
create table t4 (
a mediumint(8) unsigned not null auto_increment,
b smallint(5) unsigned not null,
c char(32) not null,
primary key (a)
) engine=myisam default charset=latin1|
insert into t4 values (1, 2, 'oneword')|
insert into t4 values (2, 2, 'anotherword')|
create table t3 (s1 int)|
--disable_warnings
drop procedure if exists bug7743|
--enable_warnings
create procedure bug7743 ( searchstring char(28) )
begin
declare var mediumint(8) unsigned;
select a into var from t4 where b = 2 and c = binary searchstring limit 1;
select var;
end|
call p1()|
insert into t3 values (1)|
call p1()|
drop procedure p1|
call bug7743("oneword")|
call bug7743("OneWord")|
call bug7743("anotherword")|
call bug7743("AnotherWord")|
drop procedure bug7743|
drop table t4|
#
# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes
# the server
#
delete from t3|
insert into t3 values(1)|
drop procedure if exists bug7992_1|
drop procedure if exists bug7992_2|
create procedure bug7992_1()
begin
declare i int;
select max(s1)+1 into i from t3;
end|
create procedure bug7992_2()
insert into t3 (s1) select max(t4.s1)+1 from t3 as t4|
call bug7992_1()|
call bug7992_1()|
call bug7992_2()|
call bug7992_2()|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
#
# backticks
# BUG#8116: calling simple stored procedure twice in a row results
# in server crash
#
--disable_warnings
drop function if exists foo|
drop table if exists t3|
--enable_warnings
create function `foo` () returns int
return 5|
select `foo` ()|
drop function `foo`|
create table t3 ( userid bigint(20) not null default 0 )|
--disable_warnings
drop procedure if exists bug8116|
--enable_warnings
create procedure bug8116(in _userid int)
select * from t3 where userid = _userid|
call bug8116(42)|
call bug8116(42)|
drop procedure bug8116|
drop table t3|
#
# Implicit LOCK/UNLOCK TABLES for table access in functions
# BUG#6857: current_time() in STORED PROCEDURES
#
--disable_warning
drop function if exists t1max|
--disable_warnings
drop procedure if exists bug6857|
--enable_warnings
create function t1max() returns int
create procedure bug6857(counter int)
begin
declare x int;
select max(data) into x from t1;
return x;
declare t0, t1 int;
declare plus bool default 0;
set t0 = current_time();
while counter > 0 do
set counter = counter - 1;
end while;
set t1 = current_time();
if t1 > t0 then
set plus = 1;
end if;
select plus;
end|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
select t1max()|
drop function t1max|
# QQ: This is currently disabled. Not only does it slow down a normal test
# run, it makes running with valgrind (or similar tools) extremely
# painful.
# Make sure this takes at least one second on all machines in all builds.
# 30000 makes it about 3 seconds on an old 1.1GHz linux.
#call bug6857(300000)|
drop procedure bug6857|
#
# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not
# work properly.
--disable_warnings
drop table if exists t3|
drop procedure if exists bug8757|
--enable_warnings
create table t3 (
v char(16) not null primary key,
c int unsigned not null
)|
create function getcount(s char(16)) returns int
create procedure bug8757()
begin
declare x int;
declare c1 cursor for select data from t1 limit 1;
select count(*) into x from t3 where v = s;
if x = 0 then
insert into t3 values (s, 1);
else
update t3 set c = c+1 where v = s;
end if;
return x;
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|
select * from t1 where data = getcount("bar")|
select * from t3|
select getcount("zip")|
select getcount("zip")|
select * from t3|
select getcount(id) from t1 where data = 3|
select getcount(id) from t1 where data = 5|
select * from t3|
drop table t3|
drop function getcount|
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|
#
# BUG#8762: Stored Procedures: Inconsistent behavior
# of DROP PROCEDURE IF EXISTS statement.
--disable_warnings
drop procedure if exists bug8762|
--enable_warnings
# Doesn't exist
drop procedure if exists bug8762; create procedure bug8762() begin end|
# Does exist
drop procedure if exists bug8762; create procedure bug8762() begin end|
drop procedure bug8762|
#
# BUG#5240: Stored procedure crash if function has cursor declaration
......@@ -3275,56 +3277,85 @@ call bug7992()|
drop procedure bug7992|
drop table t3|
delimiter ;|
drop table t1;
drop table t2;
#
# Bug#8849: rolling back changes to AND/OR structure of ON and WHERE clauses
# in SP
# BUG#8849: problem with insert statement with table alias's
#
# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP
#
CREATE TABLE t1 (
lpitnumber int(11) default NULL,
lrecordtype int(11) default NULL
);
create table t3 (
lpitnumber int(11) default null,
lrecordtype int(11) default null
)|
CREATE TABLE t2 (
lbsiid int(11) NOT NULL default '0',
ltradingmodeid int(11) NOT NULL default '0',
ltradingareaid int(11) NOT NULL default '0',
csellingprice decimal(19,4) default NULL,
PRIMARY KEY (lbsiid,ltradingmodeid,ltradingareaid)
);
create table t4 (
lbsiid int(11) not null default '0',
ltradingmodeid int(11) not null default '0',
ltradingareaid int(11) not null default '0',
csellingprice decimal(19,4) default null,
primary key (lbsiid,ltradingmodeid,ltradingareaid)
)|
CREATE TABLE t3 (
lbsiid int(11) NOT NULL default '0',
ltradingareaid int(11) NOT NULL default '0',
PRIMARY KEY (lbsiid,ltradingareaid)
);
create table t5 (
lbsiid int(11) not null default '0',
ltradingareaid int(11) not null default '0',
primary key (lbsiid,ltradingareaid)
)|
delimiter |;
CREATE PROCEDURE bug8849()
--disable_warnings
drop procedure if exists bug8849|
--enable_warnings
create procedure bug8849()
begin
insert into t3
insert into t5
(
t3.lbsiid,
t3.ltradingareaid
t5.lbsiid,
t5.ltradingareaid
)
select distinct t1.lpitnumber, t2.ltradingareaid
select distinct t3.lpitnumber, t4.ltradingareaid
from
t2 join t1 on
t1.lpitnumber = t2.lbsiid
and t1.lrecordtype = 1
left join t2 as price01 on
price01.lbsiid = t2.lbsiid and
t4 join t3 on
t3.lpitnumber = t4.lbsiid
and t3.lrecordtype = 1
left join t4 as price01 on
price01.lbsiid = t4.lbsiid and
price01.ltradingmodeid = 1 and
t2.ltradingareaid = price01.ltradingareaid;
t4.ltradingareaid = price01.ltradingareaid;
end|
delimiter ;|
call bug8849();
call bug8849();
call bug8849();
drop procedure bug8849;
drop tables t1,t2,t3;
call bug8849()|
call bug8849()|
call bug8849()|
drop procedure bug8849|
drop tables t3,t4,t5|
#
# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement
#
--disable_warnings
drop procedure if exists bug8937|
--enable_warnings
create procedure bug8937()
begin
declare s,x,y,z int;
declare a float;
select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1;
select s,x,y,z;
select avg(data) into a from t1;
select a;
end|
delete from t1|
insert into t1 (data) values (1), (2), (3), (4), (6)|
call bug8937()|
drop procedure bug8937|
delete from t1|
# Add bugs above this line. Use existing tables t1 and t2 when
# practical, or create table t3, t3 etc temporarily (and drop them).
delimiter ;|
drop table t1,t2;
......@@ -356,6 +356,8 @@ class Item_sum_avg :public Item_sum_sum
void clear();
bool add();
double val_real();
// In SPs we might force the "wrong" type with select into a declare variable
longlong val_int() { return (longlong)val_real(); }
my_decimal *val_decimal(my_decimal *);
String *val_str(String *str);
void reset_field();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment