1drop database if exists mysqltest;
2drop table if exists t1, t2, t3, t4;
3drop procedure if exists sp1;
4drop procedure if exists sp2;
5drop procedure if exists sp3;
6drop procedure if exists sp4;
7drop function if exists f1;
8drop function if exists f2;
9drop function if exists f3;
10create database mysqltest;
11use mysqltest//
12create procedure sp1 ()
13begin
14drop table if exists t1;
15select 1 as "my-col";
16end;
17//
18select database();
19database()
20mysqltest
21call sp1();
22my-col
231
24Warnings:
25Note	1051	Unknown table 'mysqltest.t1'
26select database();
27database()
28mysqltest
29use test;
30select database();
31database()
32test
33call mysqltest.sp1();
34my-col
351
36Warnings:
37Note	1051	Unknown table 'mysqltest.t1'
38select database();
39database()
40test
41drop procedure mysqltest.sp1;
42drop database mysqltest;
43create procedure sp1()
44begin
45create table t1 (a int);
46insert into t1 values (10);
47end//
48create procedure sp2()
49begin
50create table t2(a int);
51insert into t2 values(1);
52call sp1();
53end//
54create function f1() returns int
55begin
56return (select max(a) from t1);
57end//
58create procedure sp3()
59begin
60call sp1();
61select 'func', f1();
62end//
63call sp1();
64select 't1',a from t1;
65t1	a
66t1	10
67drop table t1;
68call sp2();
69select 't1',a from t1;
70t1	a
71t1	10
72select 't2',a from t2;
73t2	a
74t2	1
75drop table t1, t2;
76call sp3();
77func	f1()
78func	10
79select 't1',a from t1;
80t1	a
81t1	10
82drop table t1;
83drop procedure sp1;
84drop procedure sp2;
85drop procedure sp3;
86drop function f1;
87create procedure sp1()
88begin
89create temporary table t2(a int);
90insert into t2 select * from t1;
91end//
92create procedure sp2()
93begin
94create temporary table t1 (a int);
95insert into t1 values(1);
96call sp1();
97select 't1', a from t1;
98select 't2', a from t2;
99drop table t1;
100drop table t2;
101end//
102call sp2();
103t1	a
104t1	1
105t2	a
106t2	1
107drop procedure sp1;
108drop procedure sp2;
109create table t1 (a int);
110insert into t1 values(1),(2);
111create table t2 as select * from t1;
112create table t3 as select * from t1;
113create table t4 as select * from t1;
114create procedure sp1(a int)
115begin
116select a;
117end //
118create function f1() returns int
119begin
120return (select max(a) from t1);
121end //
122CALL sp1(f1());
123a
1242
125create procedure sp2(a int)
126begin
127select * from t3;
128select a;
129end //
130create procedure sp3()
131begin
132select * from t1;
133call sp2(5);
134end //
135create procedure sp4()
136begin
137select * from t2;
138call sp3();
139end //
140call sp4();
141a
1421
1432
144a
1451
1462
147a
1481
1492
150a
1515
152drop procedure sp1;
153drop procedure sp2;
154drop procedure sp3;
155drop procedure sp4;
156drop function f1;
157drop view if exists v1;
158create function f1(ab int) returns int
159begin
160declare i int;
161set i= (select max(a) from t1 where a < ab) ;
162return i;
163end //
164create function f2(ab int) returns int
165begin
166declare i int;
167set i= (select max(a) from t2 where a < ab) ;
168return i;
169end //
170create view v1 as
171select t3.a as x, t4.a as y, f2(3) as z
172from t3, t4 where t3.a = t4.a //
173create procedure sp1()
174begin
175declare a int;
176set a= (select f1(4) + count(*) A from t1, v1);
177end //
178create function f3() returns int
179begin
180call sp1();
181return 1;
182end //
183call sp1() //
184select f3() //
185f3()
1861
187select f3() //
188f3()
1891
190call sp1() //
191drop procedure sp1//
192drop function f3//
193create procedure sp1()
194begin
195declare x int;
196declare c cursor for select f1(3) + count(*) from v1;
197open c;
198fetch c into x;
199end;//
200create function f3() returns int
201begin
202call sp1();
203return 1;
204end //
205call sp1() //
206call sp1() //
207select f3() //
208f3()
2091
210call sp1() //
211drop view v1;
212drop table t1,t2,t3,t4;
213drop function f1;
214drop function f2;
215drop function f3;
216drop procedure sp1;
217drop table if exists t1;
218drop view if exists v1, v2, v3;
219drop function if exists bug15683;
220create table t1 (f1 bigint, f2 varchar(20), f3 bigint);
221insert into t1 set f1 = 1, f2 = 'schoenenbourg', f3 = 1;
222create view v1 as select 1 from t1 union all select 1;
223create view v2 as select 1 from v1;
224create view v3 as select 1 as f1 from v2;
225create function bug15683() returns bigint
226begin
227return (select count(*) from v3);
228end|
229prepare stmt from "select bug15683()";
230execute stmt;
231bug15683()
2322
233execute stmt;
234bug15683()
2352
236deallocate prepare stmt;
237drop table t1;
238drop view v1, v2, v3;
239drop function bug15683;
240drop table if exists t1, t2, t3;
241drop function if exists bug19634;
242create table t1 (id int, data int);
243create table t2 (id int);
244create table t3 (data int);
245create function bug19634() returns int return (select count(*) from t3);
246prepare stmt from "delete t1 from t1, t2 where t1.id = t2.id and bug19634()";
247execute stmt;
248execute stmt;
249deallocate prepare stmt;
250create trigger t1_bi before delete on t1 for each row insert into t3 values (old.data);
251prepare stmt from "delete t1 from t1, t2 where t1.id = t2.id";
252execute stmt;
253execute stmt;
254deallocate prepare stmt;
255drop function bug19634;
256drop table t1, t2, t3;
257drop table if exists bug_27907_logs;
258drop table if exists bug_27907_t1;
259create table bug_27907_logs (a int);
260create table bug_27907_t1 (a int);
261create trigger bug_27907_t1_ai after insert on bug_27907_t1
262for each row
263begin
264insert into bug_27907_logs (a) values (1);
265end|
266drop table bug_27907_logs;
267insert into bug_27907_t1(a) values (1);
268ERROR 42S02: Table 'test.bug_27907_logs' doesn't exist
269drop table bug_27907_t1;
270
271Bug#22427 create table if not exists + stored function results in
272inconsistent behavior
273
274Add a test case, the bug itself was fixed by the patch for
275Bug#20662
276
277drop table if exists t1;
278drop function if exists f_bug22427;
279create table t1 (i int);
280insert into t1 values (1);
281create function f_bug22427() returns int return (select max(i) from t1);
282select f_bug22427();
283f_bug22427()
2841
285create table if not exists t1 select f_bug22427() as i;
286Warnings:
287Note	1050	Table 't1' already exists
288create table t1 select f_bug22427() as i;
289ERROR 42S01: Table 't1' already exists
290drop table t1;
291drop function f_bug22427;
292#
293# Bug #29929 LOCK TABLES does not pre-lock tables used in triggers of the locked tables
294#
295DROP table IF EXISTS t1,t2;
296CREATE TABLE t1 (c1 INT);
297CREATE TABLE t2 (c2 INT);
298INSERT INTO t1 VALUES (1);
299INSERT INTO t2 VALUES (2);
300CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
301BEGIN
302UPDATE t2 SET c2= c2 + 1;
303END//
304# Take a table lock on t1.
305# This should pre-lock t2 through the trigger.
306LOCK TABLE t1 WRITE;
307INSERT INTO t1 VALUES (3);
308UNLOCK TABLES;
309LOCK TABLE t1 READ;
310INSERT INTO t2 values(4);
311ERROR HY000: Table 't2' was not locked with LOCK TABLES
312UNLOCK TABLES;
313SELECT * FROM t1;
314c1
3151
3163
317SELECT * FROM t2;
318c2
3193
320DROP TRIGGER t1_ai;
321DROP TABLE t1, t2;
322End of 5.0 tests
323#
324# Bug#21142859: FUNCTION UPDATING A VIEW FAILS TO FIND TABLE THAT ACTUALLY EXISTS
325#
326CREATE TABLE t1 SELECT 1 AS fld1, 'A' AS fld2;
327CREATE TABLE t2 (fld3 INT, fld4 CHAR(1));
328CREATE VIEW v1 AS SELECT * FROM t1;
329CREATE TRIGGER t1_au AFTER UPDATE ON t1
330FOR EACH ROW INSERT INTO t2 VALUES (new.fld1, new.fld2);
331CREATE FUNCTION f1() RETURNS INT
332BEGIN
333UPDATE v1 SET fld2='B' WHERE fld1=1;
334RETURN row_count();
335END !
336# Without the patch, an error was getting reported.
337SELECT f1();
338f1()
3391
340DROP FUNCTION f1;
341DROP VIEW v1;
342DROP TABLE t1,t2;
343#
344# Bug #16672723 "CAN'T FIND TEMPORARY TABLE".
345#
346CREATE FUNCTION f1() RETURNS INT RETURN 1;
347CREATE TEMPORARY TABLE tmp1(a INT);
348PREPARE stmt1 FROM "CREATE TEMPORARY TABLE tmp2 AS SELECT b FROM (SELECT f1() AS b FROM tmp1) AS t";
349# The below statement failed before the fix.
350EXECUTE stmt1;
351DROP TEMPORARY TABLES tmp1, tmp2;
352DEALLOCATE PREPARE stmt1;
353DROP FUNCTION f1;
354