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
52cd3e31
Commit
52cd3e31
authored
Feb 19, 2003
by
pem@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed SELECT INTO OUTFILE/DUMPFILE and stored procedures, and extended and
reorganized the sp.test file.
parent
02211a60
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
442 additions
and
242 deletions
+442
-242
mysql-test/r/sp.result
mysql-test/r/sp.result
+216
-138
mysql-test/t/sp.test
mysql-test/t/sp.test
+208
-104
sql/sql_class.cc
sql/sql_class.cc
+18
-0
No files found.
mysql-test/r/sp.result
View file @
52cd3e31
...
@@ -6,13 +6,31 @@ data int not null
...
@@ -6,13 +6,31 @@ data int not null
);
);
create procedure foo42()
create procedure foo42()
insert into test.t1 values ("foo", 42);
insert into test.t1 values ("foo", 42);
call foo42();
select * from t1;
id data
foo 42
delete from t1;
drop procedure foo42;
create procedure bar(x char(16), y int)
create procedure bar(x char(16), y int)
insert into test.t1 values (x, y);
insert into test.t1 values (x, y);
call bar("bar", 666);
select * from t1;
id data
bar 666
delete from t1;
create procedure two(x1 char(16), x2 char(16), y int)
create procedure two(x1 char(16), x2 char(16), y int)
begin
begin
insert into test.t1 values (x1, y);
insert into test.t1 values (x1, y);
insert into test.t1 values (x2, y);
insert into test.t1 values (x2, y);
end;
end;
call two("one", "two", 3);
select * from t1;
id data
one 3
two 3
delete from t1;
drop procedure two;
create procedure locset(x char(16), y int)
create procedure locset(x char(16), y int)
begin
begin
declare z1, z2 int;
declare z1, z2 int;
...
@@ -20,12 +38,27 @@ set z1 = y;
...
@@ -20,12 +38,27 @@ set z1 = y;
set z2 = z1+2;
set z2 = z1+2;
insert into test.t1 values (x, z2);
insert into test.t1 values (x, z2);
end;
end;
call locset("locset", 19);
select * from t1;
id data
locset 21
delete from t1;
drop procedure locset;
create procedure mixset(x char(16), y int)
create procedure mixset(x char(16), y int)
begin
begin
declare z int;
declare z int;
set @z = y, z = 666, max_join_size = 100;
set @z = y, z = 666, max_join_size = 100;
insert into test.t1 values (x, z);
insert into test.t1 values (x, z);
end;
end;
call mixset("mixset", 19);
show variables like 'max_join_size';
Variable_name Value
max_join_size 100
select id,data,@z from t1;
id data @z
mixset 666 19
delete from t1;
drop procedure mixset;
create procedure zip(x char(16), y int)
create procedure zip(x char(16), y int)
begin
begin
declare z int;
declare z int;
...
@@ -37,6 +70,14 @@ begin
...
@@ -37,6 +70,14 @@ begin
declare z int;
declare z int;
set z = x+1, y = z;
set z = x+1, y = z;
end;
end;
call zip("zip", 99);
select * from t1;
id data
zip 100
delete from t1;
drop procedure zip;
drop procedure zap;
drop procedure bar;
create procedure iotest(x1 char(16), x2 char(16), y int)
create procedure iotest(x1 char(16), x2 char(16), y int)
begin
begin
call inc2(x2, y);
call inc2(x2, y);
...
@@ -49,6 +90,15 @@ insert into test.t1 values (x, y);
...
@@ -49,6 +90,15 @@ insert into test.t1 values (x, y);
end;
end;
create procedure inc(inout io int)
create procedure inc(inout io int)
set io = io + 1;
set io = io + 1;
call iotest("io1", "io2", 1);
select * from t1;
id data
io2 2
io1 1
delete from t1;
drop procedure iotest;
drop procedure inc2;
drop procedure inc;
create procedure cbv1()
create procedure cbv1()
begin
begin
declare y int;
declare y int;
...
@@ -61,21 +111,53 @@ begin
...
@@ -61,21 +111,53 @@ begin
set y2 = 4711;
set y2 = 4711;
insert into test.t1 values ("cbv2", y1);
insert into test.t1 values ("cbv2", y1);
end;
end;
call cbv1();
select * from t1;
id data
cbv2 4
cbv1 4711
delete from t1;
drop procedure cbv1;
drop procedure cbv2;
create procedure a0(x int)
create procedure a0(x int)
while x do
while x do
set x = x-1;
set x = x-1;
insert into test.t1 values ("a0", x);
insert into test.t1 values ("a0", x);
end while;
end while;
call a0(3);
select * from t1;
id data
a0 2
a0 1
a0 0
delete from t1;
drop procedure a0;
create procedure a(x int)
create procedure a(x int)
while x > 0 do
while x > 0 do
set x = x-1;
set x = x-1;
insert into test.t1 values ("a", x);
insert into test.t1 values ("a", x);
end while;
end while;
call a(3);
select * from t1;
id data
a 2
a 1
a 0
delete from t1;
drop procedure a;
create procedure b(x int)
create procedure b(x int)
repeat
repeat
insert into test.t1 values (repeat("b",3), x);
insert into test.t1 values (repeat("b",3), x);
set x = x-1;
set x = x-1;
until x = 0 end repeat;
until x = 0 end repeat;
call b(3);
select * from t1;
id data
bbb 3
bbb 2
bbb 1
delete from t1;
drop procedure b;
create procedure b2(x int)
create procedure b2(x int)
repeat(select 1 into outfile 'b2');
repeat(select 1 into outfile 'b2');
insert into test.t1 values (repeat("b2",3), x);
insert into test.t1 values (repeat("b2",3), x);
...
@@ -96,6 +178,14 @@ set x = x-1;
...
@@ -96,6 +178,14 @@ set x = x-1;
iterate hmm;
iterate hmm;
insert into test.t1 values ("x", x);
insert into test.t1 values ("x", x);
end while hmm;
end while hmm;
call c(3);
select * from t1;
id data
c 3
c 2
c 1
delete from t1;
drop procedure c;
create procedure d(x int)
create procedure d(x int)
hmm: while x > 0 do
hmm: while x > 0 do
insert into test.t1 values ("d", x);
insert into test.t1 values ("d", x);
...
@@ -103,6 +193,12 @@ set x = x-1;
...
@@ -103,6 +193,12 @@ set x = x-1;
leave hmm;
leave hmm;
insert into test.t1 values ("x", x);
insert into test.t1 values ("x", x);
end while hmm;
end while hmm;
call d(3);
select * from t1;
id data
d 3
delete from t1;
drop procedure d;
create procedure e(x int)
create procedure e(x int)
foo: loop
foo: loop
if x = 0 then
if x = 0 then
...
@@ -111,6 +207,14 @@ end if;
...
@@ -111,6 +207,14 @@ end if;
insert into test.t1 values ("e", x);
insert into test.t1 values ("e", x);
set x = x-1;
set x = x-1;
end loop foo;
end loop foo;
call e(3);
select * from t1;
id data
e 3
e 2
e 1
delete from t1;
drop procedure e;
create procedure f(x int)
create procedure f(x int)
if x < 0 then
if x < 0 then
insert into test.t1 values ("f", 0);
insert into test.t1 values ("f", 0);
...
@@ -119,122 +223,6 @@ insert into test.t1 values ("f", 1);
...
@@ -119,122 +223,6 @@ insert into test.t1 values ("f", 1);
else
else
insert into test.t1 values ("f", 2);
insert into test.t1 values ("f", 2);
end if;
end if;
create procedure g(x int)
case
when x < 0 then
insert into test.t1 values ("g", 0);
when x = 0 then
insert into test.t1 values ("g", 1);
else
insert into test.t1 values ("g", 2);
end case;
create procedure h(x int)
case x
when 0 then
insert into test.t1 values ("h0", x);
when 1 then
insert into test.t1 values ("h1", x);
else
insert into test.t1 values ("h?", x);
end case;
create procedure into_test(x char(16), y int)
begin
insert into test.t1 values (x, y);
select id,data into x,y from test.t1 limit 1;
insert into test.t1 values (concat(x, "2"), y+2);
end;
create procedure into_test2(x char(16), y int)
begin
insert into test.t1 values (x, y);
select id,data into x,@z from test.t1 limit 1;
insert into test.t1 values (concat(x, "2"), y+2);
end;
call foo42();
select * from t1;
id data
foo 42
delete from t1;
call bar("bar", 666);
select * from t1;
id data
bar 666
delete from t1;
call two("one", "two", 3);
select * from t1;
id data
one 3
two 3
delete from t1;
call locset("locset", 19);
select * from t1;
id data
locset 21
delete from t1;
call mixset("mixset", 19);
show variables like 'max_join_size';
Variable_name Value
max_join_size 100
select id,data,@z from t1;
id data @z
mixset 666 19
delete from t1;
call zip("zip", 99);
select * from t1;
id data
zip 100
delete from t1;
call iotest("io1", "io2", 1);
select * from t1;
id data
io2 2
io1 1
delete from t1;
call cbv1();
select * from t1;
id data
cbv2 4
cbv1 4711
delete from t1;
call a0(3);
select * from t1;
id data
a0 2
a0 1
a0 0
delete from t1;
call a(3);
select * from t1;
id data
a 2
a 1
a 0
delete from t1;
call b(3);
select * from t1;
id data
bbb 3
bbb 2
bbb 1
delete from t1;
call c(3);
select * from t1;
id data
c 3
c 2
c 1
delete from t1;
call d(3);
select * from t1;
id data
d 3
delete from t1;
call e(3);
select * from t1;
id data
e 3
e 2
e 1
delete from t1;
call f(-2);
call f(-2);
call f(0);
call f(0);
call f(4);
call f(4);
...
@@ -244,6 +232,16 @@ f 0
...
@@ -244,6 +232,16 @@ f 0
f 1
f 1
f 2
f 2
delete from t1;
delete from t1;
drop procedure f;
create procedure g(x int)
case
when x < 0 then
insert into test.t1 values ("g", 0);
when x = 0 then
insert into test.t1 values ("g", 1);
else
insert into test.t1 values ("g", 2);
end case;
call g(-42);
call g(-42);
call g(0);
call g(0);
call g(1);
call g(1);
...
@@ -253,6 +251,16 @@ g 0
...
@@ -253,6 +251,16 @@ g 0
g 1
g 1
g 2
g 2
delete from t1;
delete from t1;
drop procedure g;
create procedure h(x int)
case x
when 0 then
insert into test.t1 values ("h0", x);
when 1 then
insert into test.t1 values ("h1", x);
else
insert into test.t1 values ("h?", x);
end case;
call h(0);
call h(0);
call h(1);
call h(1);
call h(17);
call h(17);
...
@@ -262,39 +270,109 @@ h0 0
...
@@ -262,39 +270,109 @@ h0 0
h1 1
h1 1
h? 17
h? 17
delete from t1;
delete from t1;
drop procedure h;
drop table if exists fac;
create table fac (n int unsigned not null primary key, f bigint unsigned);
create procedure ifac(n int unsigned)
begin
declare i int unsigned;
set i = 1;
if n > 20 then
set n = 20;
end if;
while i <= n do
begin
declare f bigint unsigned;
set f = 0; # Temp. fix, this should not be needed in the future.
call fac(i, f);
insert into test.fac values (i, f);
set i = i + 1;
end;
end while;
end;
create procedure fac(n int unsigned, out f bigint unsigned)
begin
set f = 1;
while n > 1 do
set f = f * n;
set n = n - 1;
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;
drop procedure ifac;
drop procedure fac;
create procedure into_test(x char(16), y int)
begin
insert into test.t1 values (x, y);
select id,data into x,y from test.t1 limit 1;
insert into test.t1 values (concat(x, "2"), y+2);
end;
call into_test("into", 100);
call into_test("into", 100);
select * from t1;
select * from t1;
id data
id data
into 100
into 100
into2 102
into2 102
delete from t1;
delete from t1;
drop procedure into_test;
create procedure into_test2(x char(16), y int)
begin
insert into test.t1 values (x, y);
select id,data into x,@z from test.t1 limit 1;
insert into test.t1 values (concat(x, "2"), y+2);
end;
call into_test2("into", 100);
call into_test2("into", 100);
select id,data,@z from t1;
select id,data,@z from t1;
id data @z
id data @z
into 100 100
into 100 100
into2 102 100
into2 102 100
delete from t1;
delete from t1;
drop procedure foo42;
drop procedure bar;
drop procedure two;
drop procedure locset;
drop procedure mixset;
drop procedure zip;
drop procedure zap;
drop procedure iotest;
drop procedure inc2;
drop procedure inc;
drop procedure cbv1;
drop procedure cbv2;
drop procedure a0;
drop procedure a;
drop procedure b;
drop procedure c;
drop procedure d;
drop procedure e;
drop procedure f;
drop procedure g;
drop procedure h;
drop procedure into_test;
drop procedure into_test2;
drop procedure into_test2;
create procedure into_outfile(x char(16), y int)
begin
insert into test.t1 values (x, y);
select * into outfile "/tmp/spout" from test.t1;
insert into test.t1 values (concat(x, "2"), y+2);
end;
call into_outfile("ofile", 1);
delete from t1;
drop procedure into_outfile;
create procedure into_dumpfile(x char(16), y int)
begin
insert into test.t1 values (x, y);
select * into dumpfile "/tmp/spdump" from test.t1 limit 1;
insert into test.t1 values (concat(x, "2"), y+2);
end;
call into_dumpfile("dfile", 1);
delete from t1;
drop procedure into_dumpfile;
create procedure create_select(x char(16), y int)
begin
insert into test.t1 values (x, y);
create table test.t2 select * from test.t1;
insert into test.t2 values (concat(x, "2"), y+2);
end;
drop procedure create_select;
drop table t1;
drop table t1;
mysql-test/t/sp.test
View file @
52cd3e31
...
@@ -14,16 +14,28 @@ create table t1 (
...
@@ -14,16 +14,28 @@ create table t1 (
data
int
not
null
data
int
not
null
);
);
# Single statement, no params.
# Single statement, no params.
create
procedure
foo42
()
create
procedure
foo42
()
insert
into
test
.
t1
values
(
"foo"
,
42
);
insert
into
test
.
t1
values
(
"foo"
,
42
);
call
foo42
();
select
*
from
t1
;
delete
from
t1
;
drop
procedure
foo42
;
# Single statement, two IN params.
# Single statement, two IN params.
create
procedure
bar
(
x
char
(
16
),
y
int
)
create
procedure
bar
(
x
char
(
16
),
y
int
)
insert
into
test
.
t1
values
(
x
,
y
);
insert
into
test
.
t1
values
(
x
,
y
);
# Now for multiple statements...
call
bar
(
"bar"
,
666
);
select
*
from
t1
;
delete
from
t1
;
# Don't drop procedure yet...
# Now for multiple statements...
delimiter
|
;
delimiter
|
;
# Two statements.
# Two statements.
...
@@ -33,6 +45,12 @@ begin
...
@@ -33,6 +45,12 @@ begin
insert
into
test
.
t1
values
(
x2
,
y
);
insert
into
test
.
t1
values
(
x2
,
y
);
end
|
end
|
call
two
(
"one"
,
"two"
,
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
two
|
# Simple test of local variables and SET.
# Simple test of local variables and SET.
create
procedure
locset
(
x
char
(
16
),
y
int
)
create
procedure
locset
(
x
char
(
16
),
y
int
)
begin
begin
...
@@ -42,6 +60,12 @@ begin
...
@@ -42,6 +60,12 @@ begin
insert
into
test
.
t1
values
(
x
,
z2
);
insert
into
test
.
t1
values
(
x
,
z2
);
end
|
end
|
call
locset
(
"locset"
,
19
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
locset
|
# The peculiar (non-standard) mixture of variables types in SET.
# The peculiar (non-standard) mixture of variables types in SET.
create
procedure
mixset
(
x
char
(
16
),
y
int
)
create
procedure
mixset
(
x
char
(
16
),
y
int
)
begin
begin
...
@@ -51,6 +75,13 @@ begin
...
@@ -51,6 +75,13 @@ begin
insert
into
test
.
t1
values
(
x
,
z
);
insert
into
test
.
t1
values
(
x
,
z
);
end
|
end
|
call
mixset
(
"mixset"
,
19
)
|
show
variables
like
'max_join_size'
|
select
id
,
data
,
@
z
from
t1
|
delete
from
t1
|
drop
procedure
mixset
|
# Multiple CALL statements, one with OUT parameter.
# Multiple CALL statements, one with OUT parameter.
create
procedure
zip
(
x
char
(
16
),
y
int
)
create
procedure
zip
(
x
char
(
16
),
y
int
)
begin
begin
...
@@ -66,6 +97,13 @@ begin
...
@@ -66,6 +97,13 @@ begin
set
z
=
x
+
1
,
y
=
z
;
set
z
=
x
+
1
,
y
=
z
;
end
|
end
|
call
zip
(
"zip"
,
99
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
zip
|
drop
procedure
zap
|
drop
procedure
bar
|
# INOUT test
# INOUT test
create
procedure
iotest
(
x1
char
(
16
),
x2
char
(
16
),
y
int
)
create
procedure
iotest
(
x1
char
(
16
),
x2
char
(
16
),
y
int
)
...
@@ -83,6 +121,13 @@ end|
...
@@ -83,6 +121,13 @@ end|
create
procedure
inc
(
inout
io
int
)
create
procedure
inc
(
inout
io
int
)
set
io
=
io
+
1
|
set
io
=
io
+
1
|
call
iotest
(
"io1"
,
"io2"
,
1
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
iotest
|
drop
procedure
inc2
|
drop
procedure
inc
|
# Call-by-value test
# Call-by-value test
# The expected result is:
# The expected result is:
...
@@ -103,8 +148,14 @@ begin
...
@@ -103,8 +148,14 @@ begin
insert
into
test
.
t1
values
(
"cbv2"
,
y1
);
insert
into
test
.
t1
values
(
"cbv2"
,
y1
);
end
|
end
|
call
cbv1
()
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
cbv1
|
drop
procedure
cbv2
|
#
Minimal tests of the flow control constru
ts
#
Basic tests of the flow control construc
ts
# Just test on 'x'...
# Just test on 'x'...
create
procedure
a0
(
x
int
)
create
procedure
a0
(
x
int
)
...
@@ -113,6 +164,12 @@ while x do
...
@@ -113,6 +164,12 @@ while x do
insert
into
test
.
t1
values
(
"a0"
,
x
);
insert
into
test
.
t1
values
(
"a0"
,
x
);
end
while
|
end
while
|
call
a0
(
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
a0
|
# The same, but with a more traditional test.
# The same, but with a more traditional test.
create
procedure
a
(
x
int
)
create
procedure
a
(
x
int
)
while
x
>
0
do
while
x
>
0
do
...
@@ -120,6 +177,12 @@ while x > 0 do
...
@@ -120,6 +177,12 @@ while x > 0 do
insert
into
test
.
t1
values
(
"a"
,
x
);
insert
into
test
.
t1
values
(
"a"
,
x
);
end
while
|
end
while
|
call
a
(
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
a
|
# REPEAT
# REPEAT
create
procedure
b
(
x
int
)
create
procedure
b
(
x
int
)
repeat
repeat
...
@@ -127,16 +190,24 @@ repeat
...
@@ -127,16 +190,24 @@ repeat
set
x
=
x
-
1
;
set
x
=
x
-
1
;
until
x
=
0
end
repeat
|
until
x
=
0
end
repeat
|
call
b
(
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
b
|
# Check that repeat isn't parsed the wrong way
# Check that repeat isn't parsed the wrong way
create
procedure
b2
(
x
int
)
create
procedure
b2
(
x
int
)
repeat
(
select
1
into
outfile
'b2'
);
repeat
(
select
1
into
outfile
'b2'
);
insert
into
test
.
t1
values
(
repeat
(
"b2"
,
3
),
x
);
insert
into
test
.
t1
values
(
repeat
(
"b2"
,
3
),
x
);
set
x
=
x
-
1
;
set
x
=
x
-
1
;
until
x
=
0
end
repeat
|
until
x
=
0
end
repeat
|
# We don't actually want to call it.
# We don't actually want to call it.
drop
procedure
b2
|
drop
procedure
b2
|
# Btw, this should generate an error
# Btw, this should generate an error (for now; this might change in the future)
--
error
1259
--
error
1259
create
procedure
b3
(
x
int
)
create
procedure
b3
(
x
int
)
repeat
repeat
...
@@ -145,6 +216,7 @@ repeat
...
@@ -145,6 +216,7 @@ repeat
set
x
=
x
-
1
;
set
x
=
x
-
1
;
until
x
=
0
end
repeat
|
until
x
=
0
end
repeat
|
# Labelled WHILE with ITERATE (pointless really)
# Labelled WHILE with ITERATE (pointless really)
create
procedure
c
(
x
int
)
create
procedure
c
(
x
int
)
hmm
:
while
x
>
0
do
hmm
:
while
x
>
0
do
...
@@ -154,6 +226,12 @@ hmm: while x > 0 do
...
@@ -154,6 +226,12 @@ hmm: while x > 0 do
insert
into
test
.
t1
values
(
"x"
,
x
);
insert
into
test
.
t1
values
(
"x"
,
x
);
end
while
hmm
|
end
while
hmm
|
call
c
(
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
c
|
# Labelled WHILE with LEAVE
# Labelled WHILE with LEAVE
create
procedure
d
(
x
int
)
create
procedure
d
(
x
int
)
hmm
:
while
x
>
0
do
hmm
:
while
x
>
0
do
...
@@ -163,6 +241,12 @@ hmm: while x > 0 do
...
@@ -163,6 +241,12 @@ hmm: while x > 0 do
insert
into
test
.
t1
values
(
"x"
,
x
);
insert
into
test
.
t1
values
(
"x"
,
x
);
end
while
hmm
|
end
while
hmm
|
call
d
(
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
d
|
# LOOP, with simple IF statement
# LOOP, with simple IF statement
create
procedure
e
(
x
int
)
create
procedure
e
(
x
int
)
foo
:
loop
foo
:
loop
...
@@ -173,6 +257,12 @@ foo: loop
...
@@ -173,6 +257,12 @@ foo: loop
set
x
=
x
-
1
;
set
x
=
x
-
1
;
end
loop
foo
|
end
loop
foo
|
call
e
(
3
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
e
|
# A full IF statement
# A full IF statement
create
procedure
f
(
x
int
)
create
procedure
f
(
x
int
)
if
x
<
0
then
if
x
<
0
then
...
@@ -183,6 +273,14 @@ else
...
@@ -183,6 +273,14 @@ else
insert
into
test
.
t1
values
(
"f"
,
2
);
insert
into
test
.
t1
values
(
"f"
,
2
);
end
if
|
end
if
|
call
f
(
-
2
)
|
call
f
(
0
)
|
call
f
(
4
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
f
|
# This form of CASE is really just syntactic sugar for IF-ELSEIF-...
# This form of CASE is really just syntactic sugar for IF-ELSEIF-...
create
procedure
g
(
x
int
)
create
procedure
g
(
x
int
)
case
case
...
@@ -194,6 +292,14 @@ else
...
@@ -194,6 +292,14 @@ else
insert
into
test
.
t1
values
(
"g"
,
2
);
insert
into
test
.
t1
values
(
"g"
,
2
);
end
case
|
end
case
|
call
g
(
-
42
)
|
call
g
(
0
)
|
call
g
(
1
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
g
|
# The "simple CASE"
# The "simple CASE"
create
procedure
h
(
x
int
)
create
procedure
h
(
x
int
)
case
x
case
x
...
@@ -205,6 +311,56 @@ else
...
@@ -205,6 +311,56 @@ else
insert
into
test
.
t1
values
(
"h?"
,
x
);
insert
into
test
.
t1
values
(
"h?"
,
x
);
end
case
|
end
case
|
call
h
(
0
)
|
call
h
(
1
)
|
call
h
(
17
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
h
|
# A "real" procedure example
--
disable_warnings
drop
table
if
exists
fac
|
--
enable_warnings
create
table
fac
(
n
int
unsigned
not
null
primary
key
,
f
bigint
unsigned
)
|
create
procedure
ifac
(
n
int
unsigned
)
begin
declare
i
int
unsigned
;
set
i
=
1
;
if
n
>
20
then
set
n
=
20
;
end
if
;
while
i
<=
n
do
begin
declare
f
bigint
unsigned
;
set
f
=
0
;
# Temp. fix, this should not be needed in the future.
call
fac
(
i
,
f
);
insert
into
test
.
fac
values
(
i
,
f
);
set
i
=
i
+
1
;
end
;
end
while
;
end
|
create
procedure
fac
(
n
int
unsigned
,
out
f
bigint
unsigned
)
begin
set
f
=
1
;
while
n
>
1
do
set
f
=
f
*
n
;
set
n
=
n
-
1
;
end
while
;
end
|
call
ifac
(
20
)
|
select
*
from
fac
|
drop
table
fac
|
drop
procedure
ifac
|
drop
procedure
fac
|
# SELECT INTO local variables
create
procedure
into_test
(
x
char
(
16
),
y
int
)
create
procedure
into_test
(
x
char
(
16
),
y
int
)
begin
begin
insert
into
test
.
t1
values
(
x
,
y
);
insert
into
test
.
t1
values
(
x
,
y
);
...
@@ -212,7 +368,13 @@ begin
...
@@ -212,7 +368,13 @@ begin
insert
into
test
.
t1
values
(
concat
(
x
,
"2"
),
y
+
2
);
insert
into
test
.
t1
values
(
concat
(
x
,
"2"
),
y
+
2
);
end
|
end
|
# Test INTO with a mix of local and global variables
call
into_test
(
"into"
,
100
)
|
select
*
from
t1
|
delete
from
t1
|
drop
procedure
into_test
|
# SELECT INTO with a mix of local and global variables
create
procedure
into_test2
(
x
char
(
16
),
y
int
)
create
procedure
into_test2
(
x
char
(
16
),
y
int
)
begin
begin
insert
into
test
.
t1
values
(
x
,
y
);
insert
into
test
.
t1
values
(
x
,
y
);
...
@@ -220,114 +382,56 @@ begin
...
@@ -220,114 +382,56 @@ begin
insert
into
test
.
t1
values
(
concat
(
x
,
"2"
),
y
+
2
);
insert
into
test
.
t1
values
(
concat
(
x
,
"2"
),
y
+
2
);
end
|
end
|
delimiter
;
|
call
into_test2
(
"into"
,
100
)
|
select
id
,
data
,
@
z
from
t1
|
delete
from
t1
|
drop
procedure
into_test2
|
# Now, the CALL tests...
call
foo42
();
select
*
from
t1
;
delete
from
t1
;
call
bar
(
"bar"
,
666
);
select
*
from
t1
;
delete
from
t1
;
call
two
(
"one"
,
"two"
,
3
);
select
*
from
t1
;
delete
from
t1
;
call
locset
(
"locset"
,
19
);
select
*
from
t1
;
delete
from
t1
;
call
mixset
(
"mixset"
,
19
);
show
variables
like
'max_join_size'
;
select
id
,
data
,
@
z
from
t1
;
delete
from
t1
;
call
zip
(
"zip"
,
99
);
select
*
from
t1
;
delete
from
t1
;
call
iotest
(
"io1"
,
"io2"
,
1
);
select
*
from
t1
;
delete
from
t1
;
call
cbv1
();
select
*
from
t1
;
delete
from
t1
;
call
a0
(
3
);
select
*
from
t1
;
delete
from
t1
;
call
a
(
3
);
select
*
from
t1
;
delete
from
t1
;
call
b
(
3
);
select
*
from
t1
;
delete
from
t1
;
call
c
(
3
);
select
*
from
t1
;
delete
from
t1
;
call
d
(
3
);
# These two (and the two procedures above) caused an assert() to fail in
select
*
from
t1
;
# sql_base.cc:lock_tables() at some point.
delete
from
t1
;
call
e
(
3
);
create
procedure
into_outfile
(
x
char
(
16
),
y
int
)
select
*
from
t1
;
begin
delete
from
t1
;
insert
into
test
.
t1
values
(
x
,
y
);
select
*
into
outfile
"/tmp/spout"
from
test
.
t1
;
insert
into
test
.
t1
values
(
concat
(
x
,
"2"
),
y
+
2
);
end
|
call
f
(
-
2
);
system
rm
-
f
/
tmp
/
spout
|
call
f
(
0
);
call
into_outfile
(
"ofile"
,
1
)
|
call
f
(
4
);
system
rm
-
f
/
tmp
/
spout
|
select
*
from
t1
;
delete
from
t1
|
d
elete
from
t1
;
d
rop
procedure
into_outfile
|
call
g
(
-
42
);
create
procedure
into_dumpfile
(
x
char
(
16
),
y
int
)
call
g
(
0
);
begin
call
g
(
1
);
insert
into
test
.
t1
values
(
x
,
y
);
select
*
from
t1
;
select
*
into
dumpfile
"/tmp/spdump"
from
test
.
t1
limit
1
;
delete
from
t1
;
insert
into
test
.
t1
values
(
concat
(
x
,
"2"
),
y
+
2
);
end
|
call
h
(
0
);
system
rm
-
f
/
tmp
/
spdump
|
call
h
(
1
);
call
into_dumpfile
(
"dfile"
,
1
)
|
call
h
(
17
);
system
rm
-
f
/
tmp
/
spdump
|
select
*
from
t1
;
delete
from
t1
|
d
elete
from
t1
;
d
rop
procedure
into_dumpfile
|
call
into_test
(
"into"
,
100
);
select
*
from
t1
;
delete
from
t1
;
call
into_test2
(
"into"
,
100
);
create
procedure
create_select
(
x
char
(
16
),
y
int
)
select
id
,
data
,
@
z
from
t1
;
begin
delete
from
t1
;
insert
into
test
.
t1
values
(
x
,
y
);
create
table
test
.
t2
select
*
from
test
.
t1
;
insert
into
test
.
t2
values
(
concat
(
x
,
"2"
),
y
+
2
);
end
|
drop
procedure
foo42
;
# This doesn't work right now. It suffers from the same problem as the ones
drop
procedure
bar
;
# above, but the fix caused create.test to hang. :-(
drop
procedure
two
;
#call create_select("cs", 90)|
drop
procedure
locset
;
#select * from t1, t2|
drop
procedure
mixset
;
#delete from t1|
drop
procedure
zip
;
#drop table t2|
drop
procedure
zap
;
drop
procedure
create_select
|
drop
procedure
iotest
;
drop
procedure
inc2
;
drop
procedure
inc
;
drop
procedure
cbv1
;
drop
procedure
cbv2
;
drop
procedure
a0
;
drop
procedure
a
;
drop
procedure
b
;
drop
procedure
c
;
drop
procedure
d
;
drop
procedure
e
;
drop
procedure
f
;
drop
procedure
g
;
drop
procedure
h
;
drop
procedure
into_test
;
drop
procedure
into_test2
;
delimiter
;
|
drop
table
t1
;
drop
table
t1
;
sql/sql_class.cc
View file @
52cd3e31
...
@@ -801,6 +801,15 @@ void select_export::send_error(uint errcode, const char *err)
...
@@ -801,6 +801,15 @@ void select_export::send_error(uint errcode, const char *err)
bool
select_export
::
send_eof
()
bool
select_export
::
send_eof
()
{
{
/* This mimics select_send::send_eof(), which unlocks this way.
* It appears to be necessary, since tables aren't unlock after
* selects otherwise.
*/
if
(
thd
->
lock
)
{
mysql_unlock_tables
(
thd
,
thd
->
lock
);
thd
->
lock
=
0
;
}
int
error
=
test
(
end_io_cache
(
&
cache
));
int
error
=
test
(
end_io_cache
(
&
cache
));
if
(
my_close
(
file
,
MYF
(
MY_WME
)))
if
(
my_close
(
file
,
MYF
(
MY_WME
)))
error
=
1
;
error
=
1
;
...
@@ -911,6 +920,15 @@ void select_dump::send_error(uint errcode,const char *err)
...
@@ -911,6 +920,15 @@ void select_dump::send_error(uint errcode,const char *err)
bool
select_dump
::
send_eof
()
bool
select_dump
::
send_eof
()
{
{
/* This mimics select_send::send_eof(), which unlocks this way.
* It appears to be necessary, since tables aren't unlock after
* selects otherwise.
*/
if
(
thd
->
lock
)
{
mysql_unlock_tables
(
thd
,
thd
->
lock
);
thd
->
lock
=
0
;
}
int
error
=
test
(
end_io_cache
(
&
cache
));
int
error
=
test
(
end_io_cache
(
&
cache
));
if
(
my_close
(
file
,
MYF
(
MY_WME
)))
if
(
my_close
(
file
,
MYF
(
MY_WME
)))
error
=
1
;
error
=
1
;
...
...
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