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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
45b5e513
Commit
45b5e513
authored
Mar 08, 2005
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge mysql.com:/usr/local/bk/mysql-5.0
into mysql.com:/home/pem/work/mysql-5.0
parents
05dfca24
25f8623f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2032 additions
and
1979 deletions
+2032
-1979
mysql-test/r/sp.result
mysql-test/r/sp.result
+702
-682
mysql-test/t/sp.test
mysql-test/t/sp.test
+1328
-1297
sql/item_sum.h
sql/item_sum.h
+2
-0
No files found.
mysql-test/r/sp.result
View file @
45b5e513
...
@@ -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),
...
@@ -2233,430 +2527,137 @@ abs(count(s1))
...
@@ -2233,430 +2527,137 @@ 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,62 @@ call bug7992()|
...
@@ -2696,43 +2697,62 @@ 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|
call bug8849()|
call bug8849()|
call bug8849()|
drop procedure bug8849|
drop tables t3,t4,t5|
drop procedure if exists bug8937|
create procedure bug8937()
begin
declare s,x,y,z int;
declare a float;
select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1;
select s,x,y,z;
select avg(data) into a from t1;
select a;
end|
end|
call bug8849();
delete from t1|
call bug8849();
insert into t1 (data) values (1), (2), (3), (4), (6)|
call bug8849();
call bug8937()|
drop procedure bug8849;
s x y z
drop tables t1,t2,t3;
16 3 1 6
a
3.2000
drop procedure bug8937|
delete from t1|
drop table t1,t2;
mysql-test/t/sp.test
View file @
45b5e513
...
@@ -1474,130 +1474,410 @@ delete from t2 |
...
@@ -1474,130 +1474,410 @@ delete from t2 |
#
#
#
Test cases for old bug
s
#
Some "real" example
s
#
#
#
# fac
# BUG#822
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug822
|
drop
table
if
exists
fac
|
--
enable_warnings
--
enable_warnings
create
procedure
bug822
(
a_id
char
(
16
),
a_data
int
)
create
table
fac
(
n
int
unsigned
not
null
primary
key
,
f
bigint
unsigned
)
|
--
disable_warnings
drop
procedure
if
exists
ifac
|
--
enable_warnings
create
procedure
ifac
(
n
int
unsigned
)
begin
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
=
0
then
if
n
>
2
0
then
insert
into
t1
(
id
,
data
)
values
(
a_id
,
a_data
);
set
n
=
20
;
# bigint overflow otherwise
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
bug822
(
'foo'
,
42
)
|
call
ifac
(
20
)
|
call
bug822
(
'foo'
,
42
)
|
select
*
from
fac
|
call
bug822
(
'bar'
,
666
)
|
drop
table
fac
|
select
*
from
t1
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
delete
from
t1
|
show
function
status
like
'%f%'
|
drop
procedure
bug822
|
drop
procedure
ifac
|
drop
function
fac
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
function
status
like
'%f%'
|
# primes
#
# BUG#1495
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug1495
|
drop
table
if
exists
primes
|
--
enable_warnings
--
enable_warnings
create
procedure
bug1495
()
create
table
primes
(
i
int
unsigned
not
null
primary
key
,
p
bigint
unsigned
not
null
)
|
insert
into
primes
values
(
0
,
3
),
(
1
,
5
),
(
2
,
7
),
(
3
,
11
),
(
4
,
13
),
(
5
,
17
),
(
6
,
19
),
(
7
,
23
),
(
8
,
29
),
(
9
,
31
),
(
10
,
37
),
(
11
,
41
),
(
12
,
43
),
(
13
,
47
),
(
14
,
53
),
(
15
,
59
),
(
16
,
61
),
(
17
,
67
),
(
18
,
71
),
(
19
,
73
),
(
20
,
79
),
(
21
,
83
),
(
22
,
89
),
(
23
,
97
),
(
24
,
101
),
(
25
,
103
),
(
26
,
107
),
(
27
,
109
),
(
28
,
113
),
(
29
,
127
),
(
30
,
131
),
(
31
,
137
),
(
32
,
139
),
(
33
,
149
),
(
34
,
151
),
(
35
,
157
),
(
36
,
163
),
(
37
,
167
),
(
38
,
173
),
(
39
,
179
),
(
40
,
181
),
(
41
,
191
),
(
42
,
193
),
(
43
,
197
),
(
44
,
199
)
|
--
disable_warnings
drop
procedure
if
exists
opp
|
--
enable_warnings
create
procedure
opp
(
n
bigint
unsigned
,
out
pp
bool
)
begin
begin
declare
x
int
;
declare
r
double
;
declare
b
,
s
bigint
unsigned
default
0
;
select
data
into
x
from
t1
order
by
id
limit
1
;
set
r
=
sqrt
(
n
);
if
x
>
10
then
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
)
|
call
bug1495
()
|
delete
from
t1
where
id
=
'foo'
|
insert
into
t1
values
(
'bar'
,
7
)
|
call
bug1495
()
|
delete
from
t1
where
id
=
'bar'
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
bug1495
|
#
# BUG#1547
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug1547
|
drop
procedure
if
exists
ip
|
--
enable_warnings
--
enable_warnings
create
procedure
bug1547
(
s
char
(
16
)
)
create
procedure
ip
(
m
int
unsigned
)
begin
begin
declare
x
int
;
declare
p
bigint
unsigned
;
declare
i
int
unsigned
;
select
data
into
x
from
t1
where
s
=
id
limit
1
;
set
i
=
45
,
p
=
201
;
if
x
>
10
then
insert
into
t1
values
(
"less"
,
x
-
10
);
while
i
<
m
do
else
begin
insert
into
t1
values
(
"more"
,
x
+
10
);
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
;
end
if
;
set
p
=
p
+
2
;
end
;
end
while
;
end
|
end
|
show
create
procedure
opp
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
procedure
status
like
'%p%'
|
insert
into
t1
values
(
"foo"
,
12
),
(
"bar"
,
7
)
|
# This isn't the fastest way in the world to compute prime numbers, so
call
bug1547
(
"foo"
)
|
# don't be too ambitious. ;-)
call
bug1547
(
"bar"
)
|
call
ip
(
200
)
|
select
*
from
t1
|
# We don't want to select the entire table here, just pick a few
delete
from
t1
|
# examples.
drop
procedure
bug1547
|
# The expected result is:
# i p
# --- ----
# 45 211
# 100 557
# 199 1229
select
*
from
primes
where
i
=
45
or
i
=
100
or
i
=
199
|
drop
table
primes
|
drop
procedure
opp
|
drop
procedure
ip
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
procedure
status
like
'%p%'
|
# Fibonacci, for recursion test. (Yet Another Numerical series :)
#
# BUG#1656
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t70
|
drop
table
if
exists
fib
|
--
enable_warnings
--
enable_warnings
create
table
t70
(
s1
int
,
s2
int
)
|
create
table
fib
(
f
bigint
unsigned
not
null
)
|
insert
into
t70
values
(
1
,
2
)
|
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
--
disable_warnings
drop
procedure
if
exists
bug1656
|
drop
procedure
if
exists
fib
|
--
enable_warnings
--
enable_warnings
create
procedure
bug1656
(
out
p1
int
,
out
p2
int
)
create
procedure
fib
(
n
int
unsigned
)
select
*
into
p1
,
p1
from
t70
|
begin
if
n
>
0
then
begin
declare
x
,
y
bigint
unsigned
;
declare
c
cursor
for
select
f
from
fib
order
by
f
desc
limit
2
;
open
c
;
fetch
c
into
y
;
fetch
c
into
x
;
close
c
;
insert
into
fib
values
(
x
+
y
);
call
fib
(
n
-
1
);
end
;
end
if
;
end
|
call
fib
(
20
)
|
select
*
from
fib
order
by
f
asc
|
drop
table
fib
|
drop
procedure
fib
|
call
bug1656
(
@
1
,
@
2
)
|
select
@
1
,
@
2
|
drop
table
t70
|
drop
procedure
bug1656
|
#
#
#
BUG#1862
#
Comment & suid
#
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t3
|
drop
procedure
if
exists
bar
|
--
enable_warnings
--
enable_warnings
create
table
t3
(
a
int
)
|
create
procedure
bar
(
x
char
(
16
),
y
int
)
comment
"111111111111"
sql
security
invoker
insert
into
test
.
t1
values
(
x
,
y
)
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
procedure
status
like
'bar'
|
alter
procedure
bar
comment
"2222222222"
sql
security
definer
|
alter
procedure
bar
comment
"3333333333"
|
alter
procedure
bar
|
show
create
procedure
bar
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
procedure
status
like
'bar'
|
drop
procedure
bar
|
#
# rexecution
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug1862
|
drop
procedure
if
exists
p1
|
--
enable_warnings
--
enable_warnings
create
procedure
bug1862
()
create
procedure
p1
()
begin
select
(
select
s1
from
t3
)
from
t3
|
insert
into
t3
values
(
2
);
flush
tables
;
end
|
call
bug1862
()
|
create
table
t3
(
s1
int
)
|
# the second call caused a segmentation
call
bug1862
()
|
call
p1
()
|
select
*
from
t3
|
insert
into
t3
values
(
1
)
|
call
p1
()
|
drop
procedure
p1
|
drop
table
t3
|
drop
table
t3
|
drop
procedure
bug1862
|
#
#
# BUG#1874
# backticks
#
--
disable_warnings
drop
function
if
exists
foo
|
--
enable_warnings
create
function
`
foo
` () returns int
return 5|
select `
foo
` ()|
drop function `
foo
`|
#
# Implicit LOCK/UNLOCK TABLES for table access in functions
#
--disable_warning
drop function if exists t1max|
--enable_warnings
create function t1max() returns int
begin
declare x int;
select max(data) into x from t1;
return x;
end|
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
select t1max()|
drop function t1max|
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3 (
v char(16) not null primary key,
c int unsigned not null
)|
create function getcount(s char(16)) returns int
begin
declare x int;
select count(*) into x from t3 where v = s;
if x = 0 then
insert into t3 values (s, 1);
else
update t3 set c = c+1 where v = s;
end if;
return x;
end|
select * from t1 where data = getcount("bar")|
select * from t3|
select getcount("zip")|
select getcount("zip")|
select * from t3|
select getcount(id) from t1 where data = 3|
select getcount(id) from t1 where data = 5|
select * from t3|
drop table t3|
drop function getcount|
#
# Test cases for old bugs
#
#
# BUG#822
#
--disable_warnings
drop procedure if exists bug822|
--enable_warnings
create procedure bug822(a_id char(16), a_data int)
begin
declare n int;
select count(*) into n from t1 where id = a_id and data = a_data;
if n = 0 then
insert into t1 (id, data) values (a_id, a_data);
end if;
end|
delete from t1|
call bug822('foo', 42)|
call bug822('foo', 42)|
call bug822('bar', 666)|
select * from t1|
delete from t1|
drop procedure bug822|
#
# BUG#1495
#
--disable_warnings
drop procedure if exists bug1495|
--enable_warnings
create procedure bug1495()
begin
declare x int;
select data into x from t1 order by id limit 1;
if x > 10 then
insert into t1 values ("less", x-10);
else
insert into t1 values ("more", x+10);
end if;
end|
insert into t1 values ('foo', 12)|
call bug1495()|
delete from t1 where id='foo'|
insert into t1 values ('bar', 7)|
call bug1495()|
delete from t1 where id='bar'|
select * from t1|
delete from t1|
drop procedure bug1495|
#
# BUG#1547
#
--disable_warnings
drop procedure if exists bug1547|
--enable_warnings
create procedure bug1547(s char(16))
begin
declare x int;
select data into x from t1 where s = id limit 1;
if x > 10 then
insert into t1 values ("less", x-10);
else
insert into t1 values ("more", x+10);
end if;
end|
insert into t1 values ("foo", 12), ("bar", 7)|
call bug1547("foo")|
call bug1547("bar")|
select * from t1|
delete from t1|
drop procedure bug1547|
#
# BUG#1656
#
--disable_warnings
drop table if exists t70|
--enable_warnings
create table t70 (s1 int,s2 int)|
insert into t70 values (1,2)|
--disable_warnings
drop procedure if exists bug1656|
--enable_warnings
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70|
call bug1656(@1, @2)|
select @1, @2|
drop table t70|
drop procedure bug1656|
#
# BUG#1862
#
--disable_warnings
drop table if exists t3|
--enable_warnings
create table t3(a int)|
--disable_warnings
drop procedure if exists bug1862|
--enable_warnings
create procedure bug1862()
begin
insert into t3 values(2);
flush tables;
end|
call bug1862()|
# the second call caused a segmentation
call bug1862()|
select * from t3|
drop table t3|
drop procedure bug1862|
#
# BUG#1874
#
#
--disable_warnings
--disable_warnings
drop procedure if exists bug1874|
drop procedure if exists bug1874|
...
@@ -1790,1423 +2070,1145 @@ drop procedure BUG3259_3|
...
@@ -1790,1423 +2070,1145 @@ drop procedure BUG3259_3|
# BUG#2772
# BUG#2772
#
#
--disable_warnings
--disable_warnings
drop
function
if
exists
bug2772
|
drop function if exists bug2772|
--
enable_warnings
create
function
bug2772
()
returns
char
(
10
)
character
set
latin2
return
'a'
|
select
bug2772
()
|
drop
function
bug2772
|
#
# BUG#2776
#
--
disable_warnings
drop
procedure
if
exists
bug2776_1
|
--
enable_warnings
create
procedure
bug2776_1
(
out
x
int
)
begin
declare
v
int
;
set
v
=
default
;
set
x
=
v
;
end
|
--
disable_warnings
drop
procedure
if
exists
bug2776_2
|
--
enable_warnings
create
procedure
bug2776_2
(
out
x
int
)
begin
declare
v
int
default
42
;
set
v
=
default
;
set
x
=
v
;
end
|
set
@
x
=
1
|
call
bug2776_1
(
@
x
)
|
select
@
x
|
call
bug2776_2
(
@
x
)
|
select
@
x
|
drop
procedure
bug2776_1
|
drop
procedure
bug2776_2
|
#
# BUG#2780
#
--
disable_warnings
drop
table
if
exists
t3
|
--
enable_warnings
create
table
t3
(
s1
smallint
)
|
insert
into
t3
values
(
123456789012
)
|
--
disable_warnings
drop
procedure
if
exists
bug2780
|
--
enable_warnings
create
procedure
bug2780
()
begin
declare
exit
handler
for
sqlwarning
set
@
x
=
1
;
set
@
x
=
0
;
insert
into
t3
values
(
123456789012
);
insert
into
t3
values
(
0
);
end
|
call
bug2780
()
|
select
@
x
|
select
*
from
t3
|
drop
procedure
bug2780
|
drop
table
t3
|
#
# BUG#1863
#
create
table
t3
(
content
varchar
(
10
)
)
|
insert
into
t3
values
(
"test1"
)
|
insert
into
t3
values
(
"test2"
)
|
create
table
t4
(
f1
int
,
rc
int
,
t3
int
)
|
--
disable_warnings
drop
procedure
if
exists
bug1863
|
--
enable_warnings
create
procedure
bug1863
(
in1
int
)
begin
declare
ind
int
default
0
;
declare
t1
int
;
declare
t2
int
;
declare
t3
int
;
declare
rc
int
default
0
;
declare
continue
handler
for
1065
set
rc
=
1
;
drop
temporary
table
if
exists
temp_t1
;
create
temporary
table
temp_t1
(
f1
int
auto_increment
,
f2
varchar
(
20
),
primary
key
(
f1
)
);
insert
into
temp_t1
(
f2
)
select
content
from
t3
;
select
f2
into
t3
from
temp_t1
where
f1
=
10
;
if
(
rc
)
then
insert
into
t4
values
(
1
,
rc
,
t3
);
end
if
;
insert
into
t4
values
(
2
,
rc
,
t3
);
end
|
call
bug1863
(
10
)
|
call
bug1863
(
10
)
|
select
*
from
t4
|
drop
procedure
bug1863
|
drop
temporary
table
temp_t1
;
drop
table
t3
,
t4
|
#
# BUG#2656
#
--
disable_warnings
drop
table
if
exists
t3
,
t4
|
--
enable_warnings
create
table
t3
(
OrderID
int
not
null
,
MarketID
int
,
primary
key
(
OrderID
)
)
|
create
table
t4
(
MarketID
int
not
null
,
Market
varchar
(
60
),
Status
char
(
1
),
primary
key
(
MarketID
)
)
|
insert
t3
(
OrderID
,
MarketID
)
values
(
1
,
1
)
|
insert
t3
(
OrderID
,
MarketID
)
values
(
2
,
2
)
|
insert
t4
(
MarketID
,
Market
,
Status
)
values
(
1
,
"MarketID One"
,
"A"
)
|
insert
t4
(
MarketID
,
Market
,
Status
)
values
(
2
,
"MarketID Two"
,
"A"
)
|
--
disable_warnings
drop
procedure
if
exists
bug2656_1
|
--
enable_warnings
create
procedure
bug2656_1
()
begin
select
m
.
Market
from
t4
m
JOIN
t3
o
ON
o
.
MarketID
!=
1
and
o
.
MarketID
=
m
.
MarketID
;
end
|
--
disable_warnings
drop
procedure
if
exists
bug2656_2
|
--
enable_warnings
create
procedure
bug2656_2
()
begin
select
m
.
Market
from
t4
m
,
t3
o
where
m
.
MarketID
!=
1
and
m
.
MarketID
=
o
.
MarketID
;
end
|
call
bug2656_1
()
|
call
bug2656_1
()
|
call
bug2656_2
()
|
call
bug2656_2
()
|
drop
procedure
bug2656_1
|
drop
procedure
bug2656_2
|
drop
table
t3
,
t4
|
#
# BUG#3426
#
--
disable_warnings
drop
procedure
if
exists
bug3426
|
--
enable_warnings
create
procedure
bug3426
(
in_time
int
unsigned
,
out
x
int
)
begin
if
in_time
is
null
then
set
@
stamped_time
=
10
;
set
x
=
1
;
else
set
@
stamped_time
=
in_time
;
set
x
=
2
;
end
if
;
end
|
call
bug3426
(
1000
,
@
i
)
|
select
@
i
,
from_unixtime
(
@
stamped_time
,
'%d-%m-%Y %h:%i:%s'
)
as
time
|
call
bug3426
(
NULL
,
@
i
)
|
select
@
i
,
from_unixtime
(
@
stamped_time
,
'%d-%m-%Y %h:%i:%s'
)
as
time
|
# Clear SP cache
alter
procedure
bug3426
sql
security
invoker
|
call
bug3426
(
NULL
,
@
i
)
|
select
@
i
,
from_unixtime
(
@
stamped_time
,
'%d-%m-%Y %h:%i:%s'
)
as
time
|
call
bug3426
(
1000
,
@
i
)
|
select
@
i
,
from_unixtime
(
@
stamped_time
,
'%d-%m-%Y %h:%i:%s'
)
as
time
|
drop
procedure
bug3426
|
#
# BUG#3448
#
--
disable_warnings
drop
table
if
exists
t3
,
t4
|
create
table
t3
(
a
int
primary
key
,
ach
char
(
1
)
)
engine
=
innodb
|
create
table
t4
(
b
int
primary
key
,
bch
char
(
1
)
)
engine
=
innodb
|
--
enable_warnings
insert
into
t3
values
(
1
,
'aCh1'
)
,
(
'2'
,
'aCh2'
)
|
insert
into
t4
values
(
1
,
'bCh1'
)
|
--
disable_warnings
drop
procedure
if
exists
bug3448
|
--
enable_warnings
create
procedure
bug3448
()
select
*
from
t3
inner
join
t4
on
t3
.
a
=
t4
.
b
|
select
*
from
t3
inner
join
t4
on
t3
.
a
=
t4
.
b
|
call
bug3448
()
|
call
bug3448
()
|
drop
procedure
bug3448
|
drop
table
t3
,
t4
|
#
# BUG#3734
#
--
disable_warnings
drop
table
if
exists
t3
|
--
enable_warnings
create
table
t3
(
id
int
unsigned
auto_increment
not
null
primary
key
,
title
VARCHAR
(
200
),
body
text
,
fulltext
(
title
,
body
)
)
|
insert
into
t3
(
title
,
body
)
values
(
'MySQL Tutorial'
,
'DBMS stands for DataBase ...'
),
(
'How To Use MySQL Well'
,
'After you went through a ...'
),
(
'Optimizing MySQL'
,
'In this tutorial we will show ...'
),
(
'1001 MySQL Tricks'
,
'1. Never run mysqld as root. 2. ...'
),
(
'MySQL vs. YourSQL'
,
'In the following database comparison ...'
),
(
'MySQL Security'
,
'When configured properly, MySQL ...'
)
|
--
disable_warnings
drop
procedure
if
exists
bug3734
|
--
enable_warnings
create
procedure
bug3734
(
param1
varchar
(
100
))
select
*
from
t3
where
match
(
title
,
body
)
against
(
param1
)
|
call
bug3734
(
'database'
)
|
call
bug3734
(
'Security'
)
|
drop
procedure
bug3734
|
drop
table
t3
|
#
# BUG#3863
#
--
disable_warnings
drop
procedure
if
exists
bug3863
|
--
enable_warnings
create
procedure
bug3863
()
begin
set
@
a
=
0
;
while
@
a
<
5
do
set
@
a
=
@
a
+
1
;
end
while
;
end
|
call
bug3863
()
|
select
@
a
|
call
bug3863
()
|
select
@
a
|
drop
procedure
bug3863
|
#
# BUG#2460
#
create
table
t3
(
id
int
(
10
)
unsigned
not
null
default
0
,
rid
int
(
10
)
unsigned
not
null
default
0
,
msg
text
not
null
,
primary
key
(
id
),
unique
key
rid
(
rid
,
id
)
)
|
--
disable_warnings
drop
procedure
if
exists
bug2460_1
|
--
enable_warnings
create
procedure
bug2460_1
(
in
v
int
)
begin
(
select
n0
.
id
from
t3
as
n0
where
n0
.
id
=
v
)
union
(
select
n0
.
id
from
t3
as
n0
,
t3
as
n1
where
n0
.
id
=
n1
.
rid
and
n1
.
id
=
v
)
union
(
select
n0
.
id
from
t3
as
n0
,
t3
as
n1
,
t3
as
n2
where
n0
.
id
=
n1
.
rid
and
n1
.
id
=
n2
.
rid
and
n2
.
id
=
v
);
end
|
call
bug2460_1
(
2
)
|
call
bug2460_1
(
2
)
|
insert
into
t3
values
(
1
,
1
,
'foo'
),
(
2
,
1
,
'bar'
),
(
3
,
1
,
'zip zap'
)
|
call
bug2460_1
(
2
)
|
call
bug2460_1
(
2
)
|
--
disable_warnings
drop
procedure
if
exists
bug2460_2
|
--
enable_warnings
create
procedure
bug2460_2
()
begin
drop
table
if
exists
t3
;
create
temporary
table
t3
(
s1
int
);
insert
into
t3
select
1
union
select
1
;
end
|
call
bug2460_2
()
|
call
bug2460_2
()
|
select
*
from
t3
|
drop
procedure
bug2460_1
|
drop
procedure
bug2460_2
|
drop
table
t3
|
#
# BUG#2564
#
set
@@
sql_mode
=
''
|
--
disable_warnings
drop
procedure
if
exists
bug2564_1
|
--
enable_warnings
create
procedure
bug2564_1
()
comment
'Joe''s procedure'
insert
into
`t1`
values
(
"foo"
,
1
)
|
set
@@
sql_mode
=
'ANSI_QUOTES'
|
--
disable_warnings
drop
procedure
if
exists
bug2564_2
|
--
enable_warnings
create
procedure
bug2564_2
()
insert
into
"t1"
values
(
'foo'
,
1
)
|
delimiter
$
|
set
@@
sql_mode
=
''
$
--
disable_warnings
drop
function
if
exists
bug2564_3
$
--
enable_warnings
create
function
bug2564_3
(
x
int
,
y
int
)
returns
int
return
x
||
y
$
set
@@
sql_mode
=
'ANSI'
$
--
disable_warnings
drop
function
if
exists
bug2564_4
$
--
enable_warnings
create
function
bug2564_4
(
x
int
,
y
int
)
returns
int
return
x
||
y
$
delimiter
|
$
set
@@
sql_mode
=
''
|
show
create
procedure
bug2564_1
|
show
create
procedure
bug2564_2
|
show
create
function
bug2564_3
|
show
create
function
bug2564_4
|
drop
procedure
bug2564_1
|
drop
procedure
bug2564_2
|
drop
function
bug2564_3
|
drop
function
bug2564_4
|
#
# BUG#3132
#
--
disable_warnings
drop
function
if
exists
bug3132
|
--
enable_warnings
create
function
bug3132
(
s
char
(
20
))
returns
char
(
50
)
return
concat
(
'Hello, '
,
s
,
'!'
)
|
select
bug3132
(
'Bob'
)
union
all
select
bug3132
(
'Judy'
)
|
drop
function
bug3132
|
#
# BUG#3843
#
--
disable_warnings
drop
procedure
if
exists
bug3843
|
--enable_warnings
--enable_warnings
create
procedure
bug3843
()
create function bug2772() returns char(10) character set latin2
analyze
table
t1
|
return 'a'|
# Testing for packets out of order
call
bug3843
()
|
call
bug3843
()
|
select
1
+
2
|
drop
procedure
bug3843
|
select bug2772()|
drop function bug2772|
#
#
# BUG#
3368
# BUG#
2776
#
#
--disable_warnings
--disable_warnings
drop
table
if
exists
t3
|
drop
procedure if exists bug2776_1
|
--enable_warnings
--enable_warnings
create
table
t3
(
s1
char
(
10
)
)
|
create procedure bug2776_1(out x int)
insert
into
t3
values
(
'a'
),
(
'b'
)
|
begin
declare v int;
set v = default;
set x = v;
end|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
3368
|
drop procedure if exists bug
2776_2
|
--enable_warnings
--enable_warnings
create
procedure
bug
3368
(
v
char
(
10
)
)
create procedure bug
2776_2(out x int
)
begin
begin
select
group_concat
(
v
)
from
t3
;
declare v int default 42;
set v = default;
set x = v;
end|
end|
call
bug3368
(
'x'
)
|
set @x = 1|
call
bug3368
(
'yz'
)
|
call bug2776_1(@x)|
drop
procedure
bug3368
|
select @x|
drop
table
t3
|
call bug2776_2(@x)|
select @x|
drop procedure bug2776_1|
drop procedure bug2776_2|
#
#
# BUG#
4579
# BUG#
2780
#
#
--disable_warnings
--disable_warnings
drop table if exists t3|
drop table if exists t3|
--enable_warnings
--enable_warnings
create
table
t3
(
f1
int
,
f2
int
)
|
create table t3 (s1 smallint)|
insert
into
t3
values
(
1
,
1
)
|
insert into t3 values (123456789012)|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
4579_1
|
drop procedure if exists bug
2780
|
--enable_warnings
--enable_warnings
create
procedure
bug
4579_1
()
create procedure bug
2780
()
begin
begin
declare
sf1
int
;
declare
exit handler for sqlwarning set @x = 1;
se
lect
f1
into
sf1
from
t3
where
f1
=
1
and
f2
=
1
;
se
t @x = 0
;
update
t3
set
f2
=
f2
+
1
where
f1
=
1
and
f2
=
1
;
insert into t3 values (123456789012)
;
call
bug4579_2
(
);
insert into t3 values (0
);
end|
end|
call bug2780()|
select @x|
select * from t3|
drop procedure bug2780|
drop table t3|
#
# BUG#1863
#
create table t3 (content varchar(10) )|
insert into t3 values ("test1")|
insert into t3 values ("test2")|
create table t4 (f1 int, rc int, t3 int)|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
4579_2
|
drop procedure if exists bug
1863
|
--enable_warnings
--enable_warnings
create
procedure
bug
4579_2
(
)
create procedure bug
1863(in1 int
)
begin
begin
end
|
call
bug4579_1
()
|
declare ind int default 0;
call
bug4579_1
()
|
declare t1 int;
call
bug4579_1
()
|
declare t2 int;
declare t3 int;
drop
procedure
bug4579_1
|
declare rc int default 0;
drop
procedure
bug4579_2
|
declare continue handler for 1065 set rc = 1;
drop
table
t3
|
drop temporary table if exists temp_t1;
create temporary table temp_t1 (
f1 int auto_increment, f2 varchar(20), primary key (f1)
);
insert into temp_t1 (f2) select content from t3;
select f2 into t3 from temp_t1 where f1 = 10;
if (rc) then
insert into t4 values (1, rc, t3);
end if;
insert into t4 values (2, rc, t3);
end|
call bug1863(10)|
call bug1863(10)|
select * from t4|
drop procedure bug1863|
drop temporary table temp_t1;
drop table t3, t4|
#
#
# BUG#
472
6
# BUG#
265
6
#
#
--disable_warnings
--disable_warnings
drop
table
if
exists
t3
|
drop table if exists t3
, t4
|
--enable_warnings
--enable_warnings
create
table
t3
(
f1
int
,
f2
int
,
f3
int
)
|
create table t3 (
insert
into
t3
values
(
1
,
1
,
1
)
|
OrderID int not null,
MarketID int,
primary key (OrderID)
)|
create table t4 (
MarketID int not null,
Market varchar(60),
Status char(1),
primary key (MarketID)
)|
insert t3 (OrderID,MarketID) values (1,1)|
insert t3 (OrderID,MarketID) values (2,2)|
insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")|
insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
4726
|
drop procedure if exists bug
2656_1
|
--enable_warnings
--enable_warnings
create
procedure
bug
4726
()
create procedure bug
2656_1
()
begin
begin
declare
tmp_o_id
INT
;
select
declare
tmp_d_id
INT
default
1
;
m.Market
from t4 m JOIN t3 o
ON o.MarketID != 1 and o.MarketID = m.MarketID;
end |
while
tmp_d_id
<=
2
do
--disable_warnings
begin
drop procedure if exists bug2656_2|
select
f1
into
tmp_o_id
from
t3
where
f2
=
1
and
f3
=
1
;
--enable_warnings
set
tmp_d_id
=
tmp_d_id
+
1
;
create procedure bug2656_2()
end
;
begin
end
while
;
select
end
|
m.Market
from
t4 m, t3 o
where
m.MarketID != 1 and m.MarketID = o.MarketID;
call
bug4726
()
|
end |
call
bug4726
()
|
call
bug4726
()
|
drop
procedure
bug4726
|
call bug2656_1()|
drop
table
t3
|
call bug2656_1()|
call bug2656_2()|
call bug2656_2()|
drop procedure bug2656_1|
drop procedure bug2656_2|
drop table t3, t4|
#
# BUG#4318
#
#QQ Don't know if HANDLER commands can work with SPs, or at all...
#--disable_warnings
#drop table if exists t3|
#--enable_warnings
#
#create table t3 (s1 int)|
#insert into t3 values (3), (4)|
#
#--disable_warnings
#drop procedure if exists bug4318|
#--enable_warnings
#create procedure bug4318()
# handler t3 read next|
#
#handler t3 open|
## Expect no results, as tables are closed, but there shouldn't be any errors
#call bug4318()|
#call bug4318()|
#handler t3 close|
#
#drop procedure bug4318|
#drop table t3|
#
#
# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error
# BUG#3426
#
# Added tests for most other show commands we could find too.
# (Skipping those already tested, and the ones depending on optional handlers.)
#
# Note: This will return a large number of results of different formats,
# which makes it impossible to filter with --replace_column.
# It's possible that some of these are not deterministic across
# platforms. If so, just remove the offending command.
#
#
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
4902
|
drop procedure if exists bug
3426
|
--enable_warnings
--enable_warnings
create
procedure
bug
4902
(
)
create procedure bug
3426(in_time int unsigned, out x int
)
begin
begin
show
charset
like
'foo'
;
if in_time is null then
show
collation
like
'foo'
;
set @stamped_time=10;
show
column
types
;
set x=1;
show
create
table
t1
;
else
show
create
database
test
;
set @stamped_time=in_time;
show
databases
like
'foo'
;
set x=2;
show
errors
;
end if;
show
columns
from
t1
;
show
grants
for
'root'
@
'localhost'
;
show
keys
from
t1
;
show
open
tables
like
'foo'
;
show
privileges
;
show
status
like
'foo'
;
show
tables
like
'foo'
;
show
variables
like
'foo'
;
show
warnings
;
end|
end|
#show binlog events;
#show storage engines;
#show master status;
#show slave hosts;
#show slave status;
call
bug4902
()
|
call
bug4902
()
|
drop
procedure
bug4902
|
call bug3426(1000, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
call bug3426(NULL, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
# Clear SP cache
alter procedure bug3426 sql security invoker|
call bug3426(NULL, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
call bug3426(1000, @i)|
select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
# We need separate SP for SHOW PROCESSLIST since we want use replace_column
drop procedure bug3426|
--
disable_warnings
drop
procedure
if
exists
bug4902_2
|
--
enable_warnings
create
procedure
bug4902_2
()
begin
show
processlist
;
end
|
--
replace_column
1
# 6 #
call
bug4902_2
()
|
--
replace_column
1
# 6 #
call
bug4902_2
()
|
drop
procedure
bug4902_2
|
#
#
# BUG#
4904
# BUG#
3448
#
#
--disable_warnings
--disable_warnings
drop
table
if
exists
t3
|
drop table if exists t3, t4|
create table t3 (
a int primary key,
ach char(1)
) engine = innodb|
create table t4 (
b int primary key ,
bch char(1)
) engine = innodb|
--enable_warnings
--enable_warnings
insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')|
insert into t4 values (1 , 'bCh1' )|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
4904
|
drop procedure if exists bug
3448
|
--enable_warnings
--enable_warnings
create
procedure
bug4904
()
create procedure bug3448()
begin
select * from t3 inner join t4 on t3.a = t4.b|
declare
continue
handler
for
sqlstate
'HY000'
begin
end
;
create
table
t2
as
select
*
from
t3
;
end
|
--
error
1146
select * from t3 inner join t4 on t3.a = t4.b|
call
bug4904
()
|
call bug3448()|
call bug3448()|
drop
procedure
bug4904
|
drop procedure bug3448|
drop table t3, t4|
create
table
t3
(
s1
char
character
set
latin1
,
s2
char
character
set
latin2
)
|
#
# BUG#3734
#
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug4904
|
drop
table if exists t3
|
--enable_warnings
--enable_warnings
create
procedure
bug4904
()
create table t3 (
begin
id int unsigned auto_increment not null primary key,
declare
continue
handler
for
sqlstate
'HY000'
begin
end
;
title VARCHAR(200),
body text,
fulltext (title,body)
)|
select
s1
from
t3
union
select
s2
from
t3
;
insert into t3 (title,body) values
end
|
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...')|
call
bug4904
()
|
--disable_warnings
drop procedure if exists bug3734 |
--enable_warnings
create procedure bug3734 (param1 varchar(100))
select * from t3 where match (title,body) against (param1)|
drop
procedure
bug4904
|
call bug3734('database')|
call bug3734('Security')|
drop procedure bug3734|
drop table t3|
drop table t3|
#
#
# BUG#3
36
# BUG#3
863
#
#
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug3
36
|
drop procedure if exists bug3
863
|
--enable_warnings
--enable_warnings
create
procedure
bug3
36
(
out
y
int
)
create procedure bug3
863(
)
begin
begin
declare
x
int
;
set @a = 0;
set
x
=
(
select
sum
(
t
.
data
)
from
test
.
t1
t
);
while @a < 5 do
set
y
=
x
;
set @a = @a + 1;
end while;
end|
end|
insert
into
t1
values
(
"a"
,
2
),
(
"b"
,
3
)
|
call bug3863()|
call
bug336
(
@
y
)
|
select @a|
select
@
y
|
call bug3863()|
delete
from
t1
|
select @a|
drop
procedure
bug336
|
drop procedure bug3863|
#
#
# BUG#
3157
# BUG#
2460
#
#
create table t3 (
id int(10) unsigned not null default 0,
rid int(10) unsigned not null default 0,
msg text not null,
primary key (id),
unique key rid (rid, id)
)|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
3157
|
drop procedure if exists bug
2460_1
|
--enable_warnings
--enable_warnings
create
procedure
bug
3157
(
)
create procedure bug
2460_1(in v int
)
begin
begin
if
exists
(
select
*
from
t1
)
then
( select n0.id from t3 as n0 where n0.id = v )
set
@
n
=
@
n
+
1
;
union
end
if
;
( select n0.id from t3 as n0, t3 as n1
if
(
select
count
(
*
)
from
t1
)
then
where n0.id = n1.rid and n1.id = v )
set
@
n
=
@
n
+
1
;
union
end
if
;
( select n0.id from t3 as n0, t3 as n1, t3 as n2
where n0.id = n1.rid and n1.id = n2.rid and n2.id = v );
end|
end|
set
@
n
=
0
|
call bug2460_1(2)|
insert
into
t1
values
(
"a"
,
1
)
|
call bug2460_1(2)|
call
bug3157
()
|
insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')|
select
@
n
|
call bug2460_1(2)|
delete
from
t1
|
call bug2460_1(2)|
drop
procedure
bug3157
|
#
# BUG#5251: mysql changes creation time of a procedure/function when altering
#
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
5251
|
drop procedure if exists bug
2460_2
|
--enable_warnings
--enable_warnings
create
procedure
bug
5251
()
create procedure bug
2460_2
()
begin
begin
drop table if exists t3;
create temporary table t3 (s1 int);
insert into t3 select 1 union select 1;
end|
end|
select
created
into
@
c1
from
mysql
.
proc
call bug2460_2()|
where
db
=
'test'
and
name
=
'bug5251'
|
call bug2460_2()|
--
sleep
2
select * from t3|
alter
procedure
bug5251
comment
'foobar'
|
select
count
(
*
)
from
mysql
.
proc
drop procedure bug2460_1|
where
db
=
'test'
and
name
=
'bug5251'
and
created
=
@
c1
|
drop procedure bug2460_2|
drop table t3|
drop
procedure
bug5251
|
#
#
# BUG#
5279: Stored procedure packets out of order if CHECKSUM TABLE
# BUG#
2564
#
#
set @@sql_mode = ''|
--disable_warnings
--disable_warnings
drop
procedure
if
exists
bug
525
1
|
drop procedure if exists bug
2564_
1|
--enable_warnings
--enable_warnings
create
procedure
bug5251
()
create procedure bug2564_1()
checksum
table
t1
|
comment 'Joe''s procedure'
insert into `
t1
`
values
(
"foo"
,
1
)
|
call
bug5251
()
|
call
bug5251
()
|
drop
procedure
bug5251
|
#
set
@@
sql_mode
=
'ANSI_QUOTES'
|
# BUG#5287: Stored procedure crash if leave outside loop
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
5287
|
drop
procedure
if
exists
bug
2564_2
|
--
enable_warnings
--
enable_warnings
create
procedure
bug5287
(
param1
int
)
create
procedure
bug2564_2
()
label1
:
insert
into
"t1"
values
(
'foo'
,
1
)
|
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
|
#
delimiter
$
|
# BUG#5307: Stored procedure allows statement after BEGIN ... END
set
@@
sql_mode
=
''
$
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug5307
|
drop
function
if
exists
bug2564_3
$
--
enable_warnings
--
enable_warnings
create
procedure
bug5307
()
create
function
bug2564_3
(
x
int
,
y
int
)
returns
int
begin
return
x
||
y
$
end
;
set
@
x
=
3
|
call
bug5307
()
|
select
@
x
|
drop
procedure
bug5307
|
#
set
@@
sql_mode
=
'ANSI'
$
# BUG#5258: Stored procedure modified date is 0000-00-00
# (This was a design flaw)
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug5258
|
drop
function
if
exists
bug2564_4
$
--
enable_warnings
--
enable_warnings
create
procedure
bug5258
()
create
function
bug2564_4
(
x
int
,
y
int
)
returns
int
begin
return
x
||
y
$
end
|
delimiter
|
$
set
@@
sql_mode
=
''
|
show
create
procedure
bug2564_1
|
show
create
procedure
bug2564_2
|
show
create
function
bug2564_3
|
show
create
function
bug2564_4
|
drop
procedure
bug2564_1
|
drop
procedure
bug2564_2
|
drop
function
bug2564_3
|
drop
function
bug2564_4
|
#
# BUG#3132
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug5258_aux
|
drop
function
if
exists
bug3132
|
--
enable_warnings
--
enable_warnings
create
procedure
bug5258_aux
()
create
function
bug3132
(
s
char
(
20
))
returns
char
(
50
)
begin
return
concat
(
'Hello, '
,
s
,
'!'
)
|
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
|
select
bug3132
(
'Bob'
)
union
all
select
bug3132
(
'Judy'
)
|
drop
procedure
bug5258_aux
|
drop
function
bug3132
|
#
#
# BUG#
4487: Stored procedure connection aborted if uninitialized char
# BUG#
3843
#
#
--
disable_warnings
--
disable_warnings
drop
function
if
exists
bug4487
|
drop
procedure
if
exists
bug3843
|
--
enable_warnings
--
enable_warnings
create
function
bug4487
()
returns
char
create
procedure
bug3843
()
begin
analyze
table
t1
|
declare
v
char
;
return
v
;
end
|
select
bug4487
()
|
# Testing for packets out of order
drop
function
bug4487
|
call
bug3843
()
|
call
bug3843
()
|
select
1
+
2
|
drop
procedure
bug3843
|
#
#
# BUG#
4941: Stored procedure crash fetching null value into variable.
# BUG#
3368
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug4941
|
drop
table
if
exists
t3
|
--
enable_warnings
--
enable_warnings
create
table
t3
(
s1
char
(
10
)
)
|
insert
into
t3
values
(
'a'
),
(
'b'
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
4941
|
drop
procedure
if
exists
bug
3368
|
--
enable_warnings
--
enable_warnings
create
procedure
bug
4941
(
out
x
int
)
create
procedure
bug
3368
(
v
char
(
10
)
)
begin
begin
declare
c
cursor
for
select
i
from
t2
limit
1
;
select
group_concat
(
v
)
from
t3
;
open
c
;
fetch
c
into
x
;
close
c
;
end
|
end
|
insert
into
t2
values
(
null
,
null
,
null
)
|
call
bug3368
(
'x'
)
|
set
@
x
=
42
|
call
bug3368
(
'yz'
)
|
call
bug4941
(
@
x
)
|
drop
procedure
bug3368
|
select
@
x
|
drop
table
t3
|
delete
from
t1
|
drop
procedure
bug4941
|
#
#
# BUG#
3583: query cache doesn't work for stored procedures
# BUG#
4579
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug358
3
|
drop
table
if
exists
t
3
|
--
enable_warnings
--
enable_warnings
create
table
t3
(
f1
int
,
f2
int
)
|
insert
into
t3
values
(
1
,
1
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
3583
|
drop
procedure
if
exists
bug
4579_1
|
--
enable_warnings
--
enable_warnings
create
procedure
bug
3583
()
create
procedure
bug
4579_1
()
begin
begin
declare
c
int
;
declare
sf1
int
;
select
*
from
t
1
;
select
f1
into
sf1
from
t3
where
f1
=
1
and
f2
=
1
;
select
count
(
*
)
into
c
from
t
1
;
update
t3
set
f2
=
f2
+
1
where
f1
=
1
and
f2
=
1
;
select
c
;
call
bug4579_2
()
;
end
|
end
|
insert
into
t1
values
(
"x"
,
3
),
(
"y"
,
5
)
|
--
disable_warnings
set
@
x
=
@@
query_cache_size
|
drop
procedure
if
exists
bug4579_2
|
set
global
query_cache_size
=
10
*
1024
*
1024
|
--
enable_warnings
create
procedure
bug4579_2
()
begin
end
|
flush
status
|
call
bug4579_1
()
|
flush
query
cache
|
call
bug4579_1
()
|
show
status
like
'Qcache_hits'
|
call
bug4579_1
()
|
call
bug3583
()
|
show
status
like
'Qcache_hits'
|
drop
procedure
bug4579_1
|
call
bug3583
()
|
drop
procedure
bug4579_2
|
call
bug3583
()
|
drop
table
t3
|
show
status
like
'Qcache_hits'
|
set
global
query_cache_size
=
@
x
|
flush
status
|
flush
query
cache
|
delete
from
t1
|
drop
procedure
bug3583
|
#
#
# BUG#4
905: Stored procedure doesn't clear for "Rows affected"
# BUG#4
726
#
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t3
|
drop
table
if
exists
t3
|
drop
procedure
if
exists
bug4905
|
--
enable_warnings
--
enable_warnings
create
table
t3
(
s1
int
,
primary
key
(
s1
))
|
create
table
t3
(
f1
int
,
f2
int
,
f3
int
)
|
insert
into
t3
values
(
1
,
1
,
1
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug4
905
|
drop
procedure
if
exists
bug4
726
|
--
enable_warnings
--
enable_warnings
create
procedure
bug4
905
()
create
procedure
bug4
726
()
begin
begin
declare
v
int
;
declare
tmp_o_id
INT
;
declare
continue
handler
for
sqlstate
'23000'
set
v
=
5
;
declare
tmp_d_id
INT
default
1
;
insert
into
t3
values
(
1
);
while
tmp_d_id
<=
2
do
begin
select
f1
into
tmp_o_id
from
t3
where
f2
=
1
and
f3
=
1
;
set
tmp_d_id
=
tmp_d_id
+
1
;
end
;
end
while
;
end
|
end
|
call
bug4905
()
|
call
bug4726
()
|
select
row_count
()
|
call
bug4726
()
|
call
bug4905
()
|
call
bug4726
()
|
select
row_count
()
|
call
bug4905
()
|
select
row_count
()
|
select
*
from
t3
|
drop
procedure
bug4
905
|
drop
procedure
bug4
726
|
drop
table
t3
|
drop
table
t3
|
#
#
# BUG#6022: Stored procedure shutdown problem with self-calling function.
# BUG#4318
#
#QQ Don't know if HANDLER commands can work with SPs, or at all...
#--disable_warnings
#drop table if exists t3|
#--enable_warnings
#
#create table t3 (s1 int)|
#insert into t3 values (3), (4)|
#
#--disable_warnings
#drop procedure if exists bug4318|
#--enable_warnings
#create procedure bug4318()
# handler t3 read next|
#
#handler t3 open|
## Expect no results, as tables are closed, but there shouldn't be any errors
#call bug4318()|
#call bug4318()|
#handler t3 close|
#
#drop procedure bug4318|
#drop table t3|
#
# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error
#
# Added tests for most other show commands we could find too.
# (Skipping those already tested, and the ones depending on optional handlers.)
#
# Note: This will return a large number of results of different formats,
# which makes it impossible to filter with --replace_column.
# It's possible that some of these are not deterministic across
# platforms. If so, just remove the offending command.
#
#
--
disable_warnings
--
disable_warnings
drop
function
if
exists
bug602
2
|
drop
procedure
if
exists
bug490
2
|
--
enable_warnings
--
enable_warnings
create
procedure
bug4902
()
begin
show
charset
like
'foo'
;
show
collation
like
'foo'
;
show
column
types
;
show
create
table
t1
;
show
create
database
test
;
show
databases
like
'foo'
;
show
errors
;
show
columns
from
t1
;
show
grants
for
'root'
@
'localhost'
;
show
keys
from
t1
;
show
open
tables
like
'foo'
;
show
privileges
;
show
status
like
'foo'
;
show
tables
like
'foo'
;
show
variables
like
'foo'
;
show
warnings
;
end
|
#show binlog events;
#show storage engines;
#show master status;
#show slave hosts;
#show slave status;
call
bug4902
()
|
call
bug4902
()
|
drop
procedure
bug4902
|
# We need separate SP for SHOW PROCESSLIST since we want use replace_column
--
disable_warnings
--
disable_warnings
drop
function
if
exists
bug602
2
|
drop
procedure
if
exists
bug4902_
2
|
--
enable_warnings
--
enable_warnings
create
function
bug6022
(
x
int
)
returns
int
create
procedure
bug4902_2
()
begin
begin
if
x
<
0
then
show
processlist
;
return
0
;
else
return
bug6022
(
x
-
1
);
end
if
;
end
|
end
|
--
replace_column
1
# 6 #
select
bug6022
(
5
)
|
call
bug4902_2
()
|
drop
function
bug6022
|
--
replace_column
1
# 6 #
call
bug4902_2
()
|
drop
procedure
bug4902_2
|
#
#
# BUG#
6029: Stored procedure specific handlers should have priority
# BUG#
4904
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug6029
|
drop
table
if
exists
t3
|
--
enable_warnings
--
disable_warnings
drop
procedure
if
exists
bug4904
|
--
enable_warnings
--
enable_warnings
create
procedure
bug4904
()
begin
declare
continue
handler
for
sqlstate
'HY000'
begin
end
;
create
table
t2
as
select
*
from
t3
;
end
|
--
error
1146
call
bug4904
()
|
drop
procedure
bug4904
|
create
table
t3
(
s1
char
character
set
latin1
,
s2
char
character
set
latin2
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
6029
|
drop
procedure
if
exists
bug
4904
|
--
enable_warnings
--
enable_warnings
create
procedure
bug
6029
()
create
procedure
bug
4904
()
begin
begin
declare
exit
handler
for
1136
select
'1136'
;
declare
continue
handler
for
sqlstate
'HY000'
begin
end
;
declare
exit
handler
for
sqlstate
'23000'
select
'sqlstate 23000'
;
declare
continue
handler
for
sqlexception
select
'sqlexception'
;
insert
into
t3
values
(
1
);
select
s1
from
t3
union
select
s2
from
t3
;
insert
into
t3
values
(
1
,
2
);
end
|
end
|
create
table
t3
(
s1
int
,
primary
key
(
s1
))
|
call
bug4904
()
|
insert
into
t3
values
(
1
)
|
call
bug6029
()
|
delete
from
t3
|
call
bug6029
()
|
drop
procedure
bug
6029
|
drop
procedure
bug
4904
|
drop
table
t3
|
drop
table
t3
|
#
#
# BUG#
8540: Local variable overrides an alias
# BUG#
336
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
8540
|
drop
procedure
if
exists
bug
336
|
--
enable_warnings
--
enable_warnings
create
procedure
bug336
(
out
y
int
)
create
procedure
bug8540
()
begin
begin
declare
x
int
default
1
;
declare
x
int
;
select
x
as
y
,
x
+
0
as
z
;
set
x
=
(
select
sum
(
t
.
data
)
from
test
.
t1
t
);
set
y
=
x
;
end
|
end
|
call
bug8540
()
|
insert
into
t1
values
(
"a"
,
2
),
(
"b"
,
3
)
|
drop
procedure
bug8540
|
call
bug336
(
@
y
)
|
select
@
y
|
delete
from
t1
|
drop
procedure
bug336
|
#
#
# BUG#
6642: Stored procedure crash if expression with set function
# BUG#
3157
#
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t3
|
drop
procedure
if
exists
bug3157
|
--
enable_warnings
--
enable_warnings
create
table
t3
(
s1
int
)
|
create
procedure
bug3157
()
begin
if
exists
(
select
*
from
t1
)
then
set
@
n
=
@
n
+
1
;
end
if
;
if
(
select
count
(
*
)
from
t1
)
then
set
@
n
=
@
n
+
1
;
end
if
;
end
|
set
@
n
=
0
|
insert
into
t1
values
(
"a"
,
1
)
|
call
bug3157
()
|
select
@
n
|
delete
from
t1
|
drop
procedure
bug3157
|
#
# BUG#5251: mysql changes creation time of a procedure/function when altering
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
6642
|
drop
procedure
if
exists
bug
5251
|
--
enable_warnings
--
enable_warnings
create
procedure
bug5251
()
begin
end
|
create
procedure
bug6642
()
select
created
into
@
c1
from
mysql
.
proc
select
abs
(
count
(
s1
))
from
t3
|
where
db
=
'test'
and
name
=
'bug5251'
|
--
sleep
2
alter
procedure
bug5251
comment
'foobar'
|
select
count
(
*
)
from
mysql
.
proc
where
db
=
'test'
and
name
=
'bug5251'
and
created
=
@
c1
|
call
bug6642
()
|
drop
procedure
bug5251
|
call
bug6642
()
|
drop
procedure
bug6642
|
#
#
# BUG#
7013: Stored procedure crash if group by ... with rollup
# BUG#
5279: Stored procedure packets out of order if CHECKSUM TABLE
#
#
insert
into
t3
values
(
0
),(
1
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
7013
|
drop
procedure
if
exists
bug
5251
|
--
enable_warnings
--
enable_warnings
create
procedure
bug7013
()
create
procedure
bug5251
()
select
s1
,
count
(
s1
)
from
t3
group
by
s1
with
rollup
|
checksum
table
t1
|
call
bug7013
()
|
call
bug7013
()
|
call
bug5251
()
|
drop
procedure
bug7013
|
call
bug5251
()
|
drop
procedure
bug5251
|
#
#
# BUG#
7743: 'Lost connection to MySQL server during query' on Stored Procedure
# BUG#
5287: Stored procedure crash if leave outside loop
#
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t4
|
drop
procedure
if
exists
bug5287
|
--
enable_warnings
--
enable_warnings
create
table
t4
(
create
procedure
bug5287
(
param1
int
)
a
mediumint
(
8
)
unsigned
not
null
auto_increment
,
label1
:
b
smallint
(
5
)
unsigned
not
null
,
begin
c
char
(
32
)
not
null
,
declare
c
cursor
for
select
5
;
primary
key
(
a
)
)
engine
=
myisam
default
charset
=
latin1
|
insert
into
t4
values
(
1
,
2
,
'oneword'
)
|
insert
into
t4
values
(
2
,
2
,
'anotherword'
)
|
--
disable_warnings
loop
drop
procedure
if
exists
bug7743
|
if
param1
>=
0
then
--
enable_warnings
leave
label1
;
create
procedure
bug7743
(
searchstring
char
(
28
)
)
end
if
;
begin
end
loop
;
declare
var
mediumint
(
8
)
unsigned
;
select
a
into
var
from
t4
where
b
=
2
and
c
=
binary
searchstring
limit
1
;
select
var
;
end
|
end
|
call
bug5287
(
1
)
|
drop
procedure
bug5287
|
call
bug7743
(
"oneword"
)
|
call
bug7743
(
"OneWord"
)
|
call
bug7743
(
"anotherword"
)
|
call
bug7743
(
"AnotherWord"
)
|
drop
procedure
bug7743
|
drop
table
t4
|
#
#
# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes
# BUG#5307: Stored procedure allows statement after BEGIN ... END
# the server
#
#
delete
from
t3
|
--
disable_warnings
insert
into
t3
values
(
1
)
|
drop
procedure
if
exists
bug5307
|
drop
procedure
if
exists
bug7992_1
|
--
enable_warnings
drop
procedure
if
exists
bug7992_2
|
create
procedure
bug5307
()
create
procedure
bug7992_1
()
begin
begin
declare
i
int
;
end
;
set
@
x
=
3
|
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
|
call
bug5307
()
|
drop
procedure
bug7992_2
|
select
@
x
|
drop
table
t3
|
drop
procedure
bug5307
|
#
#
# BUG#8116: calling simple stored procedure twice in a row results
# BUG#5258: Stored procedure modified date is 0000-00-00
# in server crash
# (This was a design flaw)
#
--
disable_warnings
drop
table
if
exists
t3
|
--
enable_warnings
create
table
t3
(
userid
bigint
(
20
)
not
null
default
0
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
8116
|
drop
procedure
if
exists
bug
5258
|
--
enable_warnings
--
enable_warnings
create
procedure
bug8116
(
in
_userid
int
)
create
procedure
bug5258
()
select
*
from
t3
where
userid
=
_userid
|
begin
end
|
call
bug8116
(
42
)
|
call
bug8116
(
42
)
|
drop
procedure
bug8116
|
drop
table
t3
|
#
# BUG#6857: current_time() in STORED PROCEDURES
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
6857
|
drop
procedure
if
exists
bug
5258_aux
|
--
enable_warnings
--
enable_warnings
create
procedure
bug
6857
(
counter
int
)
create
procedure
bug
5258_aux
(
)
begin
begin
declare
t0
,
t1
int
;
declare
c
,
m
char
(
19
);
declare
plus
bool
default
0
;
set
t0
=
current_time
();
select
created
,
modified
into
c
,
m
from
mysql
.
proc
where
name
=
'bug5258'
;
while
counter
>
0
do
if
c
=
m
then
set
counter
=
counter
-
1
;
select
'Ok'
;
end
while
;
else
set
t1
=
current_time
();
select
c
,
m
;
if
t1
>
t0
then
set
plus
=
1
;
end
if
;
end
if
;
select
plus
;
end
|
end
|
# QQ: This is currently disabled. Not only does it slow down a normal test
call
bug5258_aux
()
|
# 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
|
drop
procedure
bug5258
|
drop
procedure
bug5258_aux
|
#
#
# BUG#
8757: Stored Procedures: Scope of Begin and End Statements do not
# BUG#
4487: Stored procedure connection aborted if uninitialized char
#
work properly.
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug875
7
|
drop
function
if
exists
bug448
7
|
--
enable_warnings
--
enable_warnings
create
procedure
bug8757
()
create
function
bug4487
()
returns
char
begin
begin
declare
x
int
;
declare
v
char
;
declare
c1
cursor
for
select
data
from
t1
limit
1
;
return
v
;
end
|
begin
declare
y
int
;
select
bug4487
()
|
declare
c2
cursor
for
select
i
from
t2
limit
1
;
drop
function
bug4487
|
open
c2
;
fetch
c2
into
y
;
close
c2
;
select
2
,
y
;
end
;
open
c1
;
fetch
c1
into
x
;
close
c1
;
select
1
,
x
;
end
|
delete
from
t1
|
delete
from
t2
|
insert
into
t1
values
(
"x"
,
1
)
|
insert
into
t2
values
(
"y"
,
2
,
0.0
)
|
call
bug8757
()
|
delete
from
t1
|
delete
from
t2
|
drop
procedure
bug8757
|
#
#
# BUG#
8762: Stored Procedures: Inconsistent behavior
# BUG#
4941: Stored procedure crash fetching null value into variable.
#
of DROP PROCEDURE IF EXISTS statement.
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
bug
8762
|
drop
procedure
if
exists
bug
4941
|
--
enable_warnings
--
enable_warnings
# Doesn't exist
--
disable_warnings
drop
procedure
if
exists
bug8762
;
create
procedure
bug8762
()
begin
end
|
drop
procedure
if
exists
bug4941
|
# Does exist
--
enable_warnings
drop
procedure
if
exists
bug8762
;
create
procedure
bug8762
()
begin
end
|
create
procedure
bug4941
(
out
x
int
)
drop
procedure
bug8762
|
begin
declare
c
cursor
for
select
i
from
t2
limit
1
;
open
c
;
fetch
c
into
x
;
close
c
;
end
|
insert
into
t2
values
(
null
,
null
,
null
)
|
set
@
x
=
42
|
call
bug4941
(
@
x
)
|
select
@
x
|
delete
from
t1
|
drop
procedure
bug4941
|
#
#
#
Some "real" exampl
es
#
BUG#3583: query cache doesn't work for stored procedur
es
#
#
# fac
--
disable_warnings
--
disable_warnings
drop
table
if
exists
fac
|
drop
procedure
if
exists
bug3583
|
--
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
procedure
if
exists
bug3583
|
--
enable_warnings
--
enable_warnings
create
procedure
ifac
(
n
int
unsigned
)
create
procedure
bug3583
(
)
begin
begin
declare
i
int
unsigned
default
1
;
declare
c
int
;
if
n
>
20
then
select
*
from
t1
;
set
n
=
20
;
# bigint overflow otherwise
select
count
(
*
)
into
c
from
t1
;
end
if
;
select
c
;
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
)
|
insert
into
t1
values
(
"x"
,
3
),
(
"y"
,
5
)
|
select
*
from
fac
|
set
@
x
=
@@
query_cache_size
|
drop
table
fac
|
set
global
query_cache_size
=
10
*
1024
*
1024
|
--
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%'
|
flush
status
|
flush
query
cache
|
show
status
like
'Qcache_hits'
|
call
bug3583
()
|
show
status
like
'Qcache_hits'
|
call
bug3583
()
|
call
bug3583
()
|
show
status
like
'Qcache_hits'
|
# primes
set
global
query_cache_size
=
@
x
|
flush
status
|
flush
query
cache
|
delete
from
t1
|
drop
procedure
bug3583
|
#
# BUG#4905: Stored procedure doesn't clear for "Rows affected"
#
--
disable_warnings
--
disable_warnings
drop
table
if
exists
primes
|
drop
table
if
exists
t3
|
drop
procedure
if
exists
bug4905
|
--
enable_warnings
--
enable_warnings
create
table
primes
(
create
table
t3
(
s1
int
,
primary
key
(
s1
))
|
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
bug4905
|
--
enable_warnings
--
enable_warnings
create
procedure
opp
(
n
bigint
unsigned
,
out
pp
bool
)
create
procedure
bug4905
(
)
begin
begin
declare
r
double
;
declare
v
int
;
declare
b
,
s
bigint
unsigned
default
0
;
declare
continue
handler
for
sqlstate
'23000'
set
v
=
5
;
set
r
=
sqrt
(
n
);
insert
into
t3
values
(
1
);
end
|
again
:
call
bug4905
()
|
loop
select
row_count
()
|
if
s
=
45
then
call
bug4905
()
|
set
b
=
b
+
200
,
s
=
0
;
select
row_count
()
|
else
call
bug4905
()
|
begin
select
row_count
()
|
declare
p
bigint
unsigned
;
select
*
from
t3
|
select
t
.
p
into
p
from
test
.
primes
t
where
t
.
i
=
s
;
drop
procedure
bug4905
|
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#6022: Stored procedure shutdown problem with self-calling function.
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
ip
|
drop
function
if
exists
bug6022
|
--
enable_warnings
--
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
);
--
disable_warnings
if
pp
then
drop
function
if
exists
bug6022
|
insert
into
test
.
primes
values
(
i
,
p
);
--
enable_warnings
set
i
=
i
+
1
;
create
function
bug6022
(
x
int
)
returns
int
begin
if
x
<
0
then
return
0
;
else
return
bug6022
(
x
-
1
);
end
if
;
end
if
;
set
p
=
p
+
2
;
end
;
end
while
;
end
|
end
|
show
create
procedure
opp
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
procedure
status
like
'%p%'
|
# This isn't the fastest way in the world to compute prime numbers, so
# don't be too ambitious. ;-)
call
ip
(
200
)
|
# We don't want to select the entire table here, just pick a few
# examples.
# The expected result is:
# i p
# --- ----
# 45 211
# 100 557
# 199 1229
select
*
from
primes
where
i
=
45
or
i
=
100
or
i
=
199
|
drop
table
primes
|
drop
procedure
opp
|
drop
procedure
ip
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
show
procedure
status
like
'%p%'
|
select
bug6022
(
5
)
|
drop
function
bug6022
|
# Fibonacci, for recursion test. (Yet Another Numerical series :)
#
# BUG#6029: Stored procedure specific handlers should have priority
#
--
disable_warnings
drop
procedure
if
exists
bug6029
|
--
enable_warnings
--
disable_warnings
--
disable_warnings
drop
table
if
exists
fib
|
drop
procedure
if
exists
bug6029
|
--
enable_warnings
--
enable_warnings
create
table
fib
(
f
bigint
unsigned
not
null
)
|
create
procedure
bug6029
()
begin
declare
exit
handler
for
1136
select
'1136'
;
declare
exit
handler
for
sqlstate
'23000'
select
'sqlstate 23000'
;
declare
continue
handler
for
sqlexception
select
'sqlexception'
;
insert
into
fib
values
(
1
),
(
1
)
|
insert
into
t3
values
(
1
);
insert
into
t3
values
(
1
,
2
);
end
|
# We deliberately do it the awkward way, fetching the last two
create
table
t3
(
s1
int
,
primary
key
(
s1
))
|
# values from the table, in order to exercise various statements
insert
into
t3
values
(
1
)
|
# and table accesses at each turn.
call
bug6029
()
|
delete
from
t3
|
call
bug6029
()
|
drop
procedure
bug6029
|
drop
table
t3
|
#
# BUG#8540: Local variable overrides an alias
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
fib
|
drop
procedure
if
exists
bug8540
|
--
enable_warnings
--
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
;
create
procedure
bug8540
()
fetch
c
into
y
;
begin
fetch
c
into
x
;
declare
x
int
default
1
;
close
c
;
select
x
as
y
,
x
+
0
as
z
;
insert
into
fib
values
(
x
+
y
);
call
fib
(
n
-
1
);
end
;
end
if
;
end
|
end
|
call
fib
(
20
)
|
call
bug8540
()
|
drop
procedure
bug8540
|
select
*
from
fib
order
by
f
asc
|
#
drop
table
fib
|
# BUG#6642: Stored procedure crash if expression with set function
drop
procedure
fib
|
#
--
disable_warnings
drop
table
if
exists
t3
|
--
enable_warnings
create
table
t3
(
s1
int
)
|
--
disable_warnings
drop
procedure
if
exists
bug6642
|
--
enable_warnings
create
procedure
bug6642
()
select
abs
(
count
(
s1
))
from
t3
|
call
bug6642
()
|
call
bug6642
()
|
drop
procedure
bug6642
|
#
#
#
Comment & suid
#
BUG#7013: Stored procedure crash if group by ... with rollup
#
#
insert
into
t3
values
(
0
),(
1
)
|
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
b
ar
|
drop
procedure
if
exists
b
ug7013
|
--
enable_warnings
--
enable_warnings
create
procedure
bar
(
x
char
(
16
),
y
int
)
create
procedure
bug7013
()
comment
"111111111111"
sql
security
invoker
select
s1
,
count
(
s1
)
from
t3
group
by
s1
with
rollup
|
insert
into
test
.
t1
values
(
x
,
y
)
|
call
bug7013
()
|
--
replace_column
5
'0000-00-00 00:00:00'
6
'0000-00-00 00:00:00'
call
bug7013
()
|
show
procedure
status
like
'bar'
|
drop
procedure
bug7013
|
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#7743: 'Lost connection to MySQL server during query' on Stored Procedure
#
#
--
disable_warnings
--
disable_warnings
drop
procedure
if
exists
p1
|
drop
table
if
exists
t4
|
--
enable_warnings
--
enable_warnings
create
procedure
p1
()
create
table
t4
(
select
(
select
s1
from
t3
)
from
t3
|
a
mediumint
(
8
)
unsigned
not
null
auto_increment
,
b
smallint
(
5
)
unsigned
not
null
,
c
char
(
32
)
not
null
,
primary
key
(
a
)
)
engine
=
myisam
default
charset
=
latin1
|
insert
into
t4
values
(
1
,
2
,
'oneword'
)
|
insert
into
t4
values
(
2
,
2
,
'anotherword'
)
|
create
table
t3
(
s1
int
)
|
--
disable_warnings
drop
procedure
if
exists
bug7743
|
--
enable_warnings
create
procedure
bug7743
(
searchstring
char
(
28
)
)
begin
declare
var
mediumint
(
8
)
unsigned
;
select
a
into
var
from
t4
where
b
=
2
and
c
=
binary
searchstring
limit
1
;
select
var
;
end
|
call
p1
()
|
call
bug7743
(
"oneword"
)
|
insert
into
t3
values
(
1
)
|
call
bug7743
(
"OneWord"
)
|
call
p1
()
|
call
bug7743
(
"anotherword"
)
|
drop
procedure
p1
|
call
bug7743
(
"AnotherWord"
)
|
drop
procedure
bug7743
|
drop
table
t4
|
#
# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes
# the server
#
delete
from
t3
|
insert
into
t3
values
(
1
)
|
drop
procedure
if
exists
bug7992_1
|
drop
procedure
if
exists
bug7992_2
|
create
procedure
bug7992_1
()
begin
declare
i
int
;
select
max
(
s1
)
+
1
into
i
from
t3
;
end
|
create
procedure
bug7992_2
()
insert
into
t3
(
s1
)
select
max
(
t4
.
s1
)
+
1
from
t3
as
t4
|
call
bug7992_1
()
|
call
bug7992_1
()
|
call
bug7992_2
()
|
call
bug7992_2
()
|
drop
procedure
bug7992_1
|
drop
procedure
bug7992_2
|
drop
table
t3
|
drop
table
t3
|
#
#
# backticks
# BUG#8116: calling simple stored procedure twice in a row results
# in server crash
#
#
--
disable_warnings
--
disable_warnings
drop
function
if
exists
foo
|
drop
table
if
exists
t3
|
--
enable_warnings
--
enable_warnings
create
function
`
foo
` () returns int
create
table
t3
(
userid
bigint
(
20
)
not
null
default
0
)
|
return 5|
select `
foo
` ()|
--
disable_warnings
drop function `
foo
`
|
drop
procedure
if
exists
bug8116
|
--
enable_warnings
create
procedure
bug8116
(
in
_userid
int
)
select
*
from
t3
where
userid
=
_userid
|
call
bug8116
(
42
)
|
call
bug8116
(
42
)
|
drop
procedure
bug8116
|
drop
table
t3
|
#
#
#
Implicit LOCK/UNLOCK TABLES for table access in functions
#
BUG#6857: current_time() in STORED PROCEDURES
#
#
--
disable_warnings
--
disable_warning
drop
procedure
if
exists
bug6857
|
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,85 @@ call bug7992()|
...
@@ -3275,56 +3277,85 @@ 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
|
#
# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement
#
--
disable_warnings
drop
procedure
if
exists
bug8937
|
--
enable_warnings
create
procedure
bug8937
()
begin
declare
s
,
x
,
y
,
z
int
;
declare
a
float
;
select
sum
(
data
),
avg
(
data
),
min
(
data
),
max
(
data
)
into
s
,
x
,
y
,
z
from
t1
;
select
s
,
x
,
y
,
z
;
select
avg
(
data
)
into
a
from
t1
;
select
a
;
end
|
delete
from
t1
|
insert
into
t1
(
data
)
values
(
1
),
(
2
),
(
3
),
(
4
),
(
6
)
|
call
bug8937
()
|
drop
procedure
bug8937
|
delete
from
t1
|
# Add bugs above this line. Use existing tables t1 and t2 when
# practical, or create table t3, t3 etc temporarily (and drop them).
delimiter
;
|
drop
table
t1
,
t2
;
sql/item_sum.h
View file @
45b5e513
...
@@ -356,6 +356,8 @@ class Item_sum_avg :public Item_sum_sum
...
@@ -356,6 +356,8 @@ class Item_sum_avg :public Item_sum_sum
void
clear
();
void
clear
();
bool
add
();
bool
add
();
double
val_real
();
double
val_real
();
// In SPs we might force the "wrong" type with select into a declare variable
longlong
val_int
()
{
return
(
longlong
)
val_real
();
}
my_decimal
*
val_decimal
(
my_decimal
*
);
my_decimal
*
val_decimal
(
my_decimal
*
);
String
*
val_str
(
String
*
str
);
String
*
val_str
(
String
*
str
);
void
reset_field
();
void
reset_field
();
...
...
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