mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / ps.test
blob88bfe1dd2be360bca1865c66fa8bb909e3add50b
1 -- source include/not_embedded.inc
2 -- source include/have_log_bin.inc
4 # SQL Syntax for Prepared Statements test
6 --disable_warnings
7 drop table if exists t1,t2,t3,t4;
9 # Avoid wrong warnings if mysql_client_test fails
10 drop database if exists client_test_db;
11 --enable_warnings
13 create table t1
15   a int primary key,
16   b char(10)
18 insert into t1 values (1,'one');
19 insert into t1 values (2,'two');
20 insert into t1 values (3,'three');
21 insert into t1 values (4,'four');
23 # basic functionality
24 set @a=2;
25 prepare stmt1 from 'select * from t1 where a <= ?';
26 execute stmt1 using @a;
27 set @a=3;
28 execute stmt1 using @a;
30 # non-existant statement
31 --error 1243
32 deallocate prepare no_such_statement;
34 --error 1210
35 execute stmt1;
37 # Nesting ps commands is not allowed: 
38 --error ER_UNSUPPORTED_PS 
39 prepare stmt2 from 'prepare nested_stmt from "select 1"';
41 --error ER_UNSUPPORTED_PS 
42 prepare stmt2 from 'execute stmt1';
44 --error ER_UNSUPPORTED_PS 
45 prepare stmt2 from 'deallocate prepare z';
47 # PS insert 
48 prepare stmt3 from 'insert into t1 values (?,?)';
49 set @arg1=5, @arg2='five';
50 execute stmt3 using @arg1, @arg2;
51 select * from t1 where a>3;
53 # PS update 
54 prepare stmt4 from 'update t1 set a=? where b=?';
55 set @arg1=55, @arg2='five';
56 execute stmt4 using @arg1, @arg2;
57 select * from t1 where a>3;
59 # PS create/delete
60 prepare stmt4 from 'create table t2 (a int)';
61 execute stmt4;
62 prepare stmt4 from 'drop table t2';
63 execute stmt4;
65 # Do something that will cause error
66 --error 1051
67 execute stmt4;
69 # placeholders in result field names.
70 prepare stmt5 from 'select ? + a from t1';
71 set @a=1;
72 execute stmt5 using @a;
74 execute stmt5 using @no_such_var;
76 set @nullvar=1;
77 set @nullvar=NULL;
78 execute stmt5 using @nullvar;
80 set @nullvar2=NULL;
81 execute stmt5 using @nullvar2;
83 # Check that multiple SQL statements are disabled inside PREPARE
84 --error 1064
85 prepare stmt6 from 'select 1; select2';
87 --error 1064
88 prepare stmt6 from 'insert into t1 values (5,"five"); select2';
90 # This shouldn't parse
91 --error 1064
92 explain prepare stmt6 from 'insert into t1 values (5,"five"); select2';
94 create table t2
96   a int
99 insert into t2 values (0);
101 # parameter is NULL
102 set @arg00=NULL ;
103 prepare stmt1 from 'select 1 FROM t2 where a=?' ;
104 execute stmt1 using @arg00 ;
106 # prepare using variables:
107 --error 1064
108 prepare stmt1 from @nosuchvar;
110 set @ivar= 1234;
111 --error 1064
112 prepare stmt1 from @ivar;
114 set @fvar= 123.4567;
115 --error 1064
116 prepare stmt1 from @fvar;
118 drop table t1,t2;
119 deallocate prepare stmt3;
120 deallocate prepare stmt4;
121 deallocate prepare stmt5;
124 # Bug #4105: Server crash on attempt to prepare a statement with character
125 # set introducer
127 PREPARE stmt1 FROM "select _utf8 'A' collate utf8_bin = ?";
128 set @var='A';
129 EXECUTE stmt1 USING @var;
130 DEALLOCATE PREPARE stmt1;
133 # BUG#3486:  FOUND_ROWS() fails inside stored procedure [and prepared statement]
135 create table t1 (id int);
136 prepare stmt1 from "select FOUND_ROWS()";
137 select SQL_CALC_FOUND_ROWS * from t1;
138 # Expect 0
139 execute stmt1;
140 insert into t1 values (1);
141 select SQL_CALC_FOUND_ROWS * from t1;
142 # Expect 1
143 execute stmt1;
144 # Expect 0
145 execute stmt1;
146 deallocate prepare stmt1;
147 drop table t1;
150 # prepared EXPLAIN
152 create table t1 
154   c1  tinyint, c2  smallint, c3  mediumint, c4  int,
155   c5  integer, c6  bigint, c7  float, c8  double,
156   c9  double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4),
157   c13 date, c14 datetime, c15 timestamp, c16 time,
158   c17 year, c18 bit, c19 bool, c20 char,
159   c21 char(10), c22 varchar(30), c23 tinyblob, c24 tinytext,
160   c25 blob, c26 text, c27 mediumblob, c28 mediumtext,
161   c29 longblob, c30 longtext, c31 enum('one', 'two', 'three'),
162   c32 set('monday', 'tuesday', 'wednesday')
163 ) engine = MYISAM ;
164 create table t2 like t1;
166 set @stmt= ' explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25 ' ;
167 prepare stmt1 from @stmt ;
168 execute stmt1 ;
169 execute stmt1 ;
170 explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25;
171 deallocate prepare stmt1;
172 drop tables t1,t2;
175 # parameters from variables (for field creation)
177 set @arg00=1;
178 prepare stmt1 from ' create table t1 (m int) as select 1 as m ' ;
179 execute stmt1 ;
180 select m from t1;
181 drop table t1;
182 prepare stmt1 from ' create table t1 (m int) as select ? as m ' ;
183 execute stmt1 using @arg00;
184 select m from t1;
185 deallocate prepare stmt1;
186 drop table t1;
189 # eq() for parameters
191 create table t1 (id int(10) unsigned NOT NULL default '0',
192                  name varchar(64) NOT NULL default '',
193                  PRIMARY KEY  (id), UNIQUE KEY `name` (`name`));
194 insert into t1 values (1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5'),(6,'6'),(7,'7');
195 prepare stmt1 from 'select name from t1 where id=? or id=?';
196 set @id1=1,@id2=6;
197 execute stmt1 using @id1, @id2;
198 select name from t1 where id=1 or id=6;
199 deallocate prepare stmt1;
200 drop table t1;
203 # SHOW TABLE STATUS test
205 create table t1 ( a int primary key, b varchar(30)) engine = MYISAM ;
206 prepare stmt1 from ' show table status from test like ''t1%'' ';
207 --replace_column 8 4294967295 12 # 13 # 14 #
208 execute stmt1;
209 --replace_column 8 4294967295 12 # 13 # 14 #
210 show table status from test like 't1%' ;
211 deallocate prepare stmt1 ;
212 drop table t1;
215 # Bug#4912 "mysqld crashs in case a statement is executed a second time":
216 # negation elimination should work once and not break prepared statements
219 create table t1(a varchar(2), b varchar(3));
220 prepare stmt1 from "select a, b from t1 where (not (a='aa' and b < 'zzz'))";
221 execute stmt1;
222 execute stmt1;
223 deallocate prepare stmt1;
224 drop table t1;
227 # Bug#5034 "prepared "select 1 into @arg15", second execute crashes
228 # server".
229 # Check that descendands of select_result can be reused in prepared 
230 # statements or are correctly created and deleted on each execute
233 --let $outfile=$MYSQLTEST_VARDIR/tmp/f1.txt
234 --error 0,1
235 --remove_file $outfile
237 prepare stmt1 from "select 1 into @var";
238 execute stmt1;
239 execute stmt1;
240 prepare stmt1 from "create table t1 select 1 as i";
241 execute stmt1;
242 drop table t1;
243 execute stmt1;
244 prepare stmt1 from "insert into t1 select i from t1";
245 execute stmt1;
246 execute stmt1;
247 --replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR>
248 eval prepare stmt1 from "select * from t1 into outfile '$outfile'";
249 execute stmt1;
250 deallocate prepare stmt1;
251 drop table t1;
253 --remove_file $outfile
256 # BUG#5242 "Prepared statement names are case sensitive"
258 prepare stmt1 from 'select 1';
259 prepare STMT1 from 'select 2';
260 execute sTmT1;
261 deallocate prepare StMt1;
263 --error 1243
264 deallocate prepare Stmt1;
266 # also check that statement names are in right charset.
267 set names utf8;
268 prepare `ü` from 'select 1234';
269 execute `ü` ;
270 set names latin1;
271 execute `ü`;
272 deallocate prepare `ü`;
273 set names default;
277 # BUG#4368 "select * from t1 where a like ?" crashes server if a is in utf8
278 # and ? is in latin1
279 # Check that Item converting latin1 to utf8 (for LIKE function) is created
280 # in memory of prepared statement.
283 create table t1 (a varchar(10)) charset=utf8;
284 insert into t1 (a) values ('yahoo');
285 set character_set_connection=latin1;
286 prepare stmt from 'select a from t1 where a like ?';
287 set @var='google';
288 execute stmt using @var;
289 execute stmt using @var;
290 deallocate prepare stmt;
291 drop table t1;
294 # BUG#5510 "inserting Null in AutoIncrement primary key Column Fails" 
295 # (prepared statements) 
296 # The cause: misuse of internal MySQL 'Field' API.
299 create table t1 (a bigint(20) not null primary key auto_increment);
300 insert into t1 (a) values (null);
301 select * from t1;
302 prepare stmt from "insert into t1 (a) values (?)";
303 set @var=null;
304 execute stmt using @var;
305 select * from t1;
306 drop table t1;
308 # check the same for timestamps
310 create table t1 (a timestamp not null);
311 prepare stmt from "insert into t1 (a) values (?)";
312 execute stmt using @var;
313 --disable_result_log
314 select * from t1;
315 --enable_result_log
316 deallocate prepare stmt;
317 drop table t1;
320 # BUG#5688 "Upgraded 4.1.5 Server seg faults" # (prepared statements)
321 # The test case speaks for itself.
322 # Just another place where we used wrong memory root for Items created
323 # during statement prepare.
325 prepare stmt from "select 'abc' like convert('abc' using utf8)";
326 execute stmt;
327 execute stmt;
328 deallocate prepare stmt;
331 # BUG#5748 "Prepared statement with BETWEEN and bigint values crashes
332 # mysqld". Just another place where an item tree modification must be 
333 # rolled back.
335 create table t1 ( a bigint );
336 prepare stmt from 'select a from t1 where a between ? and ?';
337 set @a=1;
338 execute stmt using @a, @a;
339 execute stmt using @a, @a;
340 execute stmt using @a, @a;
341 drop table t1;
342 deallocate prepare stmt;
345 # Bug #5987 subselect in bool function crashes server (prepared statements):
346 # don't overwrite transformed subselects with old arguments of a bool
347 # function.
349 create table t1 (a int);
350 prepare stmt from "select * from t1 where 1 > (1 in (SELECT * FROM t1))";
351 execute stmt;
352 execute stmt;
353 execute stmt;
354 drop table t1;
355 deallocate prepare stmt;
358 # Test case for Bug#6042 "constants propogation works only once (prepared
359 # statements): check that the query plan changes whenever we change
360 # placeholder value.
362 create table t1 (a int, b int);
363 insert into t1 (a, b) values (1,1), (1,2), (2,1), (2,2);
364 prepare stmt from
365 "explain select * from t1 where t1.a=2 and t1.a=t1.b and t1.b > 1 + ?";
366 set @v=5;
367 --replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 -
368 execute stmt using @v;
369 set @v=0;
370 --replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 -
371 execute stmt using @v;
372 set @v=5;
373 --replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 -
374 execute stmt using @v;
375 drop table t1;
376 deallocate prepare stmt;
379 # A test case for Bug#5985 prepare stmt from "select rand(?)" crashes
380 # server. Check that Item_func_rand is prepared-statements friendly.
382 create table t1 (a int);
383 insert into t1 (a) values (1), (2), (3), (4);
384 set @precision=10000000000;
385 --replace_column 1 - 3 -
386 select rand(), 
387        cast(rand(10)*@precision as unsigned integer) from t1;
388 prepare stmt from
389 "select rand(), 
390         cast(rand(10)*@precision as unsigned integer),
391         cast(rand(?)*@precision as unsigned integer) from t1";
392 set @var=1;
393 --replace_column 1 - 3 -
394 execute stmt using @var;
395 set @var=2;
396 --replace_column 1 -
397 execute stmt using @var;
398 set @var=3;
399 --replace_column 1 -
400 execute stmt using @var;
401 drop table t1;
402 deallocate prepare stmt;
405 # A test case for Bug#6050 "EXECUTE stmt reports ambiguous fieldnames with
406 # identical tables from different schemata"
407 # Check that field name resolving in prepared statements works OK.
409 create database mysqltest1;
410 create table t1 (a int);
411 create table mysqltest1.t1 (a int);
412 select * from t1, mysqltest1.t1;
413 prepare stmt from "select * from t1, mysqltest1.t1";
414 execute stmt;
415 execute stmt;
416 execute stmt;
417 drop table t1;
418 drop table mysqltest1.t1;
419 drop database mysqltest1;
420 deallocate prepare stmt; 
421 select '1.1' as a, '1.2' as a UNION SELECT '2.1', '2.2';
422 prepare stmt from
423 "select '1.1' as a, '1.2' as a UNION SELECT '2.1', '2.2'";
424 execute stmt;
425 execute stmt;
426 execute stmt;
427 deallocate prepare stmt;
430 # Test CREATE TABLE ... SELECT (Bug #6094)
432 create table t1 (a int); 
433 insert into t1 values (1),(2),(3);
434 create table t2 select * from t1;
435 prepare stmt FROM 'create table t2 select * from t1';
436 drop table t2;
437 execute stmt;
438 drop table t2;
439 execute stmt;
440 --error 1050
441 execute stmt;
442 drop table t2;
443 execute stmt;
444 drop table t1,t2;
445 deallocate prepare stmt;
448 # Bug#6088 "FOUND_ROWS returns wrong values for prepared statements when
449 # LIMIT is used"
451 create table t1 (a int);
452 insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
453 prepare stmt from "select sql_calc_found_rows * from t1 limit 2";
454 execute stmt;
455 select found_rows();
456 execute stmt;
457 select found_rows();
458 execute stmt;
459 select found_rows();
460 deallocate prepare stmt;
461 drop table t1;
464 # Bug#6047 "permission problem when executing mysql_stmt_execute with derived
465 # table"
468 CREATE TABLE t1 (N int, M tinyint); 
469 INSERT INTO t1 VALUES (1,0),(1,0),(2,0),(2,0),(3,0);
470 PREPARE stmt FROM 'UPDATE t1 AS P1 INNER JOIN (SELECT N FROM t1 GROUP BY N HAVING COUNT(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2';
471 EXECUTE stmt;
472 DEALLOCATE PREPARE stmt;
473 DROP TABLE t1;
476 # Bug#6297 "prepared statement, wrong handling of <parameter> IS NULL"
477 # Test that placeholders work with IS NULL/IS NOT NULL clauses. 
479 prepare stmt from "select ? is null, ? is not null, ?";
480 select @no_such_var is null, @no_such_var is not null, @no_such_var;
481 execute stmt using @no_such_var, @no_such_var, @no_such_var;
482 set @var='abc';
483 select @var is null, @var is not null, @var;
484 execute stmt using @var, @var, @var;
485 set @var=null;
486 select @var is null, @var is not null, @var;
487 execute stmt using @var, @var, @var;
490 # Bug#6873 "PS, having with subquery, crash during execute"
491 # check that if we modify having subtree, we update JOIN->having pointer
493 create table t1 (pnum char(3));
494 create table t2 (pnum char(3));
495 prepare stmt from "select pnum from t2 having pnum in (select 'p1' from t1)";
496 execute stmt;
497 execute stmt;
498 execute stmt;
499 deallocate prepare stmt;
500 drop table t1, t2;
504 # Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating
505 #            tables"
506 # Check that multi-delete tables are also cleaned up before re-execution.
508 --disable_warnings
509 drop table if exists t1;
510 create temporary table if not exists t1 (a1 int);
511 --enable_warnings
512 # exact delete syntax is essential
513 prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1";
514 drop temporary table t1;
515 create temporary table if not exists t1 (a1 int);
516 # the server crashed on  the next statement without the fix
517 execute stmt;
518 drop temporary table t1;
519 create temporary table if not exists t1 (a1 int);
520 # the problem was in memory corruption: repeat the test just in case
521 execute stmt;
522 drop temporary table t1;
523 create temporary table if not exists t1 (a1 int);
524 execute stmt;
525 drop temporary table t1;
526 deallocate prepare stmt;
528 # Bug#6102 "Server crash with prepared statement and blank after
529 # function name"
530 # ensure that stored functions are cached when preparing a statement
531 # before we open tables
533 create table t1 (a varchar(20)); 
534 insert into t1 values ('foo'); 
535 prepare stmt FROM 'SELECT char_length (a) FROM t1'; 
536 -- error ER_SP_DOES_NOT_EXIST
537 prepare stmt2 FROM 'SELECT not_a_function (a) FROM t1'; 
538 drop table t1;
541 # Bug #6089: FOUND_ROWS returns wrong values when no table/view is used 
544 prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0";
545 execute stmt;
546 SELECT FOUND_ROWS();
547 execute stmt;                                                                   
548 SELECT FOUND_ROWS();                                                            
549 deallocate prepare stmt;
552 # Bug#9096 "select doesn't return all matched records if prepared statements
553 # is used"
554 # The bug was is bad co-operation of the optimizer's algorithm which determines
555 # which keys can be used to execute a query, constants propagation
556 # part of the optimizer and parameter markers used by prepared statements.
558 drop table if exists t1;
559 create table t1 (c1 int(11) not null, c2 int(11) not null,
560              primary key  (c1,c2), key c2 (c2), key c1 (c1));
562 insert into t1 values (200887, 860);
563 insert into t1 values (200887, 200887);
565 select * from t1 where (c1=200887 and c2=200887) or c2=860;
567 prepare stmt from
568 "select * from t1 where (c1=200887 and c2=200887) or c2=860";
569 execute stmt;
570 prepare stmt from
571 "select * from t1 where (c1=200887 and c2=?) or c2=?";
572 set @a=200887, @b=860;
573 # this query did not return all matching rows
574 execute stmt using @a, @b;
575 deallocate prepare stmt;
577 drop table t1;
580 # Bug#9777 - another occurrence of the problem stated in Bug#9096:
581 # we can not compare basic constants by their names, because a placeholder
582 # is a basic constant while his name is always '?'
585 create table t1 (
586    id bigint(20) not null auto_increment,
587    code varchar(20) character set utf8 collate utf8_bin not null default '',
588    company_name varchar(250) character set utf8 collate utf8_bin default null,
589    setup_mode tinyint(4) default null,
590    start_date datetime default null,
591    primary key  (id), unique key code (code)
594 create table t2 (
595    id bigint(20) not null auto_increment,
596    email varchar(250) character set utf8 collate utf8_bin default null,
597    name varchar(250) character set utf8 collate utf8_bin default null,
598    t1_id bigint(20) default null,
599    password varchar(250) character set utf8 collate utf8_bin default null,
600    primary_contact tinyint(4) not null default '0',
601    email_opt_in tinyint(4) not null default '1',
602    primary key  (id), unique key email (email), key t1_id (t1_id),
603    constraint t2_fk1 foreign key (t1_id) references t1 (id)
606 insert into t1 values
607 (1, 'demo', 'demo s', 0, current_date()),
608 (2, 'code2', 'name 2', 0, current_date()),
609 (3, 'code3', 'name 3', 0, current_date());
611 insert into t2 values
612 (2, 'email1', 'name1', 3, 'password1', 0, 0),
613 (3, 'email2', 'name1', 1, 'password2', 1, 0),
614 (5, 'email3', 'name3', 2, 'password3', 0, 0);
616 prepare stmt from 'select t2.id from t2, t1 where (t1.id=? and t2.t1_id=t1.id)';
617 set @a=1;
618 execute stmt using @a;
620 select t2.id from t2, t1 where (t1.id=1 and t2.t1_id=t1.id);
622 deallocate prepare stmt;
623 drop table t1, t2;
626 # Bug#11060 "Server crashes on calling stored procedure with INSERT SELECT
627 # UNION SELECT" aka "Server crashes on re-execution of prepared INSERT ...
628 # SELECT with UNION".
630 create table t1 (id int);
631 prepare stmt from "insert into t1 (id) select id from t1 union select id from t1";
632 execute stmt;
633 execute stmt;
634 deallocate prepare stmt;
635 drop table t1;
637 # Bug#11458 "Prepared statement with subselects return random data":
638 # drop PARAM_TABLE_BIT from the list of tables used by a subquery
640 create table t1 (
641   id int(11) unsigned not null primary key auto_increment,
642   partner_id varchar(35) not null,
643   t1_status_id int(10) unsigned
646 insert into t1 values ("1", "partner1", "10"), ("2", "partner2", "10"),
647                       ("3", "partner3", "10"), ("4", "partner4", "10");
649 create table t2 (
650   id int(11) unsigned not null default '0',
651   t1_line_id int(11) unsigned not null default '0',
652   article_id varchar(20),
653   sequence int(11) not null default '0',
654   primary key  (id,t1_line_id)
657 insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"),
658                       ("2", "2", "sup", "2"), ("2", "3", "sup", "3"),
659                       ("2", "4", "imp", "4"), ("3", "1", "sup", "0"),
660                       ("4", "1", "sup", "0");
662 create table t3 (
663   id int(11) not null default '0',
664   preceeding_id int(11) not null default '0',
665   primary key  (id,preceeding_id)
668 create table t4 (
669   user_id varchar(50) not null,
670   article_id varchar(20) not null,
671   primary key  (user_id,article_id)
674 insert into t4 values("nicke", "imp");
676 prepare stmt from
677 'select distinct t1.partner_id
678 from t1 left join t3 on t1.id = t3.id
679      left join t1 pp on pp.id = t3.preceeding_id
680 where
681   exists (
682     select *
683     from t2 as pl_inner
684     where pl_inner.id = t1.id
685     and pl_inner.sequence <= (
686       select min(sequence) from t2 pl_seqnr
687       where pl_seqnr.id = t1.id
688     )
689     and exists (
690       select * from t4
691       where t4.article_id = pl_inner.article_id
692       and t4.user_id = ?
693     )
694   )
695   and t1.id = ?
696 group by t1.id
697 having count(pp.id) = 0';
698 set @user_id = 'nicke';
699 set @id = '2';
700 execute stmt using @user_id, @id;
701 execute stmt using @user_id, @id;
702 deallocate prepare stmt;
703 drop table t1, t2, t3, t4;
705 # Bug#9379: make sure that Item::collation is reset when one sets
706 # a parameter marker from a string variable.
708 prepare stmt from 'select ?=?';
709 set @a='CHRISTINE           ';
710 set @b='CHRISTINE';
711 execute stmt using @a, @b;
712 execute stmt using @a, @b;
713 set @a=1, @b=2;
714 execute stmt using @a, @b;
715 set @a='CHRISTINE           ';
716 set @b='CHRISTINE';
717 execute stmt using @a, @b;
718 deallocate prepare stmt;
720 # Bug#11299 "prepared statement makes wrong SQL syntax in binlog which stops
721 # replication": check that errouneous queries with placeholders are not
722 # allowed
724 create table t1 (a int);
725 --error 1064
726 prepare stmt from "select ??";
727 --error 1064
728 prepare stmt from "select ?FROM t1";
729 --error 1064
730 prepare stmt from "select FROM t1 WHERE?=1";
731 --error 1064
732 prepare stmt from "update t1 set a=a+?WHERE 1";
733 --disable_ps_protocol
734 --error 1064
735 select ?;
736 --error 1064
737 select ??;
738 --error 1064
739 select ? from t1;
740 --enable_ps_protocol
741 drop table t1;
743 # Bug#9359 "Prepared statements take snapshot of system vars at PREPARE
744 # time"
746 prepare stmt from "select @@time_zone";
747 execute stmt;
748 set @@time_zone:='Japan';
749 execute stmt;
750 prepare stmt from "select @@tx_isolation";
751 execute stmt;
752 set transaction isolation level read committed;
753 execute stmt;
754 set transaction isolation level serializable;
755 execute stmt;
756 set @@tx_isolation=default;
757 execute stmt;
758 deallocate prepare stmt;
761 # Bug#14410 "Crash in Enum or Set type in CREATE TABLE and PS/SP"
763 # Part I. Make sure the typelib for ENUM is created in the statement memory
764 # root.
765 prepare stmt from "create temporary table t1 (letter enum('','a','b','c')
766 not null)";
767 execute stmt;
768 drop table t1;
769 execute stmt;
770 drop table t1;
771 execute stmt;
772 drop table t1;
773 # Part II. Make sure that when the default value is converted to UTF-8,
774 # the new item is # created in the statement memory root.
775 set names latin1;
776 prepare stmt from "create table t1 (a enum('test') default 'test')
777  character set utf8";
778 execute stmt;
779 drop table t1;
780 execute stmt;
781 drop table t1;
782 execute stmt;
783 drop table t1;
784 # Cleanup
785 set names default;
786 deallocate prepare stmt;
789 # A test case for Bug#12734 "prepared statement may return incorrect result
790 # set for a select SQL request": test that canDoTurboBM is reset for each
791 # execute of a prepared statement.
793 create table t1 (
794   word_id mediumint(8) unsigned not null default '0',
795   formatted varchar(20) not null default ''
798 insert into t1 values
799   (80,'pendant'), (475,'pretendants'), (989,'tendances'),
800   (1019,'cependant'),(1022,'abondance'),(1205,'independants'),
801   (13,'lessiver'),(25,'lambiner'),(46,'situer'),(71,'terminer'),
802   (82,'decrocher');
804 select count(*) from t1 where formatted like '%NDAN%';
805 select count(*) from t1 where formatted like '%ER';
806 prepare stmt from "select count(*) from t1 where formatted like ?";
807 set @like="%NDAN%";
808 execute stmt using @like;
809 set @like="%ER";
810 execute stmt using @like;
811 set @like="%NDAN%";
812 execute stmt using @like;
813 set @like="%ER";
814 execute stmt using @like;
815 deallocate prepare stmt;
816 drop table t1;
819 # Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is
820 # recreated with PS/SP"
823 prepare stmt from 'create table t1 (a varchar(10) character set utf8)';
824 execute stmt;
825 --disable_warnings
826 insert into t1 (a) values (repeat('a', 20));
827 --enable_warnings
828 select length(a) from t1;
829 drop table t1;
830 execute stmt;
831 --disable_warnings
832 insert into t1 (a) values (repeat('a', 20));
833 --enable_warnings
834 # Check that the data is truncated to the same length
835 select length(a) from t1;
836 drop table t1;
837 deallocate prepare stmt;
840 # Bug#16248 "WHERE (col1,col2) IN ((?,?)) gives wrong results":
841 # check that ROW implementation is reexecution-friendly.
843 create table t1 (col1 integer, col2 integer);
844 insert into t1 values(100,100),(101,101),(102,102),(103,103);
845 prepare stmt from 'select col1, col2 from t1 where (col1, col2) in ((?,?))';
846 set @a=100, @b=100;
847 execute stmt using @a,@b;
848 set @a=101, @b=101;
849 execute stmt using @a,@b;
850 set @a=102, @b=102;
851 execute stmt using @a,@b;
852 set @a=102, @b=103;
853 execute stmt using @a,@b;
854 deallocate prepare stmt;
855 drop table t1;
858 # Bug#16365 Prepared Statements: DoS with too many open statements
859 # Check that the limit @@max_prpeared_stmt_count works.
861 # This is also the test for bug#23159 prepared_stmt_count should be
862 # status variable.
864 # Save the old value
865 set @old_max_prepared_stmt_count= @@max_prepared_stmt_count;
867 # Disable prepared statement protocol: in this test we set
868 # @@max_prepared_stmt_count to 0 or 1 and would like to test the limit
869 # manually.
871 --disable_ps_protocol
873 # A. Check that the new variables are present in SHOW VARIABLES and
874 # SHOW STATUS lists.
876 show variables like 'max_prepared_stmt_count';
877 show status like 'prepared_stmt_count';
879 # B. Check that the new system variable is selectable.
881 select @@max_prepared_stmt_count;
883 # C. Check that max_prepared_stmt_count is settable (global only).
885 set global max_prepared_stmt_count=-1;
886 select @@max_prepared_stmt_count;
887 set global max_prepared_stmt_count=10000000000000000;
888 select @@max_prepared_stmt_count;
889 set global max_prepared_stmt_count=default;
890 select @@max_prepared_stmt_count;
891 --error ER_GLOBAL_VARIABLE
892 set @@max_prepared_stmt_count=1;
893 --error ER_GLOBAL_VARIABLE
894 set max_prepared_stmt_count=1;
895 --error ER_GLOBAL_VARIABLE
896 set local max_prepared_stmt_count=1;
897 # set to a reasonable limit works
898 set global max_prepared_stmt_count=1;
899 select @@max_prepared_stmt_count;
901 # D. Check that the variables actually work.
903 set global max_prepared_stmt_count=0;
904 select @@max_prepared_stmt_count;
905 show status like 'prepared_stmt_count';
906 --error ER_MAX_PREPARED_STMT_COUNT_REACHED
907 prepare stmt from "select 1";
908 show status like 'prepared_stmt_count';
909 set global max_prepared_stmt_count=1;
910 prepare stmt from "select 1";
911 show status like 'prepared_stmt_count';
912 --error ER_MAX_PREPARED_STMT_COUNT_REACHED
913 prepare stmt1 from "select 1";
914 show status like 'prepared_stmt_count';
915 deallocate prepare stmt;
916 show status like 'prepared_stmt_count';
918 # E. Check that we can prepare a statement with the same name 
919 # successfully, without hitting the limit.
921 prepare stmt from "select 1";
922 show status like 'prepared_stmt_count';
923 prepare stmt from "select 2";
924 show status like 'prepared_stmt_count';
926 # F. We can set the max below the current count. In this case no new 
927 # statements should be allowed to prepare.
929 show status like 'prepared_stmt_count';
930 select @@max_prepared_stmt_count;
931 set global max_prepared_stmt_count=0;
932 --error ER_MAX_PREPARED_STMT_COUNT_REACHED
933 prepare stmt from "select 1";
934 # Result: the old statement is deallocated, the new is not created.
935 --error ER_UNKNOWN_STMT_HANDLER
936 execute stmt;
937 show status like 'prepared_stmt_count';
938 --error ER_MAX_PREPARED_STMT_COUNT_REACHED
939 prepare stmt from "select 1";
940 show status like 'prepared_stmt_count';
942 # G. Show that the variables are up to date even after a connection with all
943 # statements in it was terminated.
945 set global max_prepared_stmt_count=3;
946 select @@max_prepared_stmt_count;
947 show status like 'prepared_stmt_count';
948 prepare stmt from "select 1";
950 connect (con1,localhost,root,,);
952 # Switch to connection con1
953 connection con1;
954 let $con1_id=`SELECT CONNECTION_ID()`;
956 prepare stmt from "select 2";
957 prepare stmt1 from "select 3";
958 --error ER_MAX_PREPARED_STMT_COUNT_REACHED
959 prepare stmt2 from "select 4";
960 connection default;
961 --error ER_MAX_PREPARED_STMT_COUNT_REACHED 
962 prepare stmt2 from "select 4";
963 select @@max_prepared_stmt_count;
964 show status like 'prepared_stmt_count';
966 # Disconnect connection con1 and switch to default connection
967 disconnect con1;
968 connection default;
970 # Wait for the connection con1 to die
971 let $wait_condition=SELECT COUNT(*)=0 FROM information_schema.processlist WHERE id=$con1_id;
972 --source include/wait_condition.inc
974 deallocate prepare stmt;
976 select @@max_prepared_stmt_count;
977 show status like 'prepared_stmt_count';
979 # Restore the old value.
981 set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
982 --enable_ps_protocol
986 # Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating
987 #            tables"
988 # Check that multi-delete tables are also cleaned up before re-execution.
990 --disable_warnings
991 drop table if exists t1;
992 create temporary table if not exists t1 (a1 int);
993 --enable_warnings
994 # exact delete syntax is essential
995 prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1";
996 drop temporary table t1;
997 create temporary table if not exists t1 (a1 int);
998 # the server crashed on  the next statement without the fix
999 execute stmt;
1000 drop temporary table t1;
1001 create temporary table if not exists t1 (a1 int);
1002 # the problem was in memory corruption: repeat the test just in case
1003 execute stmt;
1004 drop temporary table t1;
1005 create temporary table if not exists t1 (a1 int);
1006 execute stmt;
1007 drop temporary table t1;
1008 deallocate prepare stmt;
1012 # BUG#22085: Crash on the execution of a prepared statement that
1013 #            uses an IN subquery with aggregate functions in HAVING 
1016 CREATE TABLE t1(
1017   ID int(10) unsigned NOT NULL auto_increment,
1018   Member_ID varchar(15) NOT NULL default '',
1019   Action varchar(12) NOT NULL,
1020   Action_Date datetime NOT NULL,
1021   Track varchar(15) default NULL,
1022   User varchar(12) default NULL,
1023   Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update
1024     CURRENT_TIMESTAMP,
1025   PRIMARY KEY (ID),
1026   KEY Action (Action),
1027   KEY Action_Date (Action_Date)
1030 INSERT INTO t1(Member_ID, Action, Action_Date, Track) VALUES
1031   ('111111', 'Disenrolled', '2006-03-01', 'CAD' ),
1032   ('111111', 'Enrolled', '2006-03-01', 'CAD' ),
1033   ('111111', 'Disenrolled', '2006-07-03', 'CAD' ),
1034   ('222222', 'Enrolled', '2006-03-07', 'CAD' ),
1035   ('222222', 'Enrolled', '2006-03-07', 'CHF' ),
1036   ('222222', 'Disenrolled', '2006-08-02', 'CHF' ),
1037   ('333333', 'Enrolled', '2006-03-01', 'CAD' ),
1038   ('333333', 'Disenrolled', '2006-03-01', 'CAD' ),
1039   ('444444', 'Enrolled', '2006-03-01', 'CAD' ),
1040   ('555555', 'Disenrolled', '2006-03-01', 'CAD' ),
1041   ('555555', 'Enrolled', '2006-07-21', 'CAD' ),
1042   ('555555', 'Disenrolled', '2006-03-01', 'CHF' ),
1043   ('666666', 'Enrolled', '2006-02-09', 'CAD' ),
1044   ('666666', 'Enrolled', '2006-05-12', 'CHF' ),
1045   ('666666', 'Disenrolled', '2006-06-01', 'CAD' );
1047 PREPARE STMT FROM
1048 "SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t1
1049   WHERE Member_ID=? AND Action='Enrolled' AND
1050         (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t1
1051                                   WHERE Member_ID=?
1052                                     GROUP BY Track 
1053                                       HAVING Track>='CAD' AND
1054                                              MAX(Action_Date)>'2006-03-01')";
1055 SET @id='111111';
1056 EXECUTE STMT USING @id,@id;
1057 SET @id='222222';
1058 EXECUTE STMT USING @id,@id;
1060 DEALLOCATE PREPARE STMT;
1061 DROP TABLE t1;
1064 # BUG#21354: (COUNT(*) = 1) not working in SELECT inside prepared
1065 # statement 
1067 --disable_warnings
1068 DROP TABLE IF EXISTS t1;
1069 --enable_warnings
1071 CREATE TABLE t1 (i INT, INDEX(i));
1072 INSERT INTO t1 VALUES (1);
1074 PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?";
1075 SET @a = 0;
1076 EXECUTE stmt USING @a;
1077 SET @a = 1;
1078 EXECUTE stmt USING @a;
1079 SET @a = 0;
1080 EXECUTE stmt USING @a;
1082 PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?";
1083 SET @a = 0;
1084 EXECUTE stmt USING @a;
1085 SET @a = 1;
1086 EXECUTE stmt USING @a;
1087 SET @a = 0;
1088 EXECUTE stmt USING @a;
1090 PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?";
1091 SET @a = 0;
1092 EXECUTE stmt USING @a;
1093 SET @a = 1;
1094 EXECUTE stmt USING @a;
1095 SET @a = 0;
1096 EXECUTE stmt USING @a;
1098 PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?";
1099 SET @a = 0;
1100 EXECUTE stmt USING @a;
1101 SET @a = 1;
1102 EXECUTE stmt USING @a;
1103 SET @a = 0;
1104 EXECUTE stmt USING @a;
1106 PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?";
1107 SET @a = 0;
1108 EXECUTE stmt USING @a;
1109 SET @a = 1;
1110 EXECUTE stmt USING @a;
1111 SET @a = 0;
1112 EXECUTE stmt USING @a;
1114 PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?";
1115 SET @a = 0;
1116 EXECUTE stmt USING @a;
1117 SET @a = 1;
1118 EXECUTE stmt USING @a;
1119 SET @a = 0;
1120 EXECUTE stmt USING @a;
1122 PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?";
1123 SET @a = 0;
1124 EXECUTE stmt USING @a;
1125 SET @a = 1;
1126 EXECUTE stmt USING @a;
1127 SET @a = 0;
1128 EXECUTE stmt USING @a;
1130 DEALLOCATE PREPARE stmt;
1131 DROP TABLE t1;
1134 # Bug#19182: CREATE TABLE bar (m INT) SELECT n FROM foo; doesn't work
1135 # from stored procedure.
1137 # The cause of a bug was that cached LEX::create_list was modified,
1138 # and then together with LEX::key_list was reset.
1140 --disable_warnings
1141 DROP TABLE IF EXISTS t1, t2;
1142 --enable_warnings
1144 CREATE TABLE t1 (i INT);
1146 PREPARE st_19182
1147 FROM "CREATE TABLE t2 (i INT, j INT, KEY (i), KEY(j)) SELECT i FROM t1";
1149 EXECUTE st_19182;
1150 DESC t2;
1152 DROP TABLE t2;
1154 # Check that on second execution we don't loose 'j' column and the keys
1155 # on 'i' and 'j' columns.
1156 EXECUTE st_19182;
1157 DESC t2;
1159 DEALLOCATE PREPARE st_19182;
1160 DROP TABLE t2, t1;
1163 # Bug #22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server"
1165 # Code which implemented CREATE/ALTER TABLE and CREATE DATABASE
1166 # statement modified HA_CREATE_INFO structure in LEX, making these
1167 # statements PS/SP-unsafe (their re-execution might have resulted
1168 # in incorrect results).
1170 --disable_warnings
1171 drop database if exists mysqltest;
1172 drop table if exists t1, t2;
1173 --enable_warnings
1174 # CREATE TABLE and CREATE TABLE ... SELECT
1175 create database mysqltest character set utf8;
1176 prepare stmt1 from "create table mysqltest.t1 (c char(10))";
1177 prepare stmt2 from "create table mysqltest.t2 select 'test'";
1178 execute stmt1;
1179 execute stmt2;
1180 show create table mysqltest.t1;
1181 show create table mysqltest.t2;
1182 drop table mysqltest.t1;
1183 drop table mysqltest.t2;
1184 alter database mysqltest character set latin1;
1185 execute stmt1;
1186 execute stmt2;
1187 show create table mysqltest.t1;
1188 show create table mysqltest.t2;
1189 drop database mysqltest;
1190 deallocate prepare stmt1;
1191 deallocate prepare stmt2;
1193 # CREATE TABLE with DATA DIRECTORY option
1195 --disable_warnings
1196 --disable_query_log
1197 eval prepare stmt from "create table t1 (c char(10)) data directory='$MYSQLTEST_VARDIR/tmp'";
1198 --enable_query_log
1199 execute stmt;
1201 # DATA DIRECTORY option does not always work: if the operating
1202 # system does not support symlinks, have_symlinks option is automatically
1203 # disabled.
1204 # In this case DATA DIRECTORY is silently ignored when
1205 # creating a table, and is not output by SHOW CREATE TABLE.
1207 --disable_result_log
1208 show create table t1;
1209 --enable_result_log
1210 drop table t1;
1211 execute stmt;
1212 --disable_result_log
1213 show create table t1;
1214 --enable_result_log
1215 --enable_warnings
1216 drop table t1;
1217 deallocate prepare stmt;
1221 # Bug #27937: crash on the second execution for prepared statement 
1222 #             from UNION with ORDER BY an expression containing RAND()
1225 CREATE TABLE t1(a int);
1226 INSERT INTO t1 VALUES (2), (3), (1);
1228 PREPARE st1 FROM
1229   '(SELECT a FROM t1) UNION (SELECT a+10 FROM t1) ORDER BY RAND()*0+a';
1231 EXECUTE st1;
1232 EXECUTE st1;
1234 DEALLOCATE PREPARE st1;
1235 DROP TABLE t1;
1239 # Bug #32137: prepared statement crash with str_to_date in update clause
1241 create table t1 (a int, b tinyint);
1242 prepare st1 from 'update t1 set b= (str_to_date(a, a))';
1243 execute st1;
1244 deallocate prepare st1;
1245 drop table t1;
1247 --echo End of 4.1 tests.
1249 ############################# 5.0 tests start ################################
1252 # Bug#6102 "Server crash with prepared statement and blank after
1253 # function name"
1254 # ensure that stored functions are cached when preparing a statement
1255 # before we open tables
1257 create table t1 (a varchar(20)); 
1258 insert into t1 values ('foo'); 
1259 prepare stmt FROM 'SELECT char_length (a) FROM t1'; 
1260 -- error ER_SP_DOES_NOT_EXIST
1261 prepare stmt2 FROM 'SELECT not_a_function (a) FROM t1'; 
1262 drop table t1;
1265 # Bug#8115: equality propagation and prepared statements
1268 create table t1 (a char(3) not null, b char(3) not null,
1269                  c char(3) not null, primary key  (a, b, c));
1270 create table t2 like t1;
1272 # reduced query
1273 prepare stmt from
1274   "select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b)
1275   where t1.a=1";
1276 execute stmt;
1277 execute stmt;
1278 execute stmt;
1280 # original query
1281 prepare stmt from
1282 "select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from
1283 (t1 left outer join t2 on t2.a=? and t1.b=t2.b)
1284 left outer join t2 t3 on t3.a=? where t1.a=?";
1286 set @a:=1, @b:=1, @c:=1;
1288 execute stmt using @a, @b, @c;
1289 execute stmt using @a, @b, @c;
1290 execute stmt using @a, @b, @c;
1292 deallocate prepare stmt;
1294 drop table t1,t2;
1298 # Bug#9383: INFORMATION_SCHEMA.COLUMNS, JOIN, Crash, prepared statement
1301 eval SET @aux= "SELECT COUNT(*)
1302                 FROM INFORMATION_SCHEMA.COLUMNS A,
1303                 INFORMATION_SCHEMA.COLUMNS B
1304                 WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
1305                 AND A.TABLE_NAME = B.TABLE_NAME
1306                 AND A.COLUMN_NAME = B.COLUMN_NAME AND
1307                 A.TABLE_NAME = 'user'";
1309 let $exec_loop_count= 3;
1310 eval prepare my_stmt from @aux;
1311 while ($exec_loop_count)
1313   eval execute my_stmt;
1314   dec $exec_loop_count;
1316 deallocate prepare my_stmt;
1318 # Test CALL in prepared mode
1319 delimiter |;
1320 --disable_warnings
1321 drop procedure if exists p1|
1322 drop table if exists t1|
1323 --enable_warnings
1324 create table t1 (id int)|
1325 insert into t1 values(1)|
1326 create procedure p1(a int, b int)
1327 begin
1328   declare c int;
1329   select max(id)+1 into c from t1;
1330   insert into t1 select a+b;
1331   insert into t1 select a-b;
1332   insert into t1 select a-c;
1333 end|
1334 set @a= 3, @b= 4|
1335 prepare stmt from "call p1(?, ?)"|
1336 execute stmt using @a, @b|
1337 execute stmt using @a, @b|
1338 select * from t1|
1339 deallocate prepare stmt|
1340 drop procedure p1|
1341 drop table t1|
1342 delimiter ;|
1346 # Bug#7306 LIMIT ?, ? and also WL#1785 " Prepared statements: implement
1347 # support for placeholders in LIMIT clause."
1348 # Add basic test coverage for the feature.
1350 create table t1 (a int);
1351 insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
1352 prepare stmt from "select * from t1 limit ?, ?";
1353 set @offset=0, @limit=1;
1354 execute stmt using @offset, @limit;
1355 select * from t1 limit 0, 1;
1356 set @offset=3, @limit=2;
1357 execute stmt using @offset, @limit;
1358 select * from t1 limit 3, 2;
1359 prepare stmt from "select * from t1 limit ?";
1360 execute stmt using @limit;
1361 --error 1235
1362 prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
1363 prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
1364 set @offset=9;
1365 set @limit=2;
1366 execute stmt using @offset, @limit;
1367 prepare stmt from "(select * from t1 limit ?, ?) union all
1368                    (select * from t1 limit ?, ?) order by a limit ?";
1369 execute stmt using @offset, @limit, @offset, @limit, @limit;
1371 drop table t1;
1372 deallocate prepare stmt;
1375 # Bug#12651
1376 # (Crash on a PS including a subquery which is a select from a simple view)
1378 CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
1379 CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
1380 CREATE VIEW  b12651_V1 as SELECT b FROM b12651_T2;
1382 PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
1383 EXECUTE b12651;
1385 DROP VIEW b12651_V1;
1386 DROP TABLE b12651_T1, b12651_T2;
1387 DEALLOCATE PREPARE b12651;
1392 # Bug #14956: ROW_COUNT() returns incorrect result after EXECUTE of prepared
1393 # statement
1395 create table t1 (id int);
1396 prepare ins_call from "insert into t1 (id) values (1)";
1397 execute ins_call;
1398 select row_count();
1399 drop table t1;
1402 # BUG#16474: SP crashed MySQL
1403 # (when using "order by localvar", where 'localvar' is just that.
1404 # The actual bug test is in sp.test, this is just testing that we get the
1405 # expected result for prepared statements too, i.e. place holders work as
1406 # textual substitution. If it's a single integer, it works as the (deprecated)
1407 # "order by column#", otherwise it's an expression.
1409 create table t1 (a int, b int);
1410 insert into t1 (a,b) values (2,8),(1,9),(3,7);
1412 # Will order by index
1413 prepare stmt from "select * from t1 order by ?";
1414 set @a=NULL;
1415 execute stmt using @a;
1416 set @a=1;
1417 execute stmt using @a;
1418 set @a=2;
1419 execute stmt using @a;
1420 deallocate prepare stmt;
1421 # For reference:
1422 select * from t1 order by 1;
1424 # Will not order by index.
1425 prepare stmt from "select * from t1 order by ?+1";
1426 set @a=0;
1427 execute stmt using @a;
1428 set @a=1;
1429 execute stmt using @a;
1430 deallocate prepare stmt;
1431 # For reference:
1432 select * from t1 order by 1+1;
1434 drop table t1;
1437 # Bug#19308 "REPAIR/OPTIMIZE/ANALYZE supported in SP but not in PS".
1438 # Add test coverage for the added commands.
1440 create table t1 (a int);
1441 create table t2 like t1;
1442 create table t3 like t2;
1443 prepare stmt from "repair table t1";
1444 execute stmt;
1445 execute stmt;
1446 prepare stmt from "optimize table t1";
1447 execute stmt;
1448 execute stmt;
1449 prepare stmt from "analyze table t1";
1450 execute stmt;
1451 execute stmt;
1452 prepare stmt from "repair table t1, t2, t3";
1453 execute stmt;
1454 execute stmt;
1455 prepare stmt from "optimize table t1, t2, t3";
1456 execute stmt;
1457 execute stmt;
1458 prepare stmt from "analyze table t1, t2, t3";
1459 execute stmt;
1460 execute stmt;
1461 prepare stmt from "repair table t1, t4, t3";
1462 execute stmt;
1463 execute stmt;
1464 prepare stmt from "optimize table t1, t3, t4";
1465 execute stmt;
1466 execute stmt;
1467 prepare stmt from "analyze table t4, t1";
1468 execute stmt;
1469 execute stmt;
1470 deallocate prepare stmt;
1471 drop table t1, t2, t3;
1474 # Bug#17199 "Table not found" error occurs if the query contains a call
1475 #            to a function from another database.
1476 #            Test prepared statements- related behaviour.
1479 # ALTER TABLE RENAME and Prepared Statements: wrong DB name buffer was used
1480 # in ALTER ... RENAME which caused memory corruption in prepared statements.
1481 # No need to fix this problem in 4.1 as ALTER TABLE is not allowed in
1482 # Prepared Statements in 4.1.
1484 create database mysqltest_long_database_name_to_thrash_heap;
1485 use test;
1486 create table t1 (i int);
1487 prepare stmt from "alter table test.t1 rename t1";
1488 use mysqltest_long_database_name_to_thrash_heap;
1489 execute stmt;
1490 show tables like 't1';
1491 prepare stmt from "alter table test.t1 rename t1";
1492 use test;
1493 execute stmt;
1494 show tables like 't1';
1495 use mysqltest_long_database_name_to_thrash_heap;
1496 show tables like 't1';
1497 deallocate prepare stmt;
1499 # Check that a prepared statement initializes its current database at
1500 # PREPARE, and then works correctly even if the current database has been
1501 # changed.
1503 use mysqltest_long_database_name_to_thrash_heap; 
1504 # Necessary for preparation of INSERT/UPDATE/DELETE to succeed
1505 prepare stmt_create from "create table t1 (i int)";
1506 prepare stmt_insert from "insert into t1 (i) values (1)";
1507 prepare stmt_update from "update t1 set i=2";
1508 prepare stmt_delete from "delete from t1 where i=2";
1509 prepare stmt_select from "select * from t1";
1510 prepare stmt_alter from "alter table t1 add column (b int)";
1511 prepare stmt_alter1 from "alter table t1 drop column b";
1512 prepare stmt_analyze from "analyze table t1";
1513 prepare stmt_optimize from "optimize table t1";
1514 prepare stmt_show from "show tables like 't1'";
1515 prepare stmt_truncate from "truncate table t1";
1516 prepare stmt_drop from "drop table t1";
1517 # Drop the table that was used to prepare INSERT/UPDATE/DELETE: we will
1518 # create a new one by executing stmt_create
1519 drop table t1;
1520 # Switch the current database
1521 use test;
1522 # Check that all prepared statements operate on the database that was
1523 # active at PREPARE
1524 execute stmt_create;
1525 # should return empty set
1526 show tables like 't1';
1527 use mysqltest_long_database_name_to_thrash_heap;
1528 show tables like 't1';
1529 use test;
1530 execute stmt_insert;
1531 select * from mysqltest_long_database_name_to_thrash_heap.t1;
1532 execute stmt_update;
1533 select * from mysqltest_long_database_name_to_thrash_heap.t1;
1534 execute stmt_delete;
1535 execute stmt_select;
1536 execute stmt_alter;
1537 show columns from mysqltest_long_database_name_to_thrash_heap.t1;
1538 execute stmt_alter1;
1539 show columns from mysqltest_long_database_name_to_thrash_heap.t1;
1540 execute stmt_analyze;
1541 execute stmt_optimize;
1542 execute stmt_show;
1543 execute stmt_truncate;
1544 execute stmt_drop;
1545 show tables like 't1';
1546 use mysqltest_long_database_name_to_thrash_heap;
1547 show tables like 't1';
1549 # Attempt a statement PREPARE when there is no current database:
1550 # is expected to return an error.
1552 drop database mysqltest_long_database_name_to_thrash_heap;
1553 --error ER_NO_DB_ERROR
1554 prepare stmt_create from "create table t1 (i int)";
1555 --error ER_NO_DB_ERROR
1556 prepare stmt_insert from "insert into t1 (i) values (1)";
1557 --error ER_NO_DB_ERROR
1558 prepare stmt_update from "update t1 set i=2";
1559 --error ER_NO_DB_ERROR
1560 prepare stmt_delete from "delete from t1 where i=2";
1561 --error ER_NO_DB_ERROR
1562 prepare stmt_select from "select * from t1";
1563 --error ER_NO_DB_ERROR
1564 prepare stmt_alter from "alter table t1 add column (b int)";
1565 --error ER_NO_DB_ERROR
1566 prepare stmt_alter1 from "alter table t1 drop column b";
1567 --error ER_NO_DB_ERROR
1568 prepare stmt_analyze from "analyze table t1";
1569 --error ER_NO_DB_ERROR
1570 prepare stmt_optimize from "optimize table t1";
1571 --error ER_NO_DB_ERROR
1572 prepare stmt_show from "show tables like 't1'";
1573 --error ER_NO_DB_ERROR
1574 prepare stmt_truncate from "truncate table t1";
1575 --error ER_NO_DB_ERROR
1576 prepare stmt_drop from "drop table t1";
1578 # The above has automatically deallocated all our statements.
1580 # Attempt to CREATE a temporary table when no DB used: it should fail
1581 # This proves that no table can be used without explicit specification of
1582 # its database if there is no current database. 
1584 --error ER_NO_DB_ERROR
1585 create temporary table t1 (i int);
1587 # Restore the old environemnt
1589 use test;
1593 # BUG#21166: Prepared statement causes signal 11 on second execution
1595 # Changes in an item tree done by optimizer weren't properly
1596 # registered and went unnoticed, which resulted in preliminary freeing
1597 # of used memory.
1599 --disable_warnings
1600 DROP TABLE IF EXISTS t1, t2, t3;
1601 --enable_warnings
1603 CREATE TABLE t1 (i BIGINT, j BIGINT);
1604 CREATE TABLE t2 (i BIGINT);
1605 CREATE TABLE t3 (i BIGINT, j BIGINT);
1607 PREPARE stmt FROM "SELECT * FROM t1 JOIN t2 ON (t2.i = t1.i)
1608                    LEFT JOIN t3 ON ((t3.i, t3.j) = (t1.i, t1.j))
1609                    WHERE t1.i = ?";
1611 SET @a= 1;
1612 EXECUTE stmt USING @a;
1613 EXECUTE stmt USING @a;
1615 DEALLOCATE PREPARE stmt;
1616 DROP TABLE IF EXISTS t1, t2, t3;
1620 # BUG#21081: SELECT inside stored procedure returns wrong results
1622 --disable_warnings
1623 DROP TABLE IF EXISTS t1, t2;
1624 --enable_warnings
1626 CREATE TABLE t1 (i INT KEY);
1627 CREATE TABLE t2 (i INT);
1629 INSERT INTO t1 VALUES (1), (2);
1630 INSERT INTO t2 VALUES (1);
1632 PREPARE stmt FROM "SELECT t2.i FROM t1 LEFT JOIN t2 ON t2.i = t1.i
1633                    WHERE t1.i = ?";
1635 SET @arg= 1;
1636 EXECUTE stmt USING @arg;
1637 SET @arg= 2;
1638 EXECUTE stmt USING @arg;
1639 SET @arg= 1;
1640 EXECUTE stmt USING @arg;
1642 DEALLOCATE PREPARE stmt;
1643 DROP TABLE t1, t2;
1647 # BUG#20327: Marking of a wrong field leads to a wrong result on select with
1648 #            view, prepared statement and subquery.
1650 CREATE TABLE t1 (i INT);
1651 CREATE VIEW v1 AS SELECT * FROM t1;
1653 INSERT INTO t1 VALUES (1), (2);
1655 let $query = SELECT t1.i FROM t1 JOIN v1 ON t1.i = v1.i
1656              WHERE EXISTS (SELECT * FROM t1 WHERE v1.i = 1);
1657 eval $query;
1658 eval PREPARE stmt FROM "$query";
1659 # Statement execution should return '1'.
1660 EXECUTE stmt;
1661 # Check re-execution.
1662 EXECUTE stmt;
1664 DEALLOCATE PREPARE stmt;
1665 DROP VIEW v1;
1666 DROP TABLE t1;
1670 # BUG#21856: Prepared Statments: crash if bad create
1672 --disable_warnings
1673 DROP PROCEDURE IF EXISTS p1;
1674 --enable_warnings
1676 let $iterations= 100;
1677 --disable_query_log
1678 --disable_result_log
1679 while ($iterations)
1681   --error ER_PARSE_ERROR
1682   PREPARE stmt FROM "CREATE PROCEDURE p1()";
1683   dec $iterations;
1685 --enable_query_log
1686 --enable_result_log
1689 # Bug 19764:  SHOW commands end up in the slow log as table scans
1692 flush status;
1693 prepare sq from 'show status like "slow_queries"';
1694 execute sq;
1695 prepare no_index from 'select 1 from information_schema.tables limit 1';
1696 execute sq;
1697 execute no_index;
1698 execute sq;
1699 deallocate prepare no_index;
1700 deallocate prepare sq;
1704 # Bug 25027: query with a single-row non-correlated subquery
1705 #            and IS NULL predicate
1708 CREATE TABLE t1 (a int);
1709 INSERT INTO t1 VALUES (1), (2);
1710 CREATE TABLE t2 (b int);
1711 INSERT INTO t2 VALUES (NULL);
1713 SELECT a FROM t1 WHERE (SELECT b FROM t2) IS NULL;
1714 PREPARE stmt FROM 'SELECT a FROM t1 WHERE (SELECT b FROM t2) IS NULL';
1716 EXECUTE stmt;
1717 DEALLOCATE PREPARE stmt;
1719 PREPARE stmt FROM 'SELECT a FROM t1 WHERE (SELECT b FROM t2 limit ?) IS NULL';
1720 SET @arg=1;
1721 EXECUTE stmt USING @arg;
1722 DEALLOCATE PREPARE stmt;
1724 DROP TABLE t1,t2;
1726 # Bug#4968 "Stored procedure crash if cursor opened on altered table"
1727 # The bug is not repeatable any more after the fix for
1728 # Bug#15217 "Bug #15217   Using a SP cursor on a table created with PREPARE
1729 # fails with weird error", however ALTER TABLE is not re-execution friendly
1730 # and that caused a valgrind warning. Check that the warning is gone.
1732 --disable_warnings
1733 drop table if exists t1;
1734 --enable_warnings
1735 create table t1 (s1 char(20));
1736 prepare stmt from "alter table t1 modify s1 int";
1737 execute stmt;
1738 execute stmt;
1739 drop table t1;
1740 deallocate prepare stmt;
1743 # Bug#6895 "Prepared Statements: ALTER TABLE DROP COLUMN does nothing"
1745 --disable_warnings
1746 drop table if exists t1;
1747 --enable_warnings
1748 create table t1 (a int, b int);
1749 prepare s_6895 from "alter table t1 drop column b";
1750 execute s_6895;
1751 show columns from t1;
1752 drop table t1;
1753 create table t1 (a int, b int);
1754 execute s_6895;
1755 show columns from t1;
1756 drop table t1;
1757 create table t1 (a int, b int);
1758 execute s_6895;
1759 show columns from t1;
1760 deallocate prepare s_6895;
1761 drop table t1;
1764 # Bug #22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server"
1766 # 5.0 part of the test.
1769 # ALTER TABLE
1770 create table t1 (i int primary key auto_increment) comment='comment for table t1';
1771 create table t2 (i int, j int, k int);
1772 prepare stmt from "alter table t1 auto_increment=100";
1773 execute stmt;
1774 show create table t1;
1775 # Let us trash table-cache's memory
1776 flush tables;
1777 select * from t2;
1778 execute stmt;
1779 show create table t1;
1780 deallocate prepare stmt;
1781 drop table t1, t2;
1782 # 5.1 part of the test.
1783 # CREATE DATABASE
1784 set @old_character_set_server= @@character_set_server;
1785 set @@character_set_server= latin1; 
1786 prepare stmt from "create database mysqltest_1";
1787 execute stmt;
1788 show create database mysqltest_1;
1789 drop database mysqltest_1;
1790 set @@character_set_server= utf8; 
1791 execute stmt;
1792 show create database mysqltest_1;
1793 drop database mysqltest_1;
1794 deallocate prepare stmt;
1795 set @@character_set_server= @old_character_set_server;
1799 # BUG#24491 "using alias from source table in insert ... on duplicate key"
1801 --disable_warnings
1802 drop tables if exists t1;
1803 --enable_warnings
1804 create table t1 (id int primary key auto_increment, value varchar(10));
1805 insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
1806 # Let us prepare INSERT ... SELECT ... ON DUPLICATE KEY UPDATE statement
1807 # which in its ON DUPLICATE KEY clause erroneously tries to assign value
1808 # to a column which is mentioned only in SELECT part.
1809 prepare stmt from "insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP'";
1810 # Both first and second attempts to execute it should fail
1811 --error ER_BAD_FIELD_ERROR 
1812 execute stmt;
1813 --error ER_BAD_FIELD_ERROR
1814 execute stmt;
1815 deallocate prepare stmt;
1816 # And now the same test for more complex case which is more close
1817 # to the one that was reported originally.
1818 prepare stmt from "insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP'";
1819 --error ER_BAD_FIELD_ERROR 
1820 execute stmt;
1821 --error ER_BAD_FIELD_ERROR
1822 execute stmt;
1823 deallocate prepare stmt;
1824 drop tables t1;
1827 # Bug #28509: strange behaviour: passing a decimal value to PS
1829 prepare stmt from "create table t1 select ?";
1830 set @a=1.0;
1831 execute stmt using @a;
1832 show create table t1;
1833 drop table t1;
1836 # Bug#33798: prepared statements improperly handle large unsigned ints
1838 --disable_warnings
1839 drop table if exists t1;
1840 --enable_warnings
1841 create table t1 (a bigint unsigned, b bigint(20) unsigned);
1842 prepare stmt from "insert into t1 values (?,?)";
1843 set @a= 9999999999999999;
1844 set @b= 14632475938453979136;
1845 insert into t1 values (@a, @b);
1846 select * from t1 where a = @a and b = @b;
1847 execute stmt using @a, @b;
1848 select * from t1 where a = @a and b = @b;
1849 deallocate prepare stmt;
1850 drop table t1;
1853 # Bug#32890 Crash after repeated create and drop of tables and views
1856 --disable_warnings
1857 drop view if exists v1;
1858 drop table if exists t1;
1859 --enable_warnings
1861 create table t1 (a int, b int);
1862 insert into t1 values (1,1), (2,2), (3,3);
1863 insert into t1 values (3,1), (1,2), (2,3);
1865 prepare stmt from "create view v1 as select * from t1";
1866 execute stmt;
1867 drop table t1;
1868 create table t1 (a int, b int);
1869 drop view v1;
1870 execute stmt;
1871 show create view v1;
1872 drop view v1;
1874 prepare stmt from "create view v1 (c,d) as select a,b from t1";
1875 execute stmt;
1876 show create view v1;
1877 select * from v1;
1878 drop view v1;
1879 execute stmt;
1880 deallocate prepare stmt;
1881 show create view v1;
1882 select * from v1;
1883 drop view v1;
1885 prepare stmt from "create view v1 (c) as select b+1 from t1";
1886 execute stmt;
1887 show create view v1;
1888 select * from v1;
1889 drop view v1;
1890 execute stmt;
1891 deallocate prepare stmt;
1892 show create view v1;
1893 select * from v1;
1894 drop view v1;
1896 prepare stmt from "create view v1 (c,d,e,f) as select a,b,a in (select a+2 from t1), a = all (select a from t1) from t1";
1897 execute stmt;
1898 show create view v1;
1899 select * from v1;
1900 drop view v1;
1901 execute stmt;
1902 deallocate prepare stmt;
1903 show create view v1;
1904 select * from v1;
1905 drop view v1;
1907 prepare stmt from "create or replace view v1 as select 1";
1908 execute stmt;
1909 show create view v1;
1910 select * from v1;
1911 execute stmt;
1912 show create view v1;
1913 deallocate prepare stmt;
1914 show create view v1;
1915 select * from v1;
1916 drop view v1;
1918 prepare stmt from "create view v1 as select 1, 1";
1919 execute stmt;
1920 show create view v1;
1921 select * from v1;
1922 drop view v1;
1923 execute stmt;
1924 deallocate prepare stmt;
1925 show create view v1;
1926 select * from v1;
1927 drop view v1;
1929 prepare stmt from "create view v1 (x) as select a from t1 where a > 1";
1930 execute stmt;
1931 show create view v1;
1932 select * from v1;
1933 drop view v1;
1934 execute stmt;
1935 deallocate prepare stmt;
1936 show create view v1;
1937 select * from v1;
1938 drop view v1;
1940 prepare stmt from "create view v1 as select * from `t1` `b`";
1941 execute stmt;
1942 show create view v1;
1943 select * from v1;
1944 drop view v1;
1945 execute stmt;
1946 deallocate prepare stmt;
1947 show create view v1;
1948 select * from v1;
1949 drop view v1;
1951 prepare stmt from "create view v1 (a,b,c) as select * from t1";
1952 --error ER_VIEW_WRONG_LIST
1953 execute stmt;
1954 --error ER_VIEW_WRONG_LIST
1955 execute stmt;
1956 deallocate prepare stmt;
1958 drop table t1;
1959 create temporary table t1 (a int, b int);
1961 prepare stmt from "create view v1 as select * from t1";
1962 --error ER_VIEW_SELECT_TMPTABLE
1963 execute stmt;
1964 --error ER_VIEW_SELECT_TMPTABLE
1965 execute stmt;
1966 deallocate prepare stmt;
1968 drop table t1;
1970 --error ER_NO_SUCH_TABLE
1971 prepare stmt from "create view v1 as select * from t1";
1972 --error ER_NO_SUCH_TABLE
1973 prepare stmt from "create view v1 as select * from `t1` `b`";
1976 # Bug#33851: Passing UNSIGNED param to EXECUTE returns ERROR 1210
1979 prepare stmt from "select ?";
1980 set @arg= 123456789.987654321;
1981 select @arg;
1982 execute stmt using @arg;
1983 set @arg= "string";
1984 select @arg;
1985 execute stmt using @arg;
1986 set @arg= 123456;
1987 select @arg;
1988 execute stmt using @arg;
1989 set @arg= cast(-12345.54321 as decimal(20, 10));
1990 select @arg;
1991 execute stmt using @arg;
1992 deallocate prepare stmt;
1994 --echo #
1995 --echo # Bug#48508: Crash on prepared statement re-execution.
1996 --echo #
1997 create table t1(b int);
1998 insert into t1 values (0);
1999 create view v1 AS select 1 as a from t1 where b;
2000 prepare stmt from "select * from v1 where a";
2001 execute stmt;
2002 execute stmt;
2003 deallocate prepare stmt;
2004 drop table t1;
2005 drop view v1;
2007 create table t1(a bigint);
2008 create table t2(b tinyint);
2009 insert into t2 values (null);
2010 prepare stmt from "select 1 from t1 join  t2 on a xor b where b > 1  and a =1";
2011 execute stmt;
2012 execute stmt;
2013 deallocate prepare stmt;
2014 drop table t1,t2;
2015 --echo #
2018 --echo #
2019 --echo # Bug #49570: Assertion failed: !(order->used & map)
2020 --echo # on re-execution of prepared statement
2021 --echo #
2022 CREATE TABLE t1(a INT PRIMARY KEY);
2023 INSERT INTO t1 VALUES(0), (1);
2024 PREPARE stmt FROM 
2025   "SELECT 1 FROM t1 JOIN t1 t2 USING(a) GROUP BY t2.a, t1.a";
2026 EXECUTE stmt;
2027 EXECUTE stmt;
2028 EXECUTE stmt;
2029 DEALLOCATE PREPARE stmt;
2030 DROP TABLE t1;
2033 --echo End of 5.0 tests.
2036 # Bug #20665: All commands supported in Stored Procedures should work in
2037 # Prepared Statements
2039 create procedure proc_1() reset query cache;
2040 call proc_1();
2041 call proc_1();
2042 call proc_1();
2043 delimiter |;
2044 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2045 create function func_1() returns int deterministic begin reset query cache; return 1; end|
2046 create function func_1() returns int deterministic begin call proc_1(); return 1; end|
2047 delimiter ;|
2048 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2049 select func_1(), func_1(), func_1() from dual;
2050 drop function func_1;
2051 drop procedure proc_1;
2052 prepare abc from "reset query cache";
2053 execute abc;
2054 execute abc;
2055 execute abc;
2056 deallocate prepare abc;
2059 create procedure proc_1() reset master;
2060 delimiter |;
2061 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2062 create function func_1() returns int begin reset master; return 1; end|
2063 create function func_1() returns int begin call proc_1(); return 1; end|
2064 delimiter ;|
2065 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2066 select func_1(), func_1(), func_1() from dual;
2067 drop function func_1;
2068 drop procedure proc_1;
2069 prepare abc from "reset master";
2070 execute abc;
2071 execute abc;
2072 execute abc;
2073 deallocate prepare abc;
2076 create procedure proc_1() reset slave;
2077 call proc_1();
2078 call proc_1();
2079 call proc_1();
2080 delimiter |;
2081 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2082 create function func_1() returns int begin reset slave; return 1; end|
2083 create function func_1() returns int begin call proc_1(); return 1; end|
2084 delimiter ;|
2085 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2086 select func_1(), func_1(), func_1() from dual;
2087 drop function func_1;
2088 drop procedure proc_1;
2089 prepare abc from "reset slave";
2090 execute abc;
2091 execute abc;
2092 execute abc;
2093 deallocate prepare abc;
2096 create procedure proc_1(a integer) kill a;
2097 --error ER_NO_SUCH_THREAD
2098 call proc_1(0);
2099 --error ER_NO_SUCH_THREAD
2100 call proc_1(0);
2101 --error ER_NO_SUCH_THREAD
2102 call proc_1(0);
2103 drop procedure proc_1;
2104 delimiter |;
2105 create function func_1() returns int begin kill 0; return 1; end|
2106 delimiter ;|
2107 --error ER_NO_SUCH_THREAD
2108 select func_1() from dual;
2109 --error ER_NO_SUCH_THREAD
2110 select func_1() from dual;
2111 --error ER_NO_SUCH_THREAD
2112 select func_1() from dual;
2113 drop function func_1;
2114 prepare abc from "kill 0";
2115 --error ER_NO_SUCH_THREAD
2116 execute abc;
2117 --error ER_NO_SUCH_THREAD
2118 execute abc;
2119 --error ER_NO_SUCH_THREAD
2120 execute abc;
2121 deallocate prepare abc;
2124 create procedure proc_1() flush hosts;
2125 call proc_1();
2126 call proc_1();
2127 call proc_1();
2128 call proc_1();
2129 delimiter |;
2130 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2131 create function func_1() returns int begin flush hosts; return 1; end|
2132 create function func_1() returns int begin call proc_1(); return 1; end|
2133 delimiter ;|
2134 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2135 select func_1(), func_1(), func_1() from dual;
2136 drop function func_1;
2137 drop procedure proc_1;
2138 prepare abc from "flush hosts";
2139 execute abc;
2140 execute abc;
2141 execute abc;
2142 deallocate prepare abc;
2145 create procedure proc_1() flush privileges;
2146 call proc_1();
2147 call proc_1();
2148 call proc_1();
2149 delimiter |;
2150 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2151 create function func_1() returns int begin flush privileges; return 1; end|
2152 create function func_1() returns int begin call proc_1(); return 1; end|
2153 delimiter ;|
2154 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2155 select func_1(), func_1(), func_1() from dual;
2156 drop function func_1;
2157 drop procedure proc_1;
2158 prepare abc from "flush privileges";
2159 deallocate prepare abc;
2162 create procedure proc_1() flush tables with read lock;
2163 call proc_1();
2164 unlock tables;
2165 call proc_1();
2166 unlock tables;
2167 call proc_1();
2168 unlock tables;
2169 delimiter |;
2170 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2171 create function func_1() returns int begin flush tables with read lock; return 1; end|
2172 create function func_1() returns int begin call proc_1(); return 1; end|
2173 delimiter ;|
2174 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2175 select func_1(), func_1(), func_1() from dual;
2176 drop function func_1;
2177 drop procedure proc_1;
2178 prepare abc from "flush tables with read lock";
2179 execute abc;
2180 execute abc;
2181 execute abc;
2182 deallocate prepare abc;
2183 unlock tables;
2186 create procedure proc_1() flush tables;
2187 call proc_1();
2188 call proc_1();
2189 call proc_1();
2190 delimiter |;
2191 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2192 create function func_1() returns int begin flush tables; return 1; end|
2193 create function func_1() returns int begin call proc_1(); return 1; end|
2194 delimiter ;|
2195 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2196 select func_1(), func_1(), func_1() from dual;
2197 drop function func_1;
2198 drop procedure proc_1;
2199 prepare abc from "flush tables";
2200 execute abc;
2201 execute abc;
2202 execute abc;
2203 deallocate prepare abc;
2206 create procedure proc_1() flush tables;
2207 flush tables;
2208 show open tables from mysql;
2209 select Host, User from mysql.user limit 0;
2210 select Host, Db from mysql.host limit 0;
2211 show open tables from mysql;
2212 call proc_1();
2213 show open tables from mysql;
2214 select Host, User from mysql.user limit 0;
2215 select Host, Db from mysql.host limit 0;
2216 show open tables from mysql;
2217 call proc_1();
2218 show open tables from mysql;
2219 select Host, User from mysql.user limit 0;
2220 select Host, Db from mysql.host limit 0;
2221 show open tables from mysql;
2222 call proc_1();
2223 show open tables from mysql;
2224 select Host, User from mysql.user limit 0;
2225 select Host, Db from mysql.host limit 0;
2226 show open tables from mysql;
2227 flush tables;
2228 delimiter |;
2229 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2230 create function func_1() returns int begin flush tables; return 1; end|
2231 create function func_1() returns int begin call proc_1(); return 1; end|
2232 delimiter ;|
2233 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2234 select func_1(), func_1(), func_1() from dual;
2235 drop function func_1;
2236 drop procedure proc_1;
2238 # make the output deterministic:
2239 # the order used in SHOW OPEN TABLES
2240 # is too much implementation dependent
2241 --disable_ps_protocol
2242 flush tables;
2243 select Host, User from mysql.user limit 0;
2244 select Host, Db from mysql.host limit 0;
2245 show open tables from mysql;
2246 --enable_ps_protocol
2248 prepare abc from "flush tables";
2249 execute abc;
2250 show open tables from mysql;
2251 select Host, User from mysql.user limit 0;
2252 select Host, Db from mysql.host limit 0;
2253 show open tables from mysql;
2254 execute abc;
2255 show open tables from mysql;
2256 select Host, User from mysql.user limit 0;
2257 select Host, Db from mysql.host limit 0;
2258 show open tables from mysql;
2259 execute abc;
2260 show open tables from mysql;
2261 select Host, User from mysql.user limit 0;
2262 select Host, Db from mysql.host limit 0;
2263 show open tables from mysql;
2264 flush tables;
2265 deallocate prepare abc;
2268 create procedure proc_1() flush logs;
2269 call proc_1();
2270 call proc_1();
2271 call proc_1();
2272 delimiter |;
2273 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2274 create function func_1() returns int begin flush logs; return 1; end|
2275 create function func_1() returns int begin call proc_1(); return 1; end|
2276 delimiter ;|
2277 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2278 select func_1(), func_1(), func_1() from dual;
2279 drop function func_1;
2280 drop procedure proc_1;
2281 prepare abc from "flush logs";
2282 execute abc;
2283 execute abc;
2284 execute abc;
2285 deallocate prepare abc;
2288 create procedure proc_1() flush status;
2289 call proc_1();
2290 call proc_1();
2291 call proc_1();
2292 delimiter |;
2293 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2294 create function func_1() returns int begin flush status; return 1; end|
2295 create function func_1() returns int begin call proc_1(); return 1; end|
2296 delimiter ;|
2297 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2298 select func_1(), func_1(), func_1() from dual;
2299 drop function func_1;
2300 drop procedure proc_1;
2301 prepare abc from "flush status";
2302 execute abc;
2303 execute abc;
2304 execute abc;
2305 deallocate prepare abc;
2308 create procedure proc_1() flush slave;
2309 call proc_1();
2310 call proc_1();
2311 call proc_1();
2312 delimiter |;
2313 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2314 create function func_1() returns int begin flush slave; return 1; end|
2315 create function func_1() returns int begin call proc_1(); return 1; end|
2316 delimiter ;|
2317 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2318 select func_1(), func_1(), func_1() from dual;
2319 drop function func_1;
2320 drop procedure proc_1;
2321 prepare abc from "flush slave";
2322 execute abc;
2323 execute abc;
2324 execute abc;
2325 deallocate prepare abc;
2328 create procedure proc_1() flush master;
2329 delimiter |;
2330 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2331 create function func_1() returns int begin flush master; return 1; end|
2332 create function func_1() returns int begin call proc_1(); return 1; end|
2333 delimiter ;|
2334 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2335 select func_1(), func_1(), func_1() from dual;
2336 drop function func_1;
2337 drop procedure proc_1;
2338 prepare abc from "flush master";
2339 deallocate prepare abc;
2342 create procedure proc_1() flush des_key_file;
2343 call proc_1();
2344 call proc_1();
2345 call proc_1();
2346 delimiter |;
2347 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2348 create function func_1() returns int begin flush des_key_file; return 1; end|
2349 create function func_1() returns int begin call proc_1(); return 1; end|
2350 delimiter ;|
2351 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2352 select func_1(), func_1(), func_1() from dual;
2353 drop function func_1;
2354 drop procedure proc_1;
2355 prepare abc from "flush des_key_file";
2356 execute abc;
2357 execute abc;
2358 execute abc;
2359 deallocate prepare abc;
2362 create procedure proc_1() flush user_resources;
2363 call proc_1();
2364 call proc_1();
2365 call proc_1();
2366 delimiter |;
2367 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2368 create function func_1() returns int begin flush user_resources; return 1; end|
2369 create function func_1() returns int begin call proc_1(); return 1; end|
2370 delimiter ;|
2371 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
2372 select func_1(), func_1(), func_1() from dual;
2373 drop function func_1;
2374 drop procedure proc_1;
2375 prepare abc from "flush user_resources";
2376 execute abc;
2377 execute abc;
2378 execute abc;
2379 deallocate prepare abc;
2382 create procedure proc_1() start slave;
2383 drop procedure proc_1;
2384 delimiter |;
2385 create function func_1() returns int begin start slave; return 1; end|
2386 delimiter ;|
2387 drop function func_1;
2388 prepare abc from "start slave";
2389 deallocate prepare abc;
2392 create procedure proc_1() stop slave;
2393 drop procedure proc_1;
2394 delimiter |;
2395 create function func_1() returns int begin stop slave; return 1; end|
2396 delimiter ;|
2397 drop function func_1;
2398 prepare abc from "stop slave";
2399 deallocate prepare abc;
2402 create procedure proc_1() show binlog events;
2403 drop procedure proc_1;
2404 delimiter |;
2405 --error ER_SP_NO_RETSET
2406 create function func_1() returns int begin show binlog events; return 1; end|
2407 delimiter ;|
2408 --error ER_SP_DOES_NOT_EXIST
2409 select func_1(), func_1(), func_1() from dual;
2410 --error ER_SP_DOES_NOT_EXIST
2411 drop function func_1;
2412 prepare abc from "show binlog events";
2413 deallocate prepare abc;
2416 create procedure proc_1() show slave status;
2417 drop procedure proc_1;
2418 delimiter |;
2419 --error ER_SP_NO_RETSET
2420 create function func_1() returns int begin show slave status; return 1; end|
2421 delimiter ;|
2422 --error ER_SP_DOES_NOT_EXIST
2423 select func_1(), func_1(), func_1() from dual;
2424 --error ER_SP_DOES_NOT_EXIST
2425 drop function func_1;
2426 prepare abc from "show slave status";
2427 deallocate prepare abc;
2430 create procedure proc_1() show master status;
2431 drop procedure proc_1;
2432 delimiter |;
2433 --error ER_SP_NO_RETSET
2434 create function func_1() returns int begin show master status; return 1; end|
2435 delimiter ;|
2436 --error ER_SP_DOES_NOT_EXIST
2437 select func_1(), func_1(), func_1() from dual;
2438 --error ER_SP_DOES_NOT_EXIST
2439 drop function func_1;
2440 prepare abc from "show master status";
2441 deallocate prepare abc;
2444 create procedure proc_1() show master logs;
2445 drop procedure proc_1;
2446 delimiter |;
2447 --error ER_SP_NO_RETSET
2448 create function func_1() returns int begin show master logs; return 1; end|
2449 delimiter ;|
2450 --error ER_SP_DOES_NOT_EXIST
2451 select func_1(), func_1(), func_1() from dual;
2452 --error ER_SP_DOES_NOT_EXIST
2453 drop function func_1;
2454 prepare abc from "show master logs";
2455 deallocate prepare abc;
2458 create procedure proc_1() show events;
2459 call proc_1();
2460 call proc_1();
2461 call proc_1();
2462 drop procedure proc_1;
2463 delimiter |;
2464 --error ER_SP_NO_RETSET
2465 create function func_1() returns int begin show events; return 1; end|
2466 delimiter ;|
2467 --error ER_SP_DOES_NOT_EXIST
2468 select func_1(), func_1(), func_1() from dual;
2469 --error ER_SP_DOES_NOT_EXIST
2470 drop function func_1;
2471 prepare abc from "show events";
2472 execute abc;
2473 execute abc;
2474 execute abc;
2475 deallocate prepare abc;
2478 --disable_warnings
2479 drop procedure if exists a;
2480 --enable_warnings
2481 create procedure a() select 42;
2482 create procedure proc_1(a char(2)) show create procedure a;
2483 call proc_1("bb");
2484 call proc_1("bb");
2485 call proc_1("bb");
2486 drop procedure proc_1;
2487 delimiter |;
2488 --error ER_SP_NO_RETSET
2489 create function func_1() returns int begin show create procedure a; return 1; end|
2490 delimiter ;|
2491 --error ER_SP_DOES_NOT_EXIST
2492 select func_1(), func_1(), func_1() from dual;
2493 --error ER_SP_DOES_NOT_EXIST
2494 drop function func_1;
2495 prepare abc from "show create procedure a";
2496 execute abc;
2497 execute abc;
2498 execute abc;
2499 deallocate prepare abc;
2500 drop procedure a;
2503 --disable_warnings
2504 drop function if exists a;
2505 --enable_warnings
2506 create function a() returns int return 42+13;
2507 create procedure proc_1(a char(2)) show create function a;
2508 call proc_1("bb");
2509 call proc_1("bb");
2510 call proc_1("bb");
2511 drop procedure proc_1;
2512 delimiter |;
2513 --error ER_SP_NO_RETSET
2514 create function func_1() returns int begin show create function a; return 1; end|
2515 delimiter ;|
2516 --error ER_SP_DOES_NOT_EXIST
2517 select func_1(), func_1(), func_1() from dual;
2518 --error ER_SP_DOES_NOT_EXIST
2519 drop function func_1;
2520 prepare abc from "show create function a";
2521 execute abc;
2522 execute abc;
2523 execute abc;
2524 deallocate prepare abc;
2525 drop function a;
2528 --disable_warnings
2529 drop table if exists tab1;
2530 --enable_warnings
2531 create table tab1(a int, b char(1), primary key(a,b));
2532 create procedure proc_1() show create table tab1;
2533 call proc_1();
2534 call proc_1();
2535 call proc_1();
2536 drop procedure proc_1;
2537 delimiter |;
2538 --error ER_SP_NO_RETSET
2539 create function func_1() returns int begin show create table tab1; return 1; end|
2540 delimiter ;|
2541 --error ER_SP_DOES_NOT_EXIST
2542 select func_1(), func_1(), func_1() from dual;
2543 --error ER_SP_DOES_NOT_EXIST
2544 drop function func_1;
2545 prepare abc from "show create table tab1";
2546 execute abc;
2547 execute abc;
2548 execute abc;
2549 deallocate prepare abc;
2550 drop table tab1;
2553 --disable_warnings
2554 drop view if exists v1;
2555 drop table if exists t1;
2556 --enable_warnings
2557 create table t1(a int, b char(5));
2558 insert into t1 values (1, "one"), (1, "edno"), (2, "two"), (2, "dve");
2559 create view v1 as
2560     (select a, count(*) from t1 group by a)
2561     union all
2562     (select b, count(*) from t1 group by b);
2563 create procedure proc_1() show create view v1;
2564 call proc_1();
2565 call proc_1();
2566 call proc_1();
2567 drop procedure proc_1;
2568 delimiter |;
2569 --error ER_SP_NO_RETSET
2570 create function func_1() returns int begin show create view v1; return 1; end|
2571 delimiter ;|
2572 --error ER_SP_DOES_NOT_EXIST
2573 select func_1(), func_1(), func_1() from dual;
2574 --error ER_SP_DOES_NOT_EXIST
2575 drop function func_1;
2576 prepare abc from "show create view v1";
2577 execute abc;
2578 execute abc;
2579 execute abc;
2580 deallocate prepare abc;
2581 drop view v1;
2582 drop table t1;
2585 create procedure proc_1() install plugin my_plug soname 'some_plugin.so';
2586 --replace_regex /(Can\'t open shared library).*$/\1/
2587 --error ER_CANT_OPEN_LIBRARY,ER_FEATURE_DISABLED
2588 call proc_1();
2589 --replace_regex /(Can\'t open shared library).*$/\1/
2590 --error ER_CANT_OPEN_LIBRARY,ER_FEATURE_DISABLED
2591 call proc_1();
2592 --replace_regex /(Can\'t open shared library).*$/\1/
2593 --error ER_CANT_OPEN_LIBRARY,ER_FEATURE_DISABLED
2594 call proc_1();
2595 drop procedure proc_1;
2596 delimiter |;
2597 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2598 create function func_1() returns int begin install plugin my_plug soname '/tmp/plugin'; return 1; end|
2599 delimiter ;|
2600 --error ER_SP_DOES_NOT_EXIST
2601 select func_1(), func_1(), func_1() from dual;
2602 --error ER_SP_DOES_NOT_EXIST
2603 drop function func_1;
2604 prepare abc from "install plugin my_plug soname 'some_plugin.so'";
2605 deallocate prepare abc;
2608 create procedure proc_1() uninstall plugin my_plug;
2609 --error ER_SP_DOES_NOT_EXIST
2610 call proc_1();
2611 --error ER_SP_DOES_NOT_EXIST
2612 call proc_1();
2613 --error ER_SP_DOES_NOT_EXIST
2614 call proc_1();
2615 drop procedure proc_1;
2616 delimiter |;
2617 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2618 create function func_1() returns int begin uninstall plugin my_plug; return 1; end|
2619 delimiter ;|
2620 --error ER_SP_DOES_NOT_EXIST
2621 select func_1(), func_1(), func_1() from dual;
2622 --error ER_SP_DOES_NOT_EXIST
2623 drop function func_1;
2624 prepare abc from "uninstall plugin my_plug";
2625 --error ER_SP_DOES_NOT_EXIST
2626 execute abc;
2627 --error ER_SP_DOES_NOT_EXIST
2628 execute abc;
2629 --error ER_SP_DOES_NOT_EXIST
2630 execute abc;
2631 deallocate prepare abc;
2634 --disable_warnings
2635 drop database if exists mysqltest_xyz;
2636 --enable_warnings
2637 create procedure proc_1() create database mysqltest_xyz;
2638 call proc_1();
2639 drop database if exists mysqltest_xyz;
2640 call proc_1();
2641 --error ER_DB_CREATE_EXISTS
2642 call proc_1();
2643 drop database if exists mysqltest_xyz;
2644 call proc_1();
2645 drop database if exists mysqltest_xyz;
2646 drop procedure proc_1;
2647 delimiter |;
2648 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2649 create function func_1() returns int begin create database mysqltest_xyz; return 1; end|
2650 delimiter ;|
2651 --error ER_SP_DOES_NOT_EXIST
2652 select func_1(), func_1(), func_1() from dual;
2653 --error ER_SP_DOES_NOT_EXIST
2654 drop function func_1;
2655 prepare abc from "create database mysqltest_xyz";
2656 execute abc;
2657 drop database if exists mysqltest_xyz;
2658 execute abc;
2659 --error ER_DB_CREATE_EXISTS
2660 execute abc;
2661 drop database if exists mysqltest_xyz;
2662 execute abc;
2663 drop database if exists mysqltest_xyz;
2664 deallocate prepare abc;
2667 --disable_warnings
2668 drop table if exists t1;
2669 --enable_warnings
2670 create table t1 (a int, b char(5));
2671 insert into t1 values (1, "one"), (2, "two"), (3, "three");
2672 create procedure proc_1() checksum table xyz;
2673 call proc_1();
2674 call proc_1();
2675 call proc_1();
2676 drop procedure proc_1;
2677 delimiter |;
2678 --error ER_SP_NO_RETSET
2679 create function func_1() returns int begin checksum table t1; return 1; end|
2680 delimiter ;|
2681 --error ER_SP_DOES_NOT_EXIST
2682 select func_1(), func_1(), func_1() from dual;
2683 --error ER_SP_DOES_NOT_EXIST
2684 drop function func_1;
2685 prepare abc from "checksum table t1";
2686 execute abc;
2687 execute abc;
2688 execute abc;
2689 deallocate prepare abc;
2692 create procedure proc_1() create user pstest_xyz@localhost;
2693 call proc_1();
2694 drop user pstest_xyz@localhost;
2695 call proc_1();
2696 --error ER_CANNOT_USER
2697 call proc_1();
2698 drop user pstest_xyz@localhost;
2699 call proc_1();
2700 drop user pstest_xyz@localhost;
2701 drop procedure proc_1;
2702 delimiter |;
2703 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2704 create function func_1() returns int begin create user pstest_xyz@localhost; return 1; end|
2705 delimiter ;|
2706 --error ER_SP_DOES_NOT_EXIST
2707 select func_1(), func_1(), func_1() from dual;
2708 --error ER_SP_DOES_NOT_EXIST
2709 drop function func_1;
2710 prepare abc from "create user pstest_xyz@localhost";
2711 execute abc;
2712 drop user pstest_xyz@localhost;
2713 execute abc;
2714 --error ER_CANNOT_USER
2715 execute abc;
2716 drop user pstest_xyz@localhost;
2717 execute abc;
2718 drop user pstest_xyz@localhost;
2719 deallocate prepare abc;
2722 --disable_warnings
2723 drop event if exists xyz;
2724 --enable_warnings
2725 #create procedure proc_1() create event xyz on schedule every 5 minute disable do select 123;
2726 #call proc_1();
2727 #drop event xyz;
2728 #call proc_1();
2729 #--error ER_EVENT_ALREADY_EXISTS
2730 #call proc_1();
2731 #drop event xyz;
2732 #call proc_1();
2733 #drop event xyz;
2734 #drop procedure proc_1;
2735 delimiter |;
2736 --error ER_EVENT_RECURSION_FORBIDDEN
2737 create function func_1() returns int begin create event xyz on schedule at now() do select 123; return 1; end|
2738 delimiter ;|
2739 --error ER_SP_DOES_NOT_EXIST
2740 select func_1(), func_1(), func_1() from dual;
2741 --error ER_SP_DOES_NOT_EXIST
2742 drop function func_1;
2743 --error ER_UNSUPPORTED_PS
2744 prepare abc from "create event xyz on schedule at now() do select 123";
2745 --error ER_UNKNOWN_STMT_HANDLER
2746 deallocate prepare abc;
2749 --disable_warnings
2750 drop event if exists xyz;
2751 create event xyz on schedule every 5 minute disable do select 123;
2752 --enable_warnings
2753 create procedure proc_1() alter event xyz comment 'xyz';
2754 call proc_1();
2755 drop event xyz;
2756 create event xyz on schedule every 5 minute disable do select 123;
2757 call proc_1();
2758 drop event xyz;
2759 create event xyz on schedule every 5 minute disable do select 123;
2760 call proc_1();
2761 drop event xyz;
2762 drop procedure proc_1;
2763 delimiter |;
2764 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2765 create function func_1() returns int begin alter event xyz comment 'xyz'; return 1; end|
2766 delimiter ;|
2767 --error ER_UNSUPPORTED_PS
2768 prepare abc from "alter event xyz comment 'xyz'";
2769 --error ER_UNKNOWN_STMT_HANDLER
2770 deallocate prepare abc;
2773 --disable_warnings
2774 drop event if exists xyz;
2775 create event xyz on schedule every 5 minute disable do select 123;
2776 --enable_warnings
2777 create procedure proc_1() drop event xyz;
2778 call proc_1();
2779 create event xyz on schedule every 5 minute disable do select 123;
2780 call proc_1();
2781 --error ER_EVENT_DOES_NOT_EXIST
2782 call proc_1();
2783 drop procedure proc_1;
2784 delimiter |;
2785 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2786 create function func_1() returns int begin drop event xyz; return 1; end|
2787 delimiter ;|
2788 --error ER_UNSUPPORTED_PS
2789 prepare abc from "drop event xyz";
2790 --error ER_UNKNOWN_STMT_HANDLER
2791 deallocate prepare abc;
2794 --disable_warnings
2795 drop table if exists t1;
2796 create table t1 (a int, b char(5)) engine=myisam;
2797 insert into t1 values (1, "one"), (2, "two"), (3, "three");
2798 --enable_warnings
2799 SET GLOBAL new_cache.key_buffer_size=128*1024;
2800 create procedure proc_1() cache index t1 in new_cache;
2801 call proc_1();
2802 call proc_1();
2803 call proc_1();
2804 drop procedure proc_1;
2805 SET GLOBAL second_cache.key_buffer_size=128*1024;
2806 prepare abc from "cache index t1 in second_cache";
2807 execute abc;
2808 execute abc;
2809 execute abc;
2810 deallocate prepare abc;
2811 drop table t1;
2813 --disable_warnings
2814 drop table if exists t1;
2815 drop table if exists t2;
2816 create table t1 (a int, b char(5)) engine=myisam;
2817 insert into t1 values (1, "one"), (2, "two"), (3, "three");
2818 create table t2 (a int, b char(5)) engine=myisam;
2819 insert into t2 values (1, "one"), (2, "two"), (3, "three");
2820 --enable_warnings
2821 create procedure proc_1() load index into cache t1 ignore leaves;
2822 call proc_1();
2823 call proc_1();
2824 call proc_1();
2825 drop procedure proc_1;
2826 delimiter |;
2827 --error ER_SP_NO_RETSET
2828 create function func_1() returns int begin load index into cache t1 ignore leaves; return 1; end|
2829 delimiter ;|
2830 prepare abc from "load index into cache t2 ignore leaves";
2831 execute abc;
2832 execute abc;
2833 execute abc;
2834 deallocate prepare abc;
2835 drop table t1, t2;
2838 # Bug #21422: GRANT/REVOKE possible inside stored function, probably in a trigger
2839 # This is disabled for now till it is resolved in 5.0
2842 #create procedure proc_1() grant all on *.* to abc@host;
2843 #drop procedure proc_1;
2844 #delimiter |;
2845 #--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2846 #create function func_1() returns int begin grant all on *.* to abc@host; return 1; end|
2847 #delimiter ;|
2848 #prepare abc from "grant all on *.* to abc@host";
2850 #create procedure proc_1() revoke all on *.* from abc@host;
2851 #drop procedure proc_1;
2852 #delimiter |;#--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
2853 #create function func_1() returns int begin revoke all on *.* from abc@host; return 1; end|
2854 #delimiter ;|
2855 #prepare abc from "revoke all on *.* from abc@host";
2857 create procedure proc_1() show errors;
2858 call proc_1();
2859 call proc_1();
2860 call proc_1();
2861 drop procedure proc_1;
2862 delimiter |;
2863 --error ER_SP_NO_RETSET
2864 create function func_1() returns int begin show errors; return 1; end|
2865 delimiter ;|
2866 prepare abc from "show errors";
2867 deallocate prepare abc;
2869 --disable_warnings
2870 drop table if exists t1;
2871 drop table if exists t2;
2872 --enable_warnings
2873 create procedure proc_1() show warnings;
2874 drop table if exists t1;
2875 call proc_1();
2876 drop table if exists t2;
2877 call proc_1();
2878 drop table if exists t1, t2;
2879 call proc_1();
2880 drop procedure proc_1;
2881 delimiter |;
2882 --error ER_SP_NO_RETSET
2883 create function func_1() returns int begin show warnings; return 1; end|
2884 delimiter ;|
2885 prepare abc from "show warnings";
2886 drop table if exists t1;
2887 execute abc;
2888 drop table if exists t2;
2889 execute abc;
2890 drop table if exists t1, t2;
2891 execute abc;
2892 deallocate prepare abc;
2895 # Bug#22684: The Functions ENCODE, DECODE and FORMAT are not real functions
2898 set @my_password="password";
2899 set @my_data="clear text to encode";
2901 prepare stmt1 from 'select decode(encode(?, ?), ?)';
2902 execute stmt1 using @my_data, @my_password, @my_password;
2903 set @my_data="more text to encode";
2904 execute stmt1 using @my_data, @my_password, @my_password;
2905 set @my_password="new password";
2906 execute stmt1 using @my_data, @my_password, @my_password;
2907 deallocate prepare stmt1;
2909 set @to_format="123456789.123456789";
2910 set @dec=0;
2912 prepare stmt2 from 'select format(?, ?)';
2913 execute stmt2 using @to_format, @dec;
2914 set @dec=4;
2915 execute stmt2 using @to_format, @dec;
2916 set @dec=6;
2917 execute stmt2 using @to_format, @dec;
2918 set @dec=2;
2919 execute stmt2 using @to_format, @dec;
2920 set @to_format="100";
2921 execute stmt2 using @to_format, @dec;
2922 set @to_format="1000000";
2923 execute stmt2 using @to_format, @dec;
2924 set @to_format="10000";
2925 execute stmt2 using @to_format, @dec;
2926 deallocate prepare stmt2;
2930 # BUG#18326: Do not lock table for writing during prepare of statement
2932 --disable_warnings
2933 DROP TABLE IF EXISTS t1, t2;
2934 --enable_warnings
2936 CREATE TABLE t1 (i INT);
2937 INSERT INTO t1 VALUES (1);
2938 CREATE TABLE t2 (i INT);
2939 INSERT INTO t2 VALUES (2);
2941 LOCK TABLE t1 READ, t2 WRITE;
2943 connect (conn1, localhost, root, , );
2945 # Prepare never acquires the lock, and thus should not block.
2946 PREPARE stmt1 FROM "SELECT i FROM t1";
2947 PREPARE stmt2 FROM "INSERT INTO t2 (i) VALUES (3)";
2949 # This should not block because READ lock on t1 is shared.
2950 EXECUTE stmt1;
2952 # This should block because WRITE lock on t2 is exclusive.
2953 send EXECUTE stmt2;
2955 connection default;
2957 SELECT * FROM t2;
2958 UNLOCK TABLES;
2959 let $wait_condition= SELECT COUNT(*) = 2 FROM t2;
2960 --source include/wait_condition.inc
2961 SELECT * FROM t2;
2963 # DDL and DML works even if some client have a prepared statement
2964 # referencing the table.
2965 ALTER TABLE t1 ADD COLUMN j INT;
2966 ALTER TABLE t2 ADD COLUMN j INT;
2967 INSERT INTO t1 VALUES (4, 5);
2968 INSERT INTO t2 VALUES (4, 5);
2970 connection conn1;
2972 reap;
2973 EXECUTE stmt1;
2974 EXECUTE stmt2;
2975 SELECT * FROM t2;
2977 disconnect conn1;
2979 connection default;
2981 DROP TABLE t1, t2;
2984 # Bug #24879 Prepared Statements: CREATE TABLE (UTF8 KEY) produces a growing
2985 # key length
2987 # Test that parse information is not altered by subsequent executions of a
2988 # prepared statement
2990 drop table if exists t1;
2991 prepare stmt
2992 from "create table t1 (c char(100) character set utf8, key (c(10)))";
2993 execute stmt;
2994 show create table t1;
2995 drop table t1;
2996 execute stmt;
2997 show create table t1;
2998 drop table t1;
3001 # Bug #32030 DELETE does not return an error and deletes rows if error
3002 # evaluating WHERE
3004 # Test that there is an error for prepared delete just like for the normal
3005 # one.
3007 --disable_warnings
3008 drop table if exists t1, t2;
3009 --enable_warnings
3010 create table t1 (a int, b int);
3011 create table t2 like t1;
3013 insert into t1 (a, b) values (1,1), (1,2), (1,3), (1,4), (1,5),
3014        (2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6);
3016 insert into t2 select a, max(b) from t1 group by a;
3018 prepare stmt from "delete from t2 where (select (select max(b) from t1 group
3019 by a having a < 2) x from t1) > 10000";
3021 --error ER_SUBQUERY_NO_1_ROW
3022 delete from t2 where (select (select max(b) from t1 group
3023 by a having a < 2) x from t1) > 10000;
3024 --error ER_SUBQUERY_NO_1_ROW
3025 execute stmt;
3026 --error ER_SUBQUERY_NO_1_ROW
3027 execute stmt;
3029 deallocate prepare stmt;
3030 drop table t1, t2;
3032 --echo #
3033 --echo # Bug#27430 Crash in subquery code when in PS and table DDL changed
3034 --echo # after PREPARE
3035 --echo #
3036 --echo # This part of the test doesn't work in embedded server, this is
3037 --echo # why it's here. For the main test see ps_ddl*.test
3038 --echo
3039 --disable_warnings
3040 drop table if exists t1;
3041 --enable_warnings
3042 create table t1 (a int);
3043 prepare stmt from "show events where (1) in (select * from t1)";
3044 execute stmt;
3045 drop table t1;
3046 create table t1 (x int);
3047 execute stmt;
3048 drop table t1;
3049 deallocate prepare stmt;
3051 --echo #
3052 --echo # Bug#49141: Encode function is significantly slower in 5.1 compared to 5.0
3053 --echo #
3055 prepare encode from "select encode(?, ?) into @ciphertext";
3056 prepare decode from "select decode(?, ?) into @plaintext";
3057 set @str="abc", @key="cba";
3058 execute encode using @str, @key;
3059 execute decode using @ciphertext, @key;
3060 select @plaintext;
3061 set @str="bcd", @key="dcb";
3062 execute encode using @str, @key;
3063 execute decode using @ciphertext, @key;
3064 select @plaintext;
3065 deallocate prepare encode;
3066 deallocate prepare decode;
3068 --echo #
3069 --echo # Bug#52124 memory leaks like a sieve in datetime, timestamp, time, date fields + warnings
3070 --echo #
3071 CREATE TABLE t1 (a DATETIME NOT NULL, b TINYINT);
3072 INSERT INTO t1 VALUES (0, 0),(0, 0);
3073 PREPARE stmt FROM "SELECT 1 FROM t1 WHERE
3074 ROW(a, b) >= ROW('1', (SELECT 1 FROM t1 WHERE a > 1234))";
3075 --disable_warnings
3076 EXECUTE stmt;
3077 EXECUTE stmt;
3078 --enable_warnings
3079 DEALLOCATE PREPARE stmt;
3080 DROP TABLE t1;
3082 --echo #
3083 --echo # Bug#54494 crash with explain extended and prepared statements
3084 --echo #
3085 CREATE TABLE t1(a INT);
3086 INSERT INTO t1 VALUES (1),(2);
3087 PREPARE stmt FROM 'EXPLAIN EXTENDED SELECT 1 FROM t1 RIGHT JOIN t1 t2 ON 1';
3088 EXECUTE stmt;
3089 EXECUTE stmt;
3090 DEALLOCATE PREPARE stmt;
3091 DROP TABLE t1;
3093 --echo #
3094 --echo # Bug#54488 crash when using explain and prepared statements with subqueries
3095 --echo #
3096 CREATE TABLE t1(f1 INT);
3097 INSERT INTO t1 VALUES (1),(1);
3098 PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 WHERE (SELECT (SELECT 1 FROM t1 GROUP BY f1))';
3099 EXECUTE stmt;
3100 EXECUTE stmt;
3101 DEALLOCATE PREPARE stmt;
3102 DROP TABLE t1;
3104 --echo End of 5.1 tests.
3106 --echo
3107 --echo # Bug#13805127: Stored program cache produces wrong result in same THD
3108 --echo
3110 PREPARE s1 FROM 
3112 SELECT c1, t2.c2, count(c3)
3113 FROM
3114   (
3115   SELECT 3 as c2 FROM dual WHERE @x = 1
3116   UNION
3117   SELECT 2       FROM dual WHERE @x = 1 OR @x = 2
3118   ) AS t1,
3119   (
3120   SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
3121   UNION
3122   SELECT '2012-03-01 02:00:00',       3,       2       FROM dual
3123   UNION
3124   SELECT '2012-03-01 01:00:00',       2,       1       FROM dual
3125   ) AS t2
3126 WHERE t2.c2 = t1.c2
3127 GROUP BY c1, c2
3130 --echo
3131 SET @x = 1;
3132 SELECT c1, t2.c2, count(c3)
3133 FROM
3134   (
3135   SELECT 3 as c2 FROM dual WHERE @x = 1
3136   UNION
3137   SELECT 2       FROM dual WHERE @x = 1 OR @x = 2
3138   ) AS t1,
3139   (
3140   SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
3141   UNION
3142   SELECT '2012-03-01 02:00:00',       3,       2       FROM dual
3143   UNION
3144   SELECT '2012-03-01 01:00:00',       2,       1       FROM dual
3145   ) AS t2
3146 WHERE t2.c2 = t1.c2
3147 GROUP BY c1, c2;
3148 --echo
3149 EXECUTE s1;
3151 --echo
3152 SET @x = 2;
3153 SELECT c1, t2.c2, count(c3)
3154 FROM
3155   (
3156   SELECT 3 as c2 FROM dual WHERE @x = 1
3157   UNION
3158   SELECT 2       FROM dual WHERE @x = 1 OR @x = 2
3159   ) AS t1,
3160   (
3161   SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
3162   UNION
3163   SELECT '2012-03-01 02:00:00',       3,       2       FROM dual
3164   UNION
3165   SELECT '2012-03-01 01:00:00',       2,       1       FROM dual
3166   ) AS t2
3167 WHERE t2.c2 = t1.c2
3168 GROUP BY c1, c2;
3169 --echo
3170 EXECUTE s1;
3172 --echo
3173 SET @x = 1;
3174 SELECT c1, t2.c2, count(c3)
3175 FROM
3176   (
3177   SELECT 3 as c2 FROM dual WHERE @x = 1
3178   UNION
3179   SELECT 2       FROM dual WHERE @x = 1 OR @x = 2
3180   ) AS t1,
3181   (
3182   SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
3183   UNION
3184   SELECT '2012-03-01 02:00:00',       3,       2       FROM dual
3185   UNION
3186   SELECT '2012-03-01 01:00:00',       2,       1       FROM dual
3187   ) AS t2
3188 WHERE t2.c2 = t1.c2
3189 GROUP BY c1, c2;
3190 --echo
3191 EXECUTE s1;
3193 DEALLOCATE PREPARE s1;