Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
9c2fe003
Commit
9c2fe003
authored
Mar 07, 2005
by
pem@mysql.comhem.se
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganized sp.test (all bugs at the end now).
parent
4bfa6539
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1643 additions
and
1635 deletions
+1643
-1635
mysql-test/r/sp.result
mysql-test/r/sp.result
+961
-960
mysql-test/t/sp.test
mysql-test/t/sp.test
+682
-675
No files found.
mysql-test/r/sp.result
View file @
9c2fe003
...
@@ -1250,268 +1250,562 @@ drop view v1|
...
@@ -1250,268 +1250,562 @@ drop view v1|
drop view v2|
drop view v2|
delete from t1 |
delete from t1 |
delete from t2 |
delete from t2 |
drop procedure if exists bug822|
drop table if exists fac|
create procedure bug822(a_id char(16), a_data int)
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
begin
declare n int;
declare i int unsigned default 1;
select count(*) into n from t1 where id = a_id and data = a_data;
if n > 20 then
if n = 0 then
set n = 20; # bigint overflow otherwise
insert into t1 (id, data) values (a_id, a_data);
end if;
end if;
end|
while i <= n do
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
begin
declare x int;
insert into test.fac values (i, fac(i));
select data into x from t1 order by id limit 1;
set i = i + 1;
if x > 10 then
end;
insert into t1 values ("less", x-10);
end while;
else
insert into t1 values ("more", x+10);
end if;
end|
end|
insert into t1 values ('foo', 12)|
call ifac(20)|
call bug1495()|
select * from fac|
delete from t1 where id='foo'|
n f
insert into t1 values ('bar', 7)|
1 1
call bug1495()|
2 2
delete from t1 where id='bar'|
3 6
select * from t1|
4 24
id data
5 120
less 2
6 720
more 17
7 5040
delete from t1|
8 40320
drop procedure bug1495|
9 362880
drop procedure if exists bug1547|
10 3628800
create procedure bug1547(s char(16))
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
begin
declare x int;
declare r double;
select data into x from t1 where s = id limit 1;
declare b, s bigint unsigned default 0;
if x > 10 then
set r = sqrt(n);
insert into t1 values ("less", x-10);
again:
loop
if s = 45 then
set b = b+200, s = 0;
else
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 if;
end loop;
end|
end|
insert into t1 values ("foo", 12), ("bar", 7)|
drop procedure if exists ip|
call bug1547("foo")|
create procedure ip(m int unsigned)
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
begin
insert into t3 values(2);
declare p bigint unsigned;
flush tables;
declare i int unsigned;
end|
set i=45, p=201;
call bug1862()|
while i < m do
call bug1862()|
select * from t3|
a
2
2
drop table t3|
drop procedure bug1862|
drop procedure if exists bug1874|
create procedure bug1874()
begin
begin
declare x int;
declare pp bool default 0;
declare y double;
call opp(p, pp);
select max(data) into x from t1;
if pp then
insert into t2 values ("max", x, 0);
insert into test.primes values (i, p);
select min(data) into x from t1;
set i = i+1;
insert into t2 values ("min", x, 0);
end if;
select sum(data) into x from t1;
set p = p+2;
insert into t2 values ("sum", x, 0);
end;
select avg(data) into y from t1;
end while;
insert into t2 values ("avg", 0, y);
end|
end|
insert into t1 (data) values (3), (1), (5), (9), (4)|
show create procedure opp|
call bug1874()|
Procedure sql_mode Create Procedure
select * from t2|
opp CREATE PROCEDURE `test`.`opp`(n bigint unsigned, out pp bool)
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
begin
declare v1 int;
declare r double;
declare c1 cursor for select data from t1;
declare b, s bigint unsigned default 0;
declare continue handler for not found set @x2 = 1;
set r = sqrt(n);
open c1;
again:
fetch c1 into v1;
loop
set @x2 = 2;
if s = 45 then
close c1;
set b = b+200, s = 0;
end|
else
call bug2260()|
select @x2|
@x2
2
drop procedure bug2260|
drop procedure if exists bug2227|
create procedure bug2227(x int)
begin
begin
declare y float default 2.6;
declare p bigint unsigned;
declare z char(16) default "zzz";
select t.p into p from test.primes t where t.i = s;
select 1.3, x, y, 42, z;
if b+p > r then
end|
set pp = 1;
call bug2227(9)|
leave again;
1.3 x y 42 z
end if;
1.3 9 2.6 42 zzz
if mod(n, b+p) = 0 then
drop procedure bug2227|
set pp = 0;
drop function if exists bug2674|
leave again;
create function bug2674() returns int
end if;
return @@sort_buffer_size|
set s = s+1;
set @osbs = @@sort_buffer_size|
end;
set @@sort_buffer_size = 262000|
end if;
select bug2674()|
end loop;
bug2674()
end
262000
show procedure status like '%p%'|
drop function bug2674|
Db Name Type Definer Modified Created Security_type Comment
set @@sort_buffer_size = @osbs|
test ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
drop procedure if exists bug3259_1 |
test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
create procedure bug3259_1 () begin end|
call ip(200)|
drop procedure if exists BUG3259_2 |
select * from primes where i=45 or i=100 or i=199|
create procedure BUG3259_2 () begin end|
i p
drop procedure if exists Bug3259_3 |
45 211
create procedure Bug3259_3 () begin end|
100 557
call BUG3259_1()|
199 1229
call BUG3259_1()|
drop table primes|
call bug3259_2()|
drop procedure opp|
call Bug3259_2()|
drop procedure ip|
call bug3259_3()|
show procedure status like '%p%'|
call bUG3259_3()|
Db Name Type Definer Modified Created Security_type Comment
drop procedure bUg3259_1|
drop table if exists fib|
drop procedure BuG3259_2|
create table fib ( f bigint unsigned not null )|
drop procedure BUG3259_3|
insert into fib values (1), (1)|
drop function if exists bug2772|
drop procedure if exists fib|
create function bug2772() returns char(10) character set latin2
create procedure fib(n int unsigned)
return 'a'|
select bug2772()|
bug2772()
a
drop function bug2772|
drop procedure if exists bug2776_1|
create procedure bug2776_1(out x int)
begin
begin
declare v int;
if n > 0 then
set v = default;
begin
set x = v;
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|
end|
drop procedure if exists bug2776_2|
call fib(20)|
create procedure bug2776_2(out x int)
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
begin
declare
v int default 42
;
declare
x int
;
se
t v = default
;
se
lect max(data) into x from t1
;
set x = v
;
return x
;
end|
end|
set @x = 1|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
call bug2776_1(@x)|
select t1max()|
select @x|
t1max()
@x
5
NULL
drop function t1max|
call bug2776_2(@x)|
select @x|
@x
42
drop procedure bug2776_1|
drop procedure bug2776_2|
drop table if exists t3|
drop table if exists t3|
create table t3 (s1 smallint)|
create table t3 (
insert into t3 values (123456789012)|
v char(16) not null primary key,
Warnings:
c int unsigned not null
Warning 1264 Out of range value adjusted for column 's1' at row 1
)|
drop procedure if exists bug2780|
create function getcount(s char(16)) returns int
create procedure bug2780()
begin
begin
declare exit handler for sqlwarning set @x = 1;
declare x int;
set @x = 0;
select count(*) into x from t3 where v = s;
insert into t3 values (123456789012);
if x = 0 then
insert into t3 values (0);
insert into t3 values (s, 1);
else
update t3 set c = c+1 where v = s;
end if;
return x;
end|
end|
call bug2780()|
select * from t1 where data = getcount("bar")|
select @x|
id data
@x
zap 1
select * from t3|
v c
bar 4
select getcount("zip")|
getcount("zip")
0
select getcount("zip")|
getcount("zip")
1
1
select * from t3|
select * from t3|
s1
v c
32767
bar 4
32767
zip 2
drop procedure bug2780|
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 table t3|
create table t3 (content varchar(10) )|
drop function getcount|
insert into t3 values ("test1")|
drop procedure if exists bug822|
insert into t3 values ("test2")|
create procedure bug822(a_id char(16), a_data int)
create table t4 (f1 int, rc int, t3 int)|
drop procedure if exists bug1863|
create procedure bug1863(in1 int)
begin
begin
declare ind int default 0;
declare n int;
declare t1 int;
select count(*) into n from t1 where id = a_id and data = a_data;
declare t2 int;
if n = 0 then
declare t3 int;
insert into t1 (id, data) values (a_id, a_data);
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;
end if;
insert into t4 values (2, rc, t3);
end|
end|
call bug1863(10)|
delete from t1|
call bug1863(10)|
call bug822('foo', 42)|
select * from t4|
call bug822('foo', 42)|
f1 rc t3
call bug822('bar', 666)|
2 0 NULL
select * from t1|
2 0 NULL
id data
drop procedure bug1863|
foo 42
drop temporary table temp_t1;
bar 666
drop table t3, t4|
delete from t1|
drop table if exists t3, t4|
drop procedure bug822|
create table t3 (
drop procedure if exists bug1495|
OrderID int not null,
create procedure bug1495()
MarketID int,
begin
primary key (OrderID)
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 (
create table t4 (
MarketID int not null,
MarketID int not null,
Market varchar(60),
Market varchar(60),
...
@@ -2231,432 +2525,139 @@ abs(count(s1))
...
@@ -2231,432 +2525,139 @@ abs(count(s1))
call bug6642()|
call bug6642()|
abs(count(s1))
abs(count(s1))
0
0
drop procedure bug6642|
drop procedure bug6642|
insert into t3 values (0),(1)|
insert into t3 values (0),(1)|
drop procedure if exists bug7013|
drop procedure if exists bug7013|
create procedure bug7013()
create procedure bug7013()
select s1,count(s1) from t3 group by s1 with rollup|
select s1,count(s1) from t3 group by s1 with rollup|
call bug7013()|
call bug7013()|
s1 count(s1)
s1 count(s1)
0 1
0 1
1 1
1 1
NULL 2
NULL 2
call bug7013()|
call bug7013()|
s1 count(s1)
s1 count(s1)
0 1
0 1
1 1
1 1
NULL 2
NULL 2
drop procedure bug7013|
drop procedure bug7013|
drop table if exists t4|
drop table if exists t4|
create table t4 (
create table t4 (
a mediumint(8) unsigned not null auto_increment,
a mediumint(8) unsigned not null auto_increment,
b smallint(5) unsigned not null,
b smallint(5) unsigned not null,
c char(32) not null,
c char(32) not null,
primary key (a)
primary key (a)
) engine=myisam default charset=latin1|
) engine=myisam default charset=latin1|
insert into t4 values (1, 2, 'oneword')|
insert into t4 values (1, 2, 'oneword')|
insert into t4 values (2, 2, 'anotherword')|
insert into t4 values (2, 2, 'anotherword')|
drop procedure if exists bug7743|
drop procedure if exists bug7743|
create procedure bug7743 ( searchstring char(28) )
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
begin
begin
declare x, y bigint unsigned;
declare var mediumint(8) unsigned;
declare c cursor for select f from fib order by f desc limit 2;
select a into var from t4 where b = 2 and c = binary searchstring limit 1;
open c;
select var;
fetch c into y;
fetch c into x;
close c;
insert into fib values (x+y);
call fib(n-1);
end;
end if;
end|
end|
call fib(20)|
call bug7743("oneword")|
select * from fib order by f asc|
var
f
1
1
1
call bug7743("OneWord")|
var
NULL
Warnings:
Warning 1329 No data to FETCH
call bug7743("anotherword")|
var
2
2
3
call bug7743("AnotherWord")|
5
var
8
NULL
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:
Warnings:
Note 1305 FUNCTION t1max does not exist
Warning 1329 No data to FETCH
create function t1max() returns int
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
begin
declare x int;
declare i int;
select max(data) into x from t1;
select max(s1)+1 into i from t3;
return x;
end|
end|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
create procedure bug7992_2()
select t1max()|
insert into t3 (s1) select max(t4.s1)+1 from t3 as t4|
t1max()
call bug7992_1()|
5
call bug7992_1()|
drop function t1max|
call bug7992_2()|
call bug7992_2()|
drop procedure bug7992_1|
drop procedure bug7992_2|
drop table t3|
drop table if exists t3|
drop table if exists t3|
create table t3 (
create table t3 ( userid bigint(20) not null default 0 )|
v char(16) not null primary key,
drop procedure if exists bug8116|
c int unsigned not null
create procedure bug8116(in _userid int)
)|
select * from t3 where userid = _userid|
create function getcount(s char(16)) returns int
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
begin
declare x int;
declare t0, t1 int;
select count(*) into x from t3 where v = s;
declare plus bool default 0;
if x = 0 then
set t0 = current_time();
insert into t3 values (s, 1);
while counter > 0 do
else
set counter = counter - 1;
update t3 set c = c+1 where v = s;
end while;
set t1 = current_time();
if t1 > t0 then
set plus = 1;
end if;
end if;
return x
;
select plus
;
end|
end|
select * from t1 where data = getcount("bar")|
drop procedure bug6857|
id data
drop procedure if exists bug8757|
zap 1
create procedure bug8757()
select * from t3|
begin
v c
declare x int;
bar 4
declare c1 cursor for select data from t1 limit 1;
select getcount("zip")|
begin
getcount("zip")
declare y int;
0
declare c2 cursor for select i from t2 limit 1;
select getcount("zip")|
open c2;
getcount("zip")
fetch c2 into y;
1
close c2;
select * from t3|
select 2,y;
v c
end;
bar 4
open c1;
zip 2
fetch c1 into x;
select getcount(id) from t1 where data = 3|
close c1;
getcount(id)
select 1,x;
0
end|
select getcount(id) from t1 where data = 5|
delete from t1|
getcount(id)
delete from t2|
1
insert into t1 values ("x", 1)|
select * from t3|
insert into t2 values ("y", 2, 0.0)|
v c
call bug8757()|
bar 4
2 y
zip 3
2 2
foo 1
1 x
drop table t3|
1 1
drop function getcount|
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|
drop function if exists bug5240|
create function bug5240 () returns int
create function bug5240 () returns int
begin
begin
...
@@ -2696,43 +2697,43 @@ call bug7992()|
...
@@ -2696,43 +2697,43 @@ call bug7992()|
call bug7992()|
call bug7992()|
drop procedure bug7992|
drop procedure bug7992|
drop table t3|
drop table t3|
drop table t1;
create table t3 (
drop table t2;
lpitnumber int(11) default null,
CREATE TABLE t1 (
lrecordtype int(11) default null
lpitnumber int(11) default NULL,
)|
lrecordtype int(11) default NULL
create table t4 (
);
lbsiid int(11) not null default '0',
CREATE TABLE t2 (
ltradingmodeid int(11) not null default '0',
lbsiid int(11) NOT NULL default '0',
ltradingareaid int(11) not null default '0',
ltradingmodeid int(11) NOT NULL default '0',
csellingprice decimal(19,4) default null,
ltradingareaid int(11) NOT NULL default '0',
primary key (lbsiid,ltradingmodeid,ltradingareaid)
csellingprice decimal(19,4) default NULL,
)|
PRIMARY KEY (lbsiid,ltradingmodeid,ltradingareaid)
create table t5 (
);
lbsiid int(11) not null default '0',
CREATE TABLE t3 (
ltradingareaid int(11) not null default '0',
lbsiid int(11) NOT NULL default '0',
primary key (lbsiid,ltradingareaid)
ltradingareaid int(11) NOT NULL default '0',
)|
PRIMARY KEY (lbsiid,ltradingareaid)
drop procedure if exists bug8849|
);
create procedure bug8849()
CREATE PROCEDURE bug8849()
begin
begin
insert into t
3
insert into t
5
(
(
t
3
.lbsiid,
t
5
.lbsiid,
t
3
.ltradingareaid
t
5
.ltradingareaid
)
)
select distinct t
1.lpitnumber, t2
.ltradingareaid
select distinct t
3.lpitnumber, t4
.ltradingareaid
from
from
t
2 join t1
on
t
4 join t3
on
t
1.lpitnumber = t2
.lbsiid
t
3.lpitnumber = t4
.lbsiid
and t
1
.lrecordtype = 1
and t
3
.lrecordtype = 1
left join t
2
as price01 on
left join t
4
as price01 on
price01.lbsiid = t
2
.lbsiid and
price01.lbsiid = t
4
.lbsiid and
price01.ltradingmodeid = 1 and
price01.ltradingmodeid = 1 and
t2.ltradingareaid = price01.ltradingareaid;
t4.ltradingareaid = price01.ltradingareaid;
end|
end|
call bug8849();
call bug8849()|
call bug8849();
call bug8849()|
call bug8849();
call bug8849()|
drop procedure bug8849;
drop procedure bug8849|
drop tables t1,t2,t3;
drop tables t3,t4,t5|
drop table t1,t2;
mysql-test/t/sp.test
View file @
9c2fe003
...
@@ -1473,6 +1473,285 @@ delete from t2 |
...
@@ -1473,6 +1473,285 @@ delete from t2 |
# End of non-bug tests
# 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
# Test cases for old bugs
#
#
...
@@ -1492,6 +1771,7 @@ begin
...
@@ -1492,6 +1771,7 @@ begin
end if;
end if;
end|
end|
delete from t1|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
call bug822('bar', 666)|
...
@@ -2413,800 +2693,522 @@ drop procedure if exists bug4904|
...
@@ -2413,800 +2693,522 @@ drop procedure if exists bug4904|
--
enable_warnings
--
enable_warnings
create
procedure
bug4904
()
create
procedure
bug4904
()
begin
begin
declare
continue
handler
for
sqlstate
'HY000'
begin
end
;
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
|
drop
procedure
bug4905
|
select
s1
from
t3
union
select
s2
from
t3
;
end
|
call
bug4904
()
|
drop
procedure
bug4904
|
drop
table
t3
|
drop
table
t3
|
#
#
# BUG#
6022: Stored procedure shutdown problem with self-calling function.
# BUG#
336
#
#
--
disable_warnings
--
disable_warnings
drop
function
if
exists
bug6022
|
drop
procedure
if
exists
bug336
|
--
enable_warnings
--
disable_warnings
drop
function
if
exists
bug6022
|
--
enable_warnings
--
enable_warnings
create
function
bug6022
(
x
int
)
returns
int
create
procedure
bug336
(
out
y
int
)
begin
begin
if
x
<
0
then
declare
x
int
;
return
0
;
set
x
=
(
select
sum
(
t
.
data
)
from
test
.
t1
t
);
else
set
y
=
x
;
return
bug6022
(
x
-
1
);
end
if
;
end
|
end
|
select
bug6022
(
5
)
|
insert
into
t1
values
(
"a"
,
2
),
(
"b"
,
3
)
|
drop
function
bug6022
|
call
bug336
(
@
y
)
|
select
@
y
|
delete
from
t1
|
drop
procedure
bug336
|
#
#
# BUG#
6029: Stored procedure specific handlers should have priority
# BUG#
3157
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug6029
|
drop
procedure
if
exists
bug3157
|
--
enable_warnings
--
disable_warnings
drop
procedure
if
exists
bug6029
|
--
enable_warnings
--
enable_warnings
create
procedure
bug
6029
()
create
procedure
bug
3157
()
begin
begin
declare
exit
handler
for
1136
select
'1136'
;
if
exists
(
select
*
from
t1
)
then
declare
exit
handler
for
sqlstate
'23000'
select
'sqlstate 23000'
;
set
@
n
=
@
n
+
1
;
declare
continue
handler
for
sqlexception
select
'sqlexception'
;
end
if
;
if
(
select
count
(
*
)
from
t1
)
then
insert
into
t3
values
(
1
)
;
set
@
n
=
@
n
+
1
;
insert
into
t3
values
(
1
,
2
)
;
end
if
;
end
|
end
|
create
table
t3
(
s1
int
,
primary
key
(
s1
))
|
set
@
n
=
0
|
insert
into
t3
values
(
1
)
|
insert
into
t1
values
(
"a"
,
1
)
|
call
bug6029
()
|
call
bug3157
()
|
delete
from
t3
|
select
@
n
|
call
bug6029
()
|
delete
from
t1
|
drop
procedure
bug3157
|
drop
procedure
bug6029
|
drop
table
t3
|
#
#
# BUG#
8540: Local variable overrides an alias
# BUG#
5251: mysql changes creation time of a procedure/function when altering
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
8540
|
drop
procedure
if
exists
bug
5251
|
--
enable_warnings
--
enable_warnings
create
procedure
bug5251
()
create
procedure
bug8540
()
begin
begin
declare
x
int
default
1
;
select
x
as
y
,
x
+
0
as
z
;
end
|
end
|
call
bug8540
()
|
select
created
into
@
c1
from
mysql
.
proc
drop
procedure
bug8540
|
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
--
disable_warnings
drop
table
if
exists
t3
|
drop
procedure
if
exists
bug5251
|
--
enable_warnings
--
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
--
disable_warnings
drop
procedure
if
exists
bug
6642
|
drop
procedure
if
exists
bug
5287
|
--
enable_warnings
--
enable_warnings
create
procedure
bug5287
(
param1
int
)
label1
:
begin
declare
c
cursor
for
select
5
;
create
procedure
bug6642
()
loop
select
abs
(
count
(
s1
))
from
t3
|
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
--
disable_warnings
drop
procedure
if
exists
bug
7013
|
drop
procedure
if
exists
bug
5307
|
--
enable_warnings
--
enable_warnings
create
procedure
bug7013
()
create
procedure
bug5307
()
select
s1
,
count
(
s1
)
from
t3
group
by
s1
with
rollup
|
begin
call
bug7013
()
|
end
;
set
@
x
=
3
|
call
bug7013
()
|
drop
procedure
bug7013
|
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
--
disable_warnings
drop
table
if
exists
t4
|
drop
procedure
if
exists
bug5258
|
--
enable_warnings
--
enable_warnings
create
table
t4
(
create
procedure
bug5258
()
a
mediumint
(
8
)
unsigned
not
null
auto_increment
,
begin
b
smallint
(
5
)
unsigned
not
null
,
end
|
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'
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
7743
|
drop
procedure
if
exists
bug
5258_aux
|
--
enable_warnings
--
enable_warnings
create
procedure
bug
7743
(
searchstring
char
(
28
)
)
create
procedure
bug
5258_aux
(
)
begin
begin
declare
var
mediumint
(
8
)
unsigned
;
declare
c
,
m
char
(
19
);
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
|
#
select
created
,
modified
into
c
,
m
from
mysql
.
proc
where
name
=
'bug5258'
;
# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes
if
c
=
m
then
# the server
select
'Ok'
;
#
else
delete
from
t3
|
select
c
,
m
;
insert
into
t3
values
(
1
)
|
end
if
;
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
|
end
|
create
procedure
bug7992_2
()
insert
into
t3
(
s1
)
select
max
(
t4
.
s1
)
+
1
from
t3
as
t4
|
call
bug7992_1
()
|
call
bug5258_aux
()
|
call
bug7992_1
()
|
call
bug7992_2
()
|
call
bug7992_2
()
|
drop
procedure
bug7992_1
|
drop
procedure
bug5258
|
drop
procedure
bug7992_2
|
drop
procedure
bug5258_aux
|
drop
table
t3
|
#
#
# BUG#8116: calling simple stored procedure twice in a row results
# BUG#4487: Stored procedure connection aborted if uninitialized char
# in server crash
#
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t3
|
drop
function
if
exists
bug4487
|
--
enable_warnings
--
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
select
bug4487
()
|
drop
procedure
if
exists
bug8116
|
drop
function
bug4487
|
--
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
|
#
#
# BUG#
6857: current_time() in STORED PROCEDURES
# BUG#
4941: Stored procedure crash fetching null value into variable.
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
6857
|
drop
procedure
if
exists
bug
4941
|
--
enable_warnings
--
enable_warnings
create
procedure
bug6857
(
counter
int
)
--
disable_warnings
drop
procedure
if
exists
bug4941
|
--
enable_warnings
create
procedure
bug4941
(
out
x
int
)
begin
begin
declare
t0
,
t1
int
;
declare
c
cursor
for
select
i
from
t2
limit
1
;
declare
plus
bool
default
0
;
open
c
;
fetch
c
into
x
;
set
t0
=
current_time
();
close
c
;
while
counter
>
0
do
end
|
set
counter
=
counter
-
1
;
end
while
;
insert
into
t2
values
(
null
,
null
,
null
)
|
set
t1
=
current_time
();
set
@
x
=
42
|
if
t1
>
t0
then
call
bug4941
(
@
x
)
|
set
plus
=
1
;
select
@
x
|
end
if
;
delete
from
t1
|
select
plus
;
drop
procedure
bug4941
|
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)|
drop
procedure
bug6857
|
#
#
# BUG#
8757: Stored Procedures: Scope of Begin and End Statements do not
# BUG#
3583: query cache doesn't work for stored procedures
#
work properly.
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
8757
|
drop
procedure
if
exists
bug
3583
|
--
enable_warnings
--
enable_warnings
create
procedure
bug8757
()
--
disable_warnings
drop
procedure
if
exists
bug3583
|
--
enable_warnings
create
procedure
bug3583
()
begin
begin
declare
x
int
;
declare
c
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
;
select
*
from
t1
;
fetch
c2
into
y
;
select
count
(
*
)
into
c
from
t1
;
close
c2
;
select
c
;
select
2
,
y
;
end
;
open
c1
;
fetch
c1
into
x
;
close
c1
;
select
1
,
x
;
end
|
end
|
delete
from
t1
|
insert
into
t1
values
(
"x"
,
3
),
(
"y"
,
5
)
|
delete
from
t2
|
set
@
x
=
@@
query_cache_size
|
insert
into
t1
values
(
"x"
,
1
)
|
set
global
query_cache_size
=
10
*
1024
*
1024
|
insert
into
t2
values
(
"y"
,
2
,
0.0
)
|
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
t1
|
delete
from
t2
|
drop
procedure
bug3583
|
drop
procedure
bug8757
|
#
#
# BUG#
8762: Stored Procedures: Inconsistent behavior
# BUG#
4905: Stored procedure doesn't clear for "Rows affected"
#
of DROP PROCEDURE IF EXISTS statement.
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug8762
|
drop
table
if
exists
t3
|
drop
procedure
if
exists
bug4905
|
--
enable_warnings
--
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
))
|
#
--
disable_warnings
# Some "real" examples
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
--
disable_warnings
drop
table
if
exists
fac
|
drop
function
if
exists
bug6022
|
--
enable_warnings
--
enable_warnings
create
table
fac
(
n
int
unsigned
not
null
primary
key
,
f
bigint
unsigned
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
ifac
|
drop
function
if
exists
bug6022
|
--
enable_warnings
--
enable_warnings
create
procedure
ifac
(
n
int
unsigned
)
create
function
bug6022
(
x
int
)
returns
int
begin
begin
declare
i
int
unsigned
default
1
;
if
x
<
0
then
return
0
;
if
n
>
20
then
else
set
n
=
20
;
# bigint overflow otherwise
return
bug6022
(
x
-
1
);
end
if
;
end
if
;
while
i
<=
n
do
begin
insert
into
test
.
fac
values
(
i
,
fac
(
i
));
set
i
=
i
+
1
;
end
;
end
while
;
end
|
end
|
call
ifac
(
20
)
|
select
bug6022
(
5
)
|
select
*
from
fac
|
drop
function
bug6022
|
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#6029: Stored procedure specific handlers should have priority
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
primes
|
drop
procedure
if
exists
bug6029
|
--
enable_warnings
--
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
--
disable_warnings
drop
procedure
if
exists
opp
|
drop
procedure
if
exists
bug6029
|
--
enable_warnings
--
enable_warnings
create
procedure
opp
(
n
bigint
unsigned
,
out
pp
bool
)
create
procedure
bug6029
(
)
begin
begin
declare
r
double
;
declare
exit
handler
for
1136
select
'1136'
;
declare
b
,
s
bigint
unsigned
default
0
;
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
:
create
table
t3
(
s1
int
,
primary
key
(
s1
))
|
loop
insert
into
t3
values
(
1
)
|
if
s
=
45
then
call
bug6029
()
|
set
b
=
b
+
200
,
s
=
0
;
delete
from
t3
|
else
call
bug6029
()
|
begin
declare
p
bigint
unsigned
;
select
t
.
p
into
p
from
test
.
primes
t
where
t
.
i
=
s
;
drop
procedure
bug6029
|
if
b
+
p
>
r
then
drop
table
t3
|
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
|
#
# BUG#8540: Local variable overrides an alias
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
ip
|
drop
procedure
if
exists
bug8540
|
--
enable_warnings
--
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
call
bug8540
()
|
begin
drop
procedure
bug8540
|
declare
pp
bool
default
0
;
call
opp
(
p
,
pp
);
#
if
pp
then
# BUG#6642: Stored procedure crash if expression with set function
insert
into
test
.
primes
values
(
i
,
p
);
#
set
i
=
i
+
1
;
--
disable_warnings
end
if
;
drop
table
if
exists
t3
|
set
p
=
p
+
2
;
--
enable_warnings
end
;
create
table
t3
(
s1
int
)
|
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
--
disable_warnings
# don't be too ambitious. ;-)
drop
procedure
if
exists
bug6642
|
call
ip
(
200
)
|
--
enable_warnings
# 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%'
|
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
--
disable_warnings
drop
table
if
exists
fib
|
drop
procedure
if
exists
bug7013
|
--
enable_warnings
--
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
--
disable_warnings
drop
procedure
if
exists
fib
|
drop
procedure
if
exists
bug7743
|
--
enable_warnings
--
enable_warnings
create
procedure
fib
(
n
int
unsigned
)
create
procedure
bug7743
(
searchstring
char
(
28
)
)
begin
begin
if
n
>
0
then
declare
var
mediumint
(
8
)
unsigned
;
begin
select
a
into
var
from
t4
where
b
=
2
and
c
=
binary
searchstring
limit
1
;
declare
x
,
y
bigint
unsigned
;
select
var
;
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
|
end
|
call
fib
(
20
)
|
call
bug7743
(
"oneword"
)
|
call
bug7743
(
"OneWord"
)
|
select
*
from
fib
order
by
f
asc
|
call
bug7743
(
"anotherword"
)
|
drop
table
fib
|
call
bug7743
(
"AnotherWord"
)
|
drop
procedure
fib
|
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
call
bug7992_1
()
|
drop
procedure
if
exists
bar
|
call
bug7992_1
()
|
--
enable_warnings
call
bug7992_2
()
|
create
procedure
bar
(
x
char
(
16
),
y
int
)
call
bug7992_2
()
|
comment
"111111111111"
sql
security
invoker
insert
into
test
.
t1
values
(
x
,
y
)
|
drop
procedure
bug7992_1
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
drop
procedure
bug7992_2
|
show
procedure
status
like
'bar'
|
drop
table
t3
|
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
# BUG#8116: calling simple stored procedure twice in a row results
# in server crash
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
p1
|
drop
table
if
exists
t3
|
--
enable_warnings
--
enable_warnings
create
procedure
p1
()
create
table
t3
(
userid
bigint
(
20
)
not
null
default
0
)
|
select
(
select
s1
from
t3
)
from
t3
|
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
()
|
call
bug8116
(
42
)
|
insert
into
t3
values
(
1
)
|
call
bug8116
(
42
)
|
call
p1
()
|
drop
procedure
bug8116
|
drop
procedure
p1
|
drop
table
t3
|
drop
table
t3
|
#
#
#
backticks
#
BUG#6857: current_time() in STORED PROCEDURES
#
#
--
disable_warnings
--
disable_warnings
drop
function
if
exists
foo
|
drop
procedure
if
exists
bug6857
|
--
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
--
enable_warnings
create
function
t1max
()
returns
int
create
procedure
bug6857
(
counter
int
)
begin
begin
declare
x
int
;
declare
t0
,
t1
int
;
select
max
(
data
)
into
x
from
t1
;
declare
plus
bool
default
0
;
return
x
;
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
|
end
|
insert
into
t1
values
(
"foo"
,
3
),
(
"bar"
,
2
),
(
"zip"
,
5
),
(
"zap"
,
1
)
|
# QQ: This is currently disabled. Not only does it slow down a normal test
select
t1max
()
|
# run, it makes running with valgrind (or similar tools) extremely
drop
function
t1max
|
# 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
--
disable_warnings
drop
table
if
exists
t3
|
drop
procedure
if
exists
bug8757
|
--
enable_warnings
--
enable_warnings
create
table
t3
(
create
procedure
bug8757
()
v
char
(
16
)
not
null
primary
key
,
c
int
unsigned
not
null
)
|
create
function
getcount
(
s
char
(
16
))
returns
int
begin
begin
declare
x
int
;
declare
x
int
;
declare
c1
cursor
for
select
data
from
t1
limit
1
;
select
count
(
*
)
into
x
from
t3
where
v
=
s
;
begin
if
x
=
0
then
declare
y
int
;
insert
into
t3
values
(
s
,
1
);
declare
c2
cursor
for
select
i
from
t2
limit
1
;
else
update
t3
set
c
=
c
+
1
where
v
=
s
;
open
c2
;
end
if
;
fetch
c2
into
y
;
return
x
;
close
c2
;
select
2
,
y
;
end
;
open
c1
;
fetch
c1
into
x
;
close
c1
;
select
1
,
x
;
end
|
end
|
select
*
from
t1
where
data
=
getcount
(
"bar"
)
|
delete
from
t1
|
select
*
from
t3
|
delete
from
t2
|
select
getcount
(
"zip"
)
|
insert
into
t1
values
(
"x"
,
1
)
|
select
getcount
(
"zip"
)
|
insert
into
t2
values
(
"y"
,
2
,
0.0
)
|
select
*
from
t3
|
select
getcount
(
id
)
from
t1
where
data
=
3
|
call
bug8757
()
|
select
getcount
(
id
)
from
t1
where
data
=
5
|
select
*
from
t3
|
delete
from
t1
|
drop
table
t3
|
delete
from
t2
|
drop
function
getcount
|
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
# BUG#5240: Stored procedure crash if function has cursor declaration
...
@@ -3275,56 +3277,61 @@ call bug7992()|
...
@@ -3275,56 +3277,61 @@ call bug7992()|
drop
procedure
bug7992
|
drop
procedure
bug7992
|
drop
table
t3
|
drop
table
t3
|
delimiter
;
|
drop
table
t1
;
drop
table
t2
;
#
#
# Bug#8849: rolling back changes to AND/OR structure of ON and WHERE clauses
# BUG#8849: problem with insert statement with table alias's
# in SP
#
# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP
#
#
CREATE
TABLE
t1
(
create
table
t3
(
lpitnumber
int
(
11
)
default
NULL
,
lpitnumber
int
(
11
)
default
null
,
lrecordtype
int
(
11
)
default
NULL
lrecordtype
int
(
11
)
default
null
)
;
)
|
CREATE
TABLE
t2
(
create
table
t4
(
lbsiid
int
(
11
)
NOT
NULL
default
'0'
,
lbsiid
int
(
11
)
not
null
default
'0'
,
ltradingmodeid
int
(
11
)
NOT
NULL
default
'0'
,
ltradingmodeid
int
(
11
)
not
null
default
'0'
,
ltradingareaid
int
(
11
)
NOT
NULL
default
'0'
,
ltradingareaid
int
(
11
)
not
null
default
'0'
,
csellingprice
decimal
(
19
,
4
)
default
NULL
,
csellingprice
decimal
(
19
,
4
)
default
null
,
PRIMARY
KEY
(
lbsiid
,
ltradingmodeid
,
ltradingareaid
)
primary
key
(
lbsiid
,
ltradingmodeid
,
ltradingareaid
)
)
;
)
|
CREATE
TABLE
t3
(
create
table
t5
(
lbsiid
int
(
11
)
NOT
NULL
default
'0'
,
lbsiid
int
(
11
)
not
null
default
'0'
,
ltradingareaid
int
(
11
)
NOT
NULL
default
'0'
,
ltradingareaid
int
(
11
)
not
null
default
'0'
,
PRIMARY
KEY
(
lbsiid
,
ltradingareaid
)
primary
key
(
lbsiid
,
ltradingareaid
)
)
;
)
|
delimiter
|
;
--
disable_warnings
CREATE
PROCEDURE
bug8849
()
drop
procedure
if
exists
bug8849
|
--
enable_warnings
create
procedure
bug8849
()
begin
begin
insert
into
t
3
insert
into
t
5
(
(
t
3
.
lbsiid
,
t
5
.
lbsiid
,
t
3
.
ltradingareaid
t
5
.
ltradingareaid
)
)
select
distinct
t
1
.
lpitnumber
,
t2
.
ltradingareaid
select
distinct
t
3
.
lpitnumber
,
t4
.
ltradingareaid
from
from
t
2
join
t1
on
t
4
join
t3
on
t
1
.
lpitnumber
=
t2
.
lbsiid
t
3
.
lpitnumber
=
t4
.
lbsiid
and
t
1
.
lrecordtype
=
1
and
t
3
.
lrecordtype
=
1
left
join
t
2
as
price01
on
left
join
t
4
as
price01
on
price01
.
lbsiid
=
t
2
.
lbsiid
and
price01
.
lbsiid
=
t
4
.
lbsiid
and
price01
.
ltradingmodeid
=
1
and
price01
.
ltradingmodeid
=
1
and
t
2
.
ltradingareaid
=
price01
.
ltradingareaid
;
t
4
.
ltradingareaid
=
price01
.
ltradingareaid
;
end
|
end
|
delimiter
;
|
call
bug8849
();
call
bug8849
()
|
call
bug8849
();
call
bug8849
()
|
call
bug8849
();
call
bug8849
()
|
drop
procedure
bug8849
;
drop
procedure
bug8849
|
drop
tables
t1
,
t2
,
t3
;
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
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment