Commit 804a2a8c authored by unknown's avatar unknown

Reorganized sp.test (all bugs at the end now).


mysql-test/r/sp.result:
  Reorganized tests (all bugs at the end now) and made some tests adopt to the file's style.
mysql-test/t/sp.test:
  Reorganized tests (all bugs at the end now) and made some tests adopt to the file's style.
parent 5835809a
......@@ -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),
......@@ -2231,432 +2525,139 @@ abs(count(s1))
call bug6642()|
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 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 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,43 @@ 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;
end|
call bug8849();
call bug8849();
call bug8849();
drop procedure bug8849;
drop tables t1,t2,t3;
t4.ltradingareaid = price01.ltradingareaid;
end|
call bug8849()|
call bug8849()|
call bug8849()|
drop procedure bug8849|
drop tables t3,t4,t5|
drop table t1,t2;
......@@ -1473,6 +1473,285 @@ delete from t2 |
# End of non-bug tests
#
# Some "real" examples
#
# fac
--disable_warnings
drop table if exists fac|
--enable_warnings
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 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|
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
--disable_warnings
drop table if exists primes|
--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)|
--disable_warnings
drop procedure if exists opp|
--enable_warnings
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|
--disable_warnings
drop procedure if exists ip|
--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;
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%'|
# Fibonacci, for recursion test. (Yet Another Numerical series :)
--disable_warnings
drop table if exists fib|
--enable_warnings
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 fib|
--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;
end|
call fib(20)|
select * from fib order by f asc|
drop table fib|
drop procedure fib|
#
# Comment & suid
#
--disable_warnings
drop procedure if exists bar|
--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|
#
# rexecution
#
--disable_warnings
drop procedure if exists p1|
--enable_warnings
create procedure p1 ()
select (select s1 from t3) from t3|
create table t3 (s1 int)|
call p1()|
insert into t3 values (1)|
call p1()|
drop procedure p1|
drop table t3|
#
# 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
#
......@@ -1492,6 +1771,7 @@ begin
end if;
end|
delete from t1|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
......@@ -2413,800 +2693,522 @@ drop procedure if exists bug4904|
--enable_warnings
create procedure bug4904 ()
begin
declare continue handler for sqlstate 'HY000' begin end;
select s1 from t3 union select s2 from t3;
end|
call bug4904()|
drop procedure bug4904|
drop table t3|
#
# BUG#336
#
--disable_warnings
drop procedure if exists bug336|
--enable_warnings
create procedure bug336(out y int)
begin
declare x int;
set x = (select sum(t.data) from test.t1 t);
set y = x;
end|
insert into t1 values ("a", 2), ("b", 3)|
call bug336(@y)|
select @y|
delete from t1|
drop procedure bug336|
#
# BUG#3157
#
--disable_warnings
drop procedure if exists bug3157|
--enable_warnings
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 bug5251|
--enable_warnings
create procedure bug5251()
begin
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|
drop procedure bug5251|
#
# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE
#
--disable_warnings
drop procedure if exists bug5251|
--enable_warnings
create procedure bug5251()
checksum table t1|
call bug5251()|
call bug5251()|
drop procedure bug5251|
#
# BUG#5287: Stored procedure crash if leave outside loop
#
--disable_warnings
drop procedure if exists bug5287|
--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|
#
# BUG#5307: Stored procedure allows statement after BEGIN ... END
#
--disable_warnings
drop procedure if exists bug5307|
--enable_warnings
create procedure bug5307()
begin
end; set @x = 3|
call bug5307()|
select @x|
drop procedure bug5307|
#
# BUG#5258: Stored procedure modified date is 0000-00-00
# (This was a design flaw)
--disable_warnings
drop procedure if exists bug5258|
--enable_warnings
create procedure bug5258()
begin
end|
--disable_warnings
drop procedure if exists bug5258_aux|
--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()|
drop procedure bug5258|
drop procedure bug5258_aux|
#
# BUG#4487: Stored procedure connection aborted if uninitialized char
#
--disable_warnings
drop function if exists bug4487|
--enable_warnings
create function bug4487() returns char
begin
declare v char;
return v;
end|
select bug4487()|
drop function bug4487|
#
# BUG#4941: Stored procedure crash fetching null value into variable.
#
--disable_warnings
drop procedure if exists bug4941|
--enable_warnings
--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|
#
# BUG#3583: query cache doesn't work for stored procedures
#
--disable_warnings
drop procedure if exists bug3583|
--enable_warnings
--disable_warnings
drop procedure if exists bug3583|
--enable_warnings
create procedure bug3583()
begin
declare c int;
select * from t1;
select count(*) into c from t1;
select c;
end|
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'|
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 t3|
drop procedure if exists bug4905|
--enable_warnings
create table t3 (s1 int,primary key (s1))|
--disable_warnings
drop procedure if exists bug4905|
--enable_warnings
create procedure bug4905()
begin
declare v int;
declare continue handler for sqlstate '23000' set v = 5;
insert into t3 values (1);
end|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
select * from t3|
declare continue handler for sqlstate 'HY000' begin end;
drop procedure bug4905|
select s1 from t3 union select s2 from t3;
end|
call bug4904()|
drop procedure bug4904|
drop table t3|
#
# BUG#6022: Stored procedure shutdown problem with self-calling function.
# BUG#336
#
--disable_warnings
drop function if exists bug6022|
--enable_warnings
--disable_warnings
drop function if exists bug6022|
drop procedure if exists bug336|
--enable_warnings
create function bug6022(x int) returns int
create procedure bug336(out y int)
begin
if x < 0 then
return 0;
else
return bug6022(x-1);
end if;
declare x int;
set x = (select sum(t.data) from test.t1 t);
set y = x;
end|
select bug6022(5)|
drop function bug6022|
insert into t1 values ("a", 2), ("b", 3)|
call bug336(@y)|
select @y|
delete from t1|
drop procedure bug336|
#
# BUG#6029: Stored procedure specific handlers should have priority
# BUG#3157
#
--disable_warnings
drop procedure if exists bug6029|
--enable_warnings
--disable_warnings
drop procedure if exists bug6029|
drop procedure if exists bug3157|
--enable_warnings
create procedure bug6029()
create procedure bug3157()
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 t3 values (1);
insert into t3 values (1,2);
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|
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|
set @n = 0|
insert into t1 values ("a", 1)|
call bug3157()|
select @n|
delete from t1|
drop procedure bug3157|
#
# BUG#8540: Local variable overrides an alias
# BUG#5251: mysql changes creation time of a procedure/function when altering
#
--disable_warnings
drop procedure if exists bug8540|
drop procedure if exists bug5251|
--enable_warnings
create procedure bug8540()
create procedure bug5251()
begin
declare x int default 1;
select x as y, x+0 as z;
end|
call bug8540()|
drop procedure bug8540|
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|
drop procedure bug5251|
#
# BUG#6642: Stored procedure crash if expression with set function
# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE
#
--disable_warnings
drop table if exists t3|
drop procedure if exists bug5251|
--enable_warnings
create table t3 (s1 int)|
create procedure bug5251()
checksum table t1|
call bug5251()|
call bug5251()|
drop procedure bug5251|
#
# BUG#5287: Stored procedure crash if leave outside loop
#
--disable_warnings
drop procedure if exists bug6642|
drop procedure if exists bug5287|
--enable_warnings
create procedure bug5287(param1 int)
label1:
begin
declare c cursor for select 5;
create procedure bug6642()
select abs(count(s1)) from t3|
loop
if param1 >= 0 then
leave label1;
end if;
end loop;
end|
call bug5287(1)|
drop procedure bug5287|
call bug6642()|
call bug6642()|
drop procedure bug6642|
#
# BUG#7013: Stored procedure crash if group by ... with rollup
# BUG#5307: Stored procedure allows statement after BEGIN ... END
#
insert into t3 values (0),(1)|
--disable_warnings
drop procedure if exists bug7013|
drop procedure if exists bug5307|
--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 bug5307()
begin
end; set @x = 3|
call bug5307()|
select @x|
drop procedure bug5307|
#
# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure
#
# BUG#5258: Stored procedure modified date is 0000-00-00
# (This was a design flaw)
--disable_warnings
drop table if exists t4|
drop procedure if exists bug5258|
--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 bug5258()
begin
end|
--disable_warnings
drop procedure if exists bug7743|
drop procedure if exists bug5258_aux|
--enable_warnings
create procedure bug7743 ( searchstring char(28) )
create procedure bug5258_aux()
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")|
call bug7743("OneWord")|
call bug7743("anotherword")|
call bug7743("AnotherWord")|
drop procedure bug7743|
drop table t4|
declare c, m char(19);
#
# 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;
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|
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()|
call bug5258_aux()|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
drop procedure bug5258|
drop procedure bug5258_aux|
#
# BUG#8116: calling simple stored procedure twice in a row results
# in server crash
# BUG#4487: Stored procedure connection aborted if uninitialized char
#
--disable_warnings
drop table if exists t3|
drop function if exists bug4487|
--enable_warnings
create table t3 ( userid bigint(20) not null default 0 )|
create function bug4487() returns char
begin
declare v char;
return v;
end|
--disable_warnings
drop procedure if exists bug8116|
--enable_warnings
create procedure bug8116(in _userid int)
select * from t3 where userid = _userid|
select bug4487()|
drop function bug4487|
call bug8116(42)|
call bug8116(42)|
drop procedure bug8116|
drop table t3|
#
# BUG#6857: current_time() in STORED PROCEDURES
# BUG#4941: Stored procedure crash fetching null value into variable.
#
--disable_warnings
drop procedure if exists bug6857|
drop procedure if exists bug4941|
--enable_warnings
create procedure bug6857(counter int)
--disable_warnings
drop procedure if exists bug4941|
--enable_warnings
create procedure bug4941(out x 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|
# 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)|
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|
drop procedure bug6857|
#
# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not
# work properly.
# BUG#3583: query cache doesn't work for stored procedures
#
--disable_warnings
drop procedure if exists bug8757|
drop procedure if exists bug3583|
--enable_warnings
create procedure bug8757()
--disable_warnings
drop procedure if exists bug3583|
--enable_warnings
create procedure bug3583()
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;
declare c int;
open c2;
fetch c2 into y;
close c2;
select 2,y;
end;
open c1;
fetch c1 into x;
close c1;
select 1,x;
select * from t1;
select count(*) into c from t1;
select c;
end|
delete from t1|
delete from t2|
insert into t1 values ("x", 1)|
insert into t2 values ("y", 2, 0.0)|
insert into t1 values ("x", 3), ("y", 5)|
set @x = @@query_cache_size|
set global query_cache_size = 10*1024*1024|
call bug8757()|
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'|
set global query_cache_size = @x|
flush status|
flush query cache|
delete from t1|
delete from t2|
drop procedure bug8757|
drop procedure bug3583|
#
# BUG#8762: Stored Procedures: Inconsistent behavior
# of DROP PROCEDURE IF EXISTS statement.
# BUG#4905: Stored procedure doesn't clear for "Rows affected"
#
--disable_warnings
drop procedure if exists bug8762|
drop table if exists t3|
drop procedure if exists bug4905|
--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|
create table t3 (s1 int,primary key (s1))|
#
# Some "real" examples
#
--disable_warnings
drop procedure if exists bug4905|
--enable_warnings
create procedure bug4905()
begin
declare v int;
declare continue handler for sqlstate '23000' set v = 5;
# fac
insert into t3 values (1);
end|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
call bug4905()|
select row_count()|
select * from t3|
drop procedure bug4905|
drop table t3|
#
# BUG#6022: Stored procedure shutdown problem with self-calling function.
#
--disable_warnings
drop table if exists fac|
drop function if exists bug6022|
--enable_warnings
create table fac (n int unsigned not null primary key, f bigint unsigned)|
--disable_warnings
drop procedure if exists ifac|
drop function if exists bug6022|
--enable_warnings
create procedure ifac(n int unsigned)
create function bug6022(x int) returns int
begin
declare i int unsigned default 1;
if n > 20 then
set n = 20; # bigint overflow otherwise
if x < 0 then
return 0;
else
return bug6022(x-1);
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|
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
select bug6022(5)|
drop function bug6022|
#
# BUG#6029: Stored procedure specific handlers should have priority
#
--disable_warnings
drop table if exists primes|
drop procedure if exists bug6029|
--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)|
--disable_warnings
drop procedure if exists opp|
drop procedure if exists bug6029|
--enable_warnings
create procedure opp(n bigint unsigned, out pp bool)
create procedure bug6029()
begin
declare r double;
declare b, s bigint unsigned default 0;
declare exit handler for 1136 select '1136';
declare exit handler for sqlstate '23000' select 'sqlstate 23000';
declare continue handler for sqlexception select 'sqlexception';
set r = sqrt(n);
insert into t3 values (1);
insert into t3 values (1,2);
end|
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
begin
declare p bigint unsigned;
create table t3 (s1 int, primary key (s1))|
insert into t3 values (1)|
call bug6029()|
delete from t3|
call bug6029()|
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 bug6029|
drop table t3|
#
# BUG#8540: Local variable overrides an alias
#
--disable_warnings
drop procedure if exists ip|
drop procedure if exists bug8540|
--enable_warnings
create procedure ip(m int unsigned)
begin
declare p bigint unsigned;
declare i int unsigned;
set i=45, p=201;
create procedure bug8540()
begin
declare x int default 1;
select x as y, x+0 as z;
end|
while i < m do
begin
declare pp bool default 0;
call bug8540()|
drop procedure bug8540|
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%'|
#
# BUG#6642: Stored procedure crash if expression with set function
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (s1 int)|
# 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%'|
--disable_warnings
drop procedure if exists bug6642|
--enable_warnings
create procedure bug6642()
select abs(count(s1)) from t3|
# Fibonacci, for recursion test. (Yet Another Numerical series :)
call bug6642()|
call bug6642()|
drop procedure bug6642|
#
# BUG#7013: Stored procedure crash if group by ... with rollup
#
insert into t3 values (0),(1)|
--disable_warnings
drop table if exists fib|
drop procedure if exists bug7013|
--enable_warnings
create table fib ( f bigint unsigned not null )|
create procedure bug7013()
select s1,count(s1) from t3 group by s1 with rollup|
call bug7013()|
call bug7013()|
drop procedure bug7013|
insert into fib values (1), (1)|
#
# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure
#
--disable_warnings
drop table if exists t4|
--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')|
# 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 fib|
drop procedure if exists bug7743|
--enable_warnings
create procedure fib(n int unsigned)
create procedure bug7743 ( searchstring char(28) )
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;
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|
drop table fib|
drop procedure fib|
call bug7743("oneword")|
call bug7743("OneWord")|
call bug7743("anotherword")|
call bug7743("AnotherWord")|
drop procedure bug7743|
drop table t4|
#
# Comment & suid
# 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|
--disable_warnings
drop procedure if exists bar|
--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|
call bug7992_1()|
call bug7992_1()|
call bug7992_2()|
call bug7992_2()|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
#
# rexecution
# BUG#8116: calling simple stored procedure twice in a row results
# in server crash
#
--disable_warnings
drop procedure if exists p1|
drop table if exists t3|
--enable_warnings
create procedure p1 ()
select (select s1 from t3) from t3|
create table t3 ( userid bigint(20) not null default 0 )|
create table t3 (s1 int)|
--disable_warnings
drop procedure if exists bug8116|
--enable_warnings
create procedure bug8116(in _userid int)
select * from t3 where userid = _userid|
call p1()|
insert into t3 values (1)|
call p1()|
drop procedure p1|
call bug8116(42)|
call bug8116(42)|
drop procedure bug8116|
drop table t3|
#
# backticks
# BUG#6857: current_time() in STORED PROCEDURES
#
--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|
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,61 @@ 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|
# Add bug 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;
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