1 2-- source include/not_embedded.inc 3-- source include/have_log_bin.inc 4 5call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.'); 6# 7# SQL Syntax for Prepared Statements test 8# 9--disable_warnings 10drop table if exists t1,t2,t3,t4; 11 12# Avoid wrong warnings if mysql_client_test fails 13drop database if exists client_test_db; 14--enable_warnings 15 16create table t1 17( 18 a int primary key, 19 b char(10) 20); 21insert into t1 values (1,'one'); 22insert into t1 values (2,'two'); 23insert into t1 values (3,'three'); 24insert into t1 values (4,'four'); 25 26# basic functionality 27set @a=2; 28prepare stmt1 from 'select * from t1 where a <= ?'; 29execute stmt1 using @a; 30set @a=3; 31execute stmt1 using @a; 32 33# non-existant statement 34--error 1243 35deallocate prepare no_such_statement; 36 37--error 1210 38execute stmt1; 39 40# Nesting ps commands is not allowed: 41--error ER_UNSUPPORTED_PS 42prepare stmt2 from 'prepare nested_stmt from "select 1"'; 43 44--error ER_UNSUPPORTED_PS 45prepare stmt2 from 'execute stmt1'; 46 47--error ER_UNSUPPORTED_PS 48prepare stmt2 from 'deallocate prepare z'; 49 50# PS insert 51prepare stmt3 from 'insert into t1 values (?,?)'; 52set @arg1=5, @arg2='five'; 53execute stmt3 using @arg1, @arg2; 54select * from t1 where a>3; 55 56# PS update 57prepare stmt4 from 'update t1 set a=? where b=?'; 58set @arg1=55, @arg2='five'; 59execute stmt4 using @arg1, @arg2; 60select * from t1 where a>3; 61 62# PS create/delete 63prepare stmt4 from 'create table t2 (a int)'; 64execute stmt4; 65prepare stmt4 from 'drop table t2'; 66execute stmt4; 67 68# Do something that will cause error 69--error 1051 70execute stmt4; 71 72# placeholders in result field names. 73prepare stmt5 from 'select ? + a from t1'; 74set @a=1; 75execute stmt5 using @a; 76 77execute stmt5 using @no_such_var; 78 79set @nullvar=1; 80set @nullvar=NULL; 81execute stmt5 using @nullvar; 82 83set @nullvar2=NULL; 84execute stmt5 using @nullvar2; 85 86# Check that multiple SQL statements are disabled inside PREPARE 87--error 1064 88prepare stmt6 from 'select 1; select2'; 89 90--error 1064 91prepare stmt6 from 'insert into t1 values (5,"five"); select2'; 92 93# This shouldn't parse 94--error 1064 95explain prepare stmt6 from 'insert into t1 values (5,"five"); select2'; 96 97create table t2 98( 99 a int 100); 101 102insert into t2 values (0); 103 104# parameter is NULL 105set @arg00=NULL ; 106prepare stmt1 from 'select 1 FROM t2 where a=?' ; 107execute stmt1 using @arg00 ; 108 109# prepare using variables: 110--error 1064 111prepare stmt1 from @nosuchvar; 112 113set @ivar= 1234; 114--error 1064 115prepare stmt1 from @ivar; 116 117set @fvar= 123.4567; 118--error 1064 119prepare stmt1 from @fvar; 120 121drop table t1,t2; 122deallocate prepare stmt3; 123deallocate prepare stmt4; 124deallocate prepare stmt5; 125 126# 127# Bug #4105: Server crash on attempt to prepare a statement with character 128# set introducer 129# 130PREPARE stmt1 FROM "select _utf8 'A' collate utf8_bin = ?"; 131set @var='A'; 132EXECUTE stmt1 USING @var; 133DEALLOCATE PREPARE stmt1; 134 135# 136# BUG#3486: FOUND_ROWS() fails inside stored procedure [and prepared statement] 137# 138create table t1 (id int); 139prepare stmt1 from "select FOUND_ROWS()"; 140select SQL_CALC_FOUND_ROWS * from t1; 141# Expect 0 142execute stmt1; 143insert into t1 values (1); 144select SQL_CALC_FOUND_ROWS * from t1; 145# Expect 1 146execute stmt1; 147# Expect 0 148execute stmt1; 149deallocate prepare stmt1; 150drop table t1; 151 152# 153# prepared EXPLAIN 154# 155create table t1 156( 157 c1 tinyint, c2 smallint, c3 mediumint, c4 int, 158 c5 integer, c6 bigint, c7 float, c8 double, 159 c9 double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4), 160 c13 date, c14 datetime, c15 timestamp, c16 time, 161 c17 year, c18 bit, c19 bool, c20 char, 162 c21 char(10), c22 varchar(30), c23 tinyblob, c24 tinytext, 163 c25 blob, c26 text, c27 mediumblob, c28 mediumtext, 164 c29 longblob, c30 longtext, c31 enum('one', 'two', 'three'), 165 c32 set('monday', 'tuesday', 'wednesday') 166) engine = MYISAM ; 167create table t2 like t1; 168 169set @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 ' ; 170prepare stmt1 from @stmt ; 171execute stmt1 ; 172execute stmt1 ; 173explain 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; 174deallocate prepare stmt1; 175drop tables t1,t2; 176 177# 178# parameters from variables (for field creation) 179# 180set @arg00=1; 181prepare stmt1 from ' create table t1 (m int) as select 1 as m ' ; 182execute stmt1 ; 183select m from t1; 184drop table t1; 185prepare stmt1 from ' create table t1 (m int) as select ? as m ' ; 186execute stmt1 using @arg00; 187select m from t1; 188deallocate prepare stmt1; 189drop table t1; 190 191# 192# eq() for parameters 193# 194create table t1 (id int(10) unsigned NOT NULL default '0', 195 name varchar(64) NOT NULL default '', 196 PRIMARY KEY (id), UNIQUE KEY `name` (`name`)); 197insert into t1 values (1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5'),(6,'6'),(7,'7'); 198prepare stmt1 from 'select name from t1 where id=? or id=?'; 199set @id1=1,@id2=6; 200execute stmt1 using @id1, @id2; 201select name from t1 where id=1 or id=6; 202deallocate prepare stmt1; 203drop table t1; 204 205# 206# SHOW TABLE STATUS test 207# 208create table t1 ( a int primary key, b varchar(30)) engine = MYISAM ; 209prepare stmt1 from ' show table status from test like ''t1%'' '; 210--replace_column 8 4294967295 12 # 13 # 14 # 211execute stmt1; 212--replace_column 8 4294967295 12 # 13 # 14 # 213show table status from test like 't1%' ; 214deallocate prepare stmt1 ; 215drop table t1; 216 217# 218# Bug#4912 "mysqld crashs in case a statement is executed a second time": 219# negation elimination should work once and not break prepared statements 220# 221 222create table t1(a varchar(2), b varchar(3)); 223prepare stmt1 from "select a, b from t1 where (not (a='aa' and b < 'zzz'))"; 224execute stmt1; 225execute stmt1; 226deallocate prepare stmt1; 227drop table t1; 228 229# 230# Bug#5034 "prepared "select 1 into @arg15", second execute crashes 231# server". 232# Check that descendands of select_result can be reused in prepared 233# statements or are correctly created and deleted on each execute 234# 235 236--let $outfile=$MYSQLTEST_VARDIR/tmp/f1.txt 237--error 0,1 238--remove_file $outfile 239 240prepare stmt1 from "select 1 into @var"; 241execute stmt1; 242execute stmt1; 243prepare stmt1 from "create table t1 select 1 as i"; 244--disable_warnings ONCE 245execute stmt1; 246drop table t1; 247--disable_warnings ONCE 248execute stmt1; 249prepare stmt1 from "insert into t1 select i from t1"; 250execute stmt1; 251execute stmt1; 252--replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR> 253eval prepare stmt1 from "select * from t1 into outfile '$outfile'"; 254execute stmt1; 255deallocate prepare stmt1; 256drop table t1; 257 258--remove_file $outfile 259 260# 261# BUG#5242 "Prepared statement names are case sensitive" 262# 263prepare stmt1 from 'select 1'; 264prepare STMT1 from 'select 2'; 265execute sTmT1; 266deallocate prepare StMt1; 267 268--error 1243 269deallocate prepare Stmt1; 270 271# also check that statement names are in right charset. 272set names utf8; 273prepare `ü` from 'select 1234'; 274execute `ü` ; 275set names latin1; 276execute `�`; 277deallocate prepare `�`; 278set names default; 279 280 281# 282# BUG#4368 "select * from t1 where a like ?" crashes server if a is in utf8 283# and ? is in latin1 284# Check that Item converting latin1 to utf8 (for LIKE function) is created 285# in memory of prepared statement. 286# 287 288create table t1 (a varchar(10)) charset=utf8; 289insert into t1 (a) values ('yahoo'); 290set character_set_connection=latin1; 291prepare stmt from 'select a from t1 where a like ?'; 292set @var='google'; 293execute stmt using @var; 294execute stmt using @var; 295deallocate prepare stmt; 296drop table t1; 297 298# 299# BUG#5510 "inserting Null in AutoIncrement primary key Column Fails" 300# (prepared statements) 301# The cause: misuse of internal MySQL 'Field' API. 302# 303 304create table t1 (a bigint(20) not null primary key auto_increment); 305insert into t1 (a) values (null); 306select * from t1; 307prepare stmt from "insert into t1 (a) values (?)"; 308set @var=null; 309execute stmt using @var; 310select * from t1; 311drop table t1; 312# 313# check the same for timestamps 314# 315create table t1 (a timestamp not null); 316prepare stmt from "insert into t1 (a) values (?)"; 317execute stmt using @var; 318--disable_result_log ONCE 319select * from t1; 320deallocate prepare stmt; 321drop table t1; 322 323# 324# BUG#5688 "Upgraded 4.1.5 Server seg faults" # (prepared statements) 325# The test case speaks for itself. 326# Just another place where we used wrong memory root for Items created 327# during statement prepare. 328# 329prepare stmt from "select 'abc' like convert('abc' using utf8)"; 330execute stmt; 331execute stmt; 332deallocate prepare stmt; 333 334# 335# BUG#5748 "Prepared statement with BETWEEN and bigint values crashes 336# mysqld". Just another place where an item tree modification must be 337# rolled back. 338# 339create table t1 ( a bigint ); 340prepare stmt from 'select a from t1 where a between ? and ?'; 341set @a=1; 342execute stmt using @a, @a; 343execute stmt using @a, @a; 344execute stmt using @a, @a; 345drop table t1; 346deallocate prepare stmt; 347 348# 349# Bug #5987 subselect in bool function crashes server (prepared statements): 350# don't overwrite transformed subselects with old arguments of a bool 351# function. 352# 353create table t1 (a int); 354prepare stmt from "select * from t1 where 1 > (1 in (SELECT * FROM t1))"; 355execute stmt; 356execute stmt; 357execute stmt; 358drop table t1; 359deallocate prepare stmt; 360 361# 362# Test case for Bug#6042 "constants propogation works only once (prepared 363# statements): check that the query plan changes whenever we change 364# placeholder value. 365# 366create table t1 (a int, b int) engine = myisam; 367insert into t1 (a, b) values (1,1), (1,2), (2,1), (2,2); 368prepare stmt from 369"explain select * from t1 where t1.a=2 and t1.a=t1.b and t1.b > 1 + ?"; 370set @v=5; 371--replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 372execute stmt using @v; 373set @v=0; 374--replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 375execute stmt using @v; 376set @v=5; 377--replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 378execute stmt using @v; 379drop table t1; 380deallocate prepare stmt; 381 382# 383# A test case for Bug#5985 prepare stmt from "select rand(?)" crashes 384# server. Check that Item_func_rand is prepared-statements friendly. 385# 386create table t1 (a int); 387insert into t1 (a) values (1), (2), (3), (4); 388set @precision=10000000000; 389--replace_column 1 - 3 - 390select rand(), 391 cast(rand(10)*@precision as unsigned integer) from t1; 392prepare stmt from 393"select rand(), 394 cast(rand(10)*@precision as unsigned integer), 395 cast(rand(?)*@precision as unsigned integer) from t1"; 396set @var=1; 397--replace_column 1 - 3 - 398execute stmt using @var; 399set @var=2; 400--replace_column 1 - 401execute stmt using @var; 402set @var=3; 403--replace_column 1 - 404execute stmt using @var; 405drop table t1; 406deallocate prepare stmt; 407 408# 409# A test case for Bug#6050 "EXECUTE stmt reports ambiguous fieldnames with 410# identical tables from different schemata" 411# Check that field name resolving in prepared statements works OK. 412# 413create database mysqltest1; 414create table t1 (a int); 415create table mysqltest1.t1 (a int); 416select * from t1, mysqltest1.t1; 417prepare stmt from "select * from t1, mysqltest1.t1"; 418execute stmt; 419execute stmt; 420execute stmt; 421drop table t1; 422drop table mysqltest1.t1; 423drop database mysqltest1; 424deallocate prepare stmt; 425select '1.1' as a, '1.2' as a UNION SELECT '2.1', '2.2'; 426prepare stmt from 427"select '1.1' as a, '1.2' as a UNION SELECT '2.1', '2.2'"; 428execute stmt; 429execute stmt; 430execute stmt; 431deallocate prepare stmt; 432 433# 434# Test CREATE TABLE ... SELECT (Bug #6094) 435# 436create table t1 (a int); 437insert into t1 values (1),(2),(3); 438create table t2 select * from t1; 439--disable_warnings 440prepare stmt FROM 'create table t2 select * from t1'; 441drop table t2; 442execute stmt; 443drop table t2; 444execute stmt; 445--error 1050 446execute stmt; 447drop table t2; 448execute stmt; 449--enable_warnings 450drop table t1,t2; 451deallocate prepare stmt; 452 453# 454# Bug#6088 "FOUND_ROWS returns wrong values for prepared statements when 455# LIMIT is used" 456# 457create table t1 (a int); 458insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); 459prepare stmt from "select sql_calc_found_rows * from t1 limit 2"; 460execute stmt; 461select found_rows(); 462execute stmt; 463select found_rows(); 464execute stmt; 465select found_rows(); 466deallocate prepare stmt; 467drop table t1; 468 469# 470# Bug#6047 "permission problem when executing mysql_stmt_execute with derived 471# table" 472# 473 474CREATE TABLE t1 (N int, M tinyint); 475INSERT INTO t1 VALUES (1,0),(1,0),(2,0),(2,0),(3,0); 476PREPARE 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'; 477EXECUTE stmt; 478DEALLOCATE PREPARE stmt; 479DROP TABLE t1; 480 481# 482# Bug#6297 "prepared statement, wrong handling of <parameter> IS NULL" 483# Test that placeholders work with IS NULL/IS NOT NULL clauses. 484# 485prepare stmt from "select ? is null, ? is not null, ?"; 486select @no_such_var is null, @no_such_var is not null, @no_such_var; 487execute stmt using @no_such_var, @no_such_var, @no_such_var; 488set @var='abc'; 489select @var is null, @var is not null, @var; 490execute stmt using @var, @var, @var; 491set @var=null; 492select @var is null, @var is not null, @var; 493execute stmt using @var, @var, @var; 494 495# 496# Bug#6873 "PS, having with subquery, crash during execute" 497# check that if we modify having subtree, we update JOIN->having pointer 498# 499create table t1 (pnum char(3)); 500create table t2 (pnum char(3)); 501prepare stmt from "select pnum from t2 having pnum in (select 'p1' from t1)"; 502execute stmt; 503execute stmt; 504execute stmt; 505deallocate prepare stmt; 506drop table t1, t2; 507 508# 509# 510# Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating 511# tables" 512# Check that multi-delete tables are also cleaned up before re-execution. 513# 514--disable_warnings 515drop table if exists t1; 516create temporary table if not exists t1 (a1 int); 517--enable_warnings 518# exact delete syntax is essential 519prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1"; 520drop temporary table t1; 521create temporary table if not exists t1 (a1 int); 522# the server crashed on the next statement without the fix 523execute stmt; 524drop temporary table t1; 525create temporary table if not exists t1 (a1 int); 526# the problem was in memory corruption: repeat the test just in case 527execute stmt; 528drop temporary table t1; 529create temporary table if not exists t1 (a1 int); 530execute stmt; 531drop temporary table t1; 532deallocate prepare stmt; 533 534# Bug#6102 "Server crash with prepared statement and blank after 535# function name" 536# ensure that stored functions are cached when preparing a statement 537# before we open tables 538# 539create table t1 (a varchar(20)); 540insert into t1 values ('foo'); 541prepare stmt FROM 'SELECT char_length (a) FROM t1'; 542-- error ER_SP_DOES_NOT_EXIST 543prepare stmt2 FROM 'SELECT not_a_function (a) FROM t1'; 544drop table t1; 545 546# 547# Bug #6089: FOUND_ROWS returns wrong values when no table/view is used 548# 549 550prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0"; 551execute stmt; 552SELECT FOUND_ROWS(); 553execute stmt; 554SELECT FOUND_ROWS(); 555deallocate prepare stmt; 556 557# 558# Bug#9096 "select doesn't return all matched records if prepared statements 559# is used" 560# The bug was is bad co-operation of the optimizer's algorithm which determines 561# which keys can be used to execute a query, constants propagation 562# part of the optimizer and parameter markers used by prepared statements. 563 564drop table if exists t1; 565create table t1 (c1 int(11) not null, c2 int(11) not null, 566 primary key (c1,c2), key c2 (c2), key c1 (c1)); 567 568insert into t1 values (200887, 860); 569insert into t1 values (200887, 200887); 570 571select * from t1 where (c1=200887 and c2=200887) or c2=860; 572 573prepare stmt from 574"select * from t1 where (c1=200887 and c2=200887) or c2=860"; 575execute stmt; 576prepare stmt from 577"select * from t1 where (c1=200887 and c2=?) or c2=?"; 578set @a=200887, @b=860; 579# this query did not return all matching rows 580execute stmt using @a, @b; 581deallocate prepare stmt; 582 583drop table t1; 584 585# 586# Bug#9777 - another occurrence of the problem stated in Bug#9096: 587# we can not compare basic constants by their names, because a placeholder 588# is a basic constant while his name is always '?' 589# 590 591create table t1 ( 592 id bigint(20) not null auto_increment, 593 code varchar(20) character set utf8 collate utf8_bin not null default '', 594 company_name varchar(250) character set utf8 collate utf8_bin default null, 595 setup_mode tinyint(4) default null, 596 start_date datetime default null, 597 primary key (id), unique key code (code) 598); 599 600create table t2 ( 601 id bigint(20) not null auto_increment, 602 email varchar(250) character set utf8 collate utf8_bin default null, 603 name varchar(250) character set utf8 collate utf8_bin default null, 604 t1_id bigint(20) default null, 605 password varchar(250) character set utf8 collate utf8_bin default null, 606 primary_contact tinyint(4) not null default '0', 607 email_opt_in tinyint(4) not null default '1', 608 primary key (id), unique key email (email), key t1_id (t1_id), 609 constraint t2_fk1 foreign key (t1_id) references t1 (id) 610); 611 612insert into t1 values 613(1, 'demo', 'demo s', 0, current_date()), 614(2, 'code2', 'name 2', 0, current_date()), 615(3, 'code3', 'name 3', 0, current_date()); 616 617insert into t2 values 618(2, 'email1', 'name1', 3, 'password1', 0, 0), 619(3, 'email2', 'name1', 1, 'password2', 1, 0), 620(5, 'email3', 'name3', 2, 'password3', 0, 0); 621 622prepare stmt from 'select t2.id from t2, t1 where (t1.id=? and t2.t1_id=t1.id)'; 623set @a=1; 624execute stmt using @a; 625 626select t2.id from t2, t1 where (t1.id=1 and t2.t1_id=t1.id); 627 628deallocate prepare stmt; 629drop table t2, t1; 630 631# 632# Bug#11060 "Server crashes on calling stored procedure with INSERT SELECT 633# UNION SELECT" aka "Server crashes on re-execution of prepared INSERT ... 634# SELECT with UNION". 635# 636create table t1 (id int); 637prepare stmt from "insert into t1 (id) select id from t1 union select id from t1"; 638execute stmt; 639execute stmt; 640deallocate prepare stmt; 641drop table t1; 642# 643# Bug#11458 "Prepared statement with subselects return random data": 644# drop PARAM_TABLE_BIT from the list of tables used by a subquery 645# 646create table t1 ( 647 id int(11) unsigned not null primary key auto_increment, 648 partner_id varchar(35) not null, 649 t1_status_id int(10) unsigned 650); 651 652insert into t1 values ("1", "partner1", "10"), ("2", "partner2", "10"), 653 ("3", "partner3", "10"), ("4", "partner4", "10"); 654 655create table t2 ( 656 id int(11) unsigned not null default '0', 657 t1_line_id int(11) unsigned not null default '0', 658 article_id varchar(20), 659 sequence int(11) not null default '0', 660 primary key (id,t1_line_id) 661); 662 663insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"), 664 ("2", "2", "sup", "2"), ("2", "3", "sup", "3"), 665 ("2", "4", "imp", "4"), ("3", "1", "sup", "0"), 666 ("4", "1", "sup", "0"); 667 668create table t3 ( 669 id int(11) not null default '0', 670 preceding_id int(11) not null default '0', 671 primary key (id,preceding_id) 672); 673 674create table t4 ( 675 user_id varchar(50) not null, 676 article_id varchar(20) not null, 677 primary key (user_id,article_id) 678); 679 680insert into t4 values("nicke", "imp"); 681 682prepare stmt from 683'select distinct t1.partner_id 684from t1 left join t3 on t1.id = t3.id 685 left join t1 pp on pp.id = t3.preceding_id 686where 687 exists ( 688 select * 689 from t2 as pl_inner 690 where pl_inner.id = t1.id 691 and pl_inner.sequence <= ( 692 select min(sequence) from t2 pl_seqnr 693 where pl_seqnr.id = t1.id 694 ) 695 and exists ( 696 select * from t4 697 where t4.article_id = pl_inner.article_id 698 and t4.user_id = ? 699 ) 700 ) 701 and t1.id = ? 702group by t1.id 703having count(pp.id) = 0'; 704set @user_id = 'nicke'; 705set @id = '2'; 706execute stmt using @user_id, @id; 707execute stmt using @user_id, @id; 708deallocate prepare stmt; 709drop table t1, t2, t3, t4; 710# 711# Bug#9379: make sure that Item::collation is reset when one sets 712# a parameter marker from a string variable. 713# 714prepare stmt from 'select ?=?'; 715set @a='CHRISTINE '; 716set @b='CHRISTINE'; 717execute stmt using @a, @b; 718execute stmt using @a, @b; 719set @a=1, @b=2; 720execute stmt using @a, @b; 721set @a='CHRISTINE '; 722set @b='CHRISTINE'; 723execute stmt using @a, @b; 724deallocate prepare stmt; 725# 726# Bug#11299 "prepared statement makes wrong SQL syntax in binlog which stops 727# replication": check that errouneous queries with placeholders are not 728# allowed 729# 730create table t1 (a int); 731--error 1064 732prepare stmt from "select ??"; 733--error 1064 734prepare stmt from "select ?FROM t1"; 735--error 1064 736prepare stmt from "select FROM t1 WHERE?=1"; 737--error 1064 738prepare stmt from "update t1 set a=a+?WHERE 1"; 739--disable_ps_protocol 740--error 1064 741select ?; 742--error 1064 743select ??; 744--error 1064 745select ? from t1; 746--enable_ps_protocol 747drop table t1; 748# 749# Bug#9359 "Prepared statements take snapshot of system vars at PREPARE 750# time" 751# 752prepare stmt from "select @@time_zone"; 753execute stmt; 754set @@time_zone:='Japan'; 755execute stmt; 756prepare stmt from "select @@tx_isolation"; 757execute stmt; 758set transaction isolation level read committed; 759execute stmt; 760set transaction isolation level serializable; 761execute stmt; 762set @@tx_isolation=default; 763execute stmt; 764deallocate prepare stmt; 765 766# 767# Bug#14410 "Crash in Enum or Set type in CREATE TABLE and PS/SP" 768# 769# Part I. Make sure the typelib for ENUM is created in the statement memory 770# root. 771prepare stmt from "create temporary table t1 (letter enum('','a','b','c') 772not null)"; 773execute stmt; 774drop table t1; 775execute stmt; 776drop table t1; 777execute stmt; 778drop table t1; 779# Part II. Make sure that when the default value is converted to UTF-8, 780# the new item is # created in the statement memory root. 781set names latin1; 782prepare stmt from "create table t1 (a enum('test') default 'test') 783 character set utf8"; 784execute stmt; 785drop table t1; 786execute stmt; 787drop table t1; 788execute stmt; 789drop table t1; 790# Cleanup 791set names default; 792deallocate prepare stmt; 793 794# 795# A test case for Bug#12734 "prepared statement may return incorrect result 796# set for a select SQL request": test that canDoTurboBM is reset for each 797# execute of a prepared statement. 798# 799create table t1 ( 800 word_id mediumint(8) unsigned not null default '0', 801 formatted varchar(20) not null default '' 802); 803 804insert into t1 values 805 (80,'pendant'), (475,'pretendants'), (989,'tendances'), 806 (1019,'cependant'),(1022,'abondance'),(1205,'independants'), 807 (13,'lessiver'),(25,'lambiner'),(46,'situer'),(71,'terminer'), 808 (82,'decrocher'); 809 810select count(*) from t1 where formatted like '%NDAN%'; 811select count(*) from t1 where formatted like '%ER'; 812prepare stmt from "select count(*) from t1 where formatted like ?"; 813set @like="%NDAN%"; 814execute stmt using @like; 815set @like="%ER"; 816execute stmt using @like; 817set @like="%NDAN%"; 818execute stmt using @like; 819set @like="%ER"; 820execute stmt using @like; 821deallocate prepare stmt; 822drop table t1; 823 824# 825# Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is 826# recreated with PS/SP" 827# 828SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; 829prepare stmt from 'create table t1 (a varchar(10) character set utf8)'; 830execute stmt; 831--disable_warnings ONCE 832insert into t1 (a) values (repeat('a', 20)); 833select length(a) from t1; 834drop table t1; 835execute stmt; 836--disable_warnings ONCE 837insert into t1 (a) values (repeat('a', 20)); 838# Check that the data is truncated to the same length 839select length(a) from t1; 840drop table t1; 841deallocate prepare stmt; 842SET sql_mode = default; 843# 844# Bug#16248 "WHERE (col1,col2) IN ((?,?)) gives wrong results": 845# check that ROW implementation is reexecution-friendly. 846# 847create table t1 (col1 integer, col2 integer); 848insert into t1 values(100,100),(101,101),(102,102),(103,103); 849prepare stmt from 'select col1, col2 from t1 where (col1, col2) in ((?,?))'; 850set @a=100, @b=100; 851execute stmt using @a,@b; 852set @a=101, @b=101; 853execute stmt using @a,@b; 854set @a=102, @b=102; 855execute stmt using @a,@b; 856set @a=102, @b=103; 857execute stmt using @a,@b; 858deallocate prepare stmt; 859drop table t1; 860 861# 862# Bug#16365 Prepared Statements: DoS with too many open statements 863# Check that the limit @@max_prpeared_stmt_count works. 864# 865# This is also the test for bug#23159 prepared_stmt_count should be 866# status variable. 867# 868# Save the old value 869set @old_max_prepared_stmt_count= @@max_prepared_stmt_count; 870# 871# Disable prepared statement protocol: in this test we set 872# @@max_prepared_stmt_count to 0 or 1 and would like to test the limit 873# manually. 874# 875--disable_ps_protocol 876# 877# A. Check that the new variables are present in SHOW VARIABLES and 878# SHOW STATUS lists. 879# 880show variables like 'max_prepared_stmt_count'; 881show status like 'prepared_stmt_count'; 882# 883# B. Check that the new system variable is selectable. 884# 885select @@max_prepared_stmt_count; 886# 887# C. Check that max_prepared_stmt_count is settable (global only). 888# 889set global max_prepared_stmt_count=-1; 890select @@max_prepared_stmt_count; 891set global max_prepared_stmt_count=10000000000000000; 892select @@max_prepared_stmt_count; 893set global max_prepared_stmt_count=default; 894select @@max_prepared_stmt_count; 895--error ER_GLOBAL_VARIABLE 896set @@max_prepared_stmt_count=1; 897--error ER_GLOBAL_VARIABLE 898set max_prepared_stmt_count=1; 899--error ER_GLOBAL_VARIABLE 900set local max_prepared_stmt_count=1; 901# set to a reasonable limit works 902set global max_prepared_stmt_count=1; 903select @@max_prepared_stmt_count; 904# 905# D. Check that the variables actually work. 906# 907set global max_prepared_stmt_count=0; 908select @@max_prepared_stmt_count; 909show status like 'prepared_stmt_count'; 910--error ER_MAX_PREPARED_STMT_COUNT_REACHED 911prepare stmt from "select 1"; 912show status like 'prepared_stmt_count'; 913set global max_prepared_stmt_count=1; 914prepare stmt from "select 1"; 915show status like 'prepared_stmt_count'; 916--error ER_MAX_PREPARED_STMT_COUNT_REACHED 917prepare stmt1 from "select 1"; 918show status like 'prepared_stmt_count'; 919deallocate prepare stmt; 920show status like 'prepared_stmt_count'; 921# 922# E. Check that we can prepare a statement with the same name 923# successfully, without hitting the limit. 924# 925prepare stmt from "select 1"; 926show status like 'prepared_stmt_count'; 927prepare stmt from "select 2"; 928show status like 'prepared_stmt_count'; 929# 930# F. We can set the max below the current count. In this case no new 931# statements should be allowed to prepare. 932# 933show status like 'prepared_stmt_count'; 934select @@max_prepared_stmt_count; 935set global max_prepared_stmt_count=0; 936--error ER_MAX_PREPARED_STMT_COUNT_REACHED 937prepare stmt from "select 1"; 938# Result: the old statement is deallocated, the new is not created. 939--error ER_UNKNOWN_STMT_HANDLER 940execute stmt; 941show status like 'prepared_stmt_count'; 942--error ER_MAX_PREPARED_STMT_COUNT_REACHED 943prepare stmt from "select 1"; 944show status like 'prepared_stmt_count'; 945# 946# G. Show that the variables are up to date even after a connection with all 947# statements in it was terminated. 948# 949set global max_prepared_stmt_count=3; 950select @@max_prepared_stmt_count; 951show status like 'prepared_stmt_count'; 952prepare stmt from "select 1"; 953 954connect (con1,localhost,root,,); 955 956# Switch to connection con1 957connection con1; 958let $con1_id=`SELECT CONNECTION_ID()`; 959 960prepare stmt from "select 2"; 961prepare stmt1 from "select 3"; 962--error ER_MAX_PREPARED_STMT_COUNT_REACHED 963prepare stmt2 from "select 4"; 964connection default; 965--error ER_MAX_PREPARED_STMT_COUNT_REACHED 966prepare stmt2 from "select 4"; 967select @@max_prepared_stmt_count; 968show status like 'prepared_stmt_count'; 969 970# Disconnect connection con1 and switch to default connection 971disconnect con1; 972connection default; 973 974# Wait for the connection con1 to die 975let $wait_condition=SELECT COUNT(*)=0 FROM information_schema.processlist WHERE id=$con1_id; 976--source include/wait_condition.inc 977 978deallocate prepare stmt; 979 980select @@max_prepared_stmt_count; 981show status like 'prepared_stmt_count'; 982# 983# Restore the old value. 984# 985set global max_prepared_stmt_count= @old_max_prepared_stmt_count; 986--enable_ps_protocol 987 988 989# 990# Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating 991# tables" 992# Check that multi-delete tables are also cleaned up before re-execution. 993# 994--disable_warnings 995drop table if exists t1; 996create temporary table if not exists t1 (a1 int); 997--enable_warnings 998# exact delete syntax is essential 999prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1"; 1000drop temporary table t1; 1001create temporary table if not exists t1 (a1 int); 1002# the server crashed on the next statement without the fix 1003execute stmt; 1004drop temporary table t1; 1005create temporary table if not exists t1 (a1 int); 1006# the problem was in memory corruption: repeat the test just in case 1007execute stmt; 1008drop temporary table t1; 1009create temporary table if not exists t1 (a1 int); 1010execute stmt; 1011drop temporary table t1; 1012deallocate prepare stmt; 1013 1014 1015# 1016# BUG#22085: Crash on the execution of a prepared statement that 1017# uses an IN subquery with aggregate functions in HAVING 1018# 1019 1020CREATE TABLE t1( 1021 ID int(10) unsigned NOT NULL auto_increment, 1022 Member_ID varchar(15) NOT NULL default '', 1023 Action varchar(12) NOT NULL, 1024 Action_Date datetime NOT NULL, 1025 Track varchar(15) default NULL, 1026 User varchar(12) default NULL, 1027 Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update 1028 CURRENT_TIMESTAMP, 1029 PRIMARY KEY (ID), 1030 KEY Action (Action), 1031 KEY Action_Date (Action_Date) 1032); 1033 1034INSERT INTO t1(Member_ID, Action, Action_Date, Track) VALUES 1035 ('111111', 'Disenrolled', '2006-03-01', 'CAD' ), 1036 ('111111', 'Enrolled', '2006-03-01', 'CAD' ), 1037 ('111111', 'Disenrolled', '2006-07-03', 'CAD' ), 1038 ('222222', 'Enrolled', '2006-03-07', 'CAD' ), 1039 ('222222', 'Enrolled', '2006-03-07', 'CHF' ), 1040 ('222222', 'Disenrolled', '2006-08-02', 'CHF' ), 1041 ('333333', 'Enrolled', '2006-03-01', 'CAD' ), 1042 ('333333', 'Disenrolled', '2006-03-01', 'CAD' ), 1043 ('444444', 'Enrolled', '2006-03-01', 'CAD' ), 1044 ('555555', 'Disenrolled', '2006-03-01', 'CAD' ), 1045 ('555555', 'Enrolled', '2006-07-21', 'CAD' ), 1046 ('555555', 'Disenrolled', '2006-03-01', 'CHF' ), 1047 ('666666', 'Enrolled', '2006-02-09', 'CAD' ), 1048 ('666666', 'Enrolled', '2006-05-12', 'CHF' ), 1049 ('666666', 'Disenrolled', '2006-06-01', 'CAD' ); 1050 1051PREPARE STMT FROM 1052"SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t1 1053 WHERE Member_ID=? AND Action='Enrolled' AND 1054 (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t1 1055 WHERE Member_ID=? 1056 GROUP BY Track 1057 HAVING Track>='CAD' AND 1058 MAX(Action_Date)>'2006-03-01')"; 1059SET @id='111111'; 1060EXECUTE STMT USING @id,@id; 1061SET @id='222222'; 1062EXECUTE STMT USING @id,@id; 1063 1064DEALLOCATE PREPARE STMT; 1065DROP TABLE t1; 1066 1067# 1068# BUG#21354: (COUNT(*) = 1) not working in SELECT inside prepared 1069# statement 1070# 1071--disable_warnings 1072DROP TABLE IF EXISTS t1; 1073--enable_warnings 1074 1075CREATE TABLE t1 (i INT, INDEX(i)); 1076INSERT INTO t1 VALUES (1); 1077 1078PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?"; 1079SET @a = 0; 1080EXECUTE stmt USING @a; 1081SET @a = 1; 1082EXECUTE stmt USING @a; 1083SET @a = 0; 1084EXECUTE stmt USING @a; 1085 1086PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?"; 1087SET @a = 0; 1088EXECUTE stmt USING @a; 1089SET @a = 1; 1090EXECUTE stmt USING @a; 1091SET @a = 0; 1092EXECUTE stmt USING @a; 1093 1094PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?"; 1095SET @a = 0; 1096EXECUTE stmt USING @a; 1097SET @a = 1; 1098EXECUTE stmt USING @a; 1099SET @a = 0; 1100EXECUTE stmt USING @a; 1101 1102PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?"; 1103SET @a = 0; 1104EXECUTE stmt USING @a; 1105SET @a = 1; 1106EXECUTE stmt USING @a; 1107SET @a = 0; 1108EXECUTE stmt USING @a; 1109 1110PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?"; 1111SET @a = 0; 1112EXECUTE stmt USING @a; 1113SET @a = 1; 1114EXECUTE stmt USING @a; 1115SET @a = 0; 1116EXECUTE stmt USING @a; 1117 1118PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?"; 1119SET @a = 0; 1120EXECUTE stmt USING @a; 1121SET @a = 1; 1122EXECUTE stmt USING @a; 1123SET @a = 0; 1124EXECUTE stmt USING @a; 1125 1126PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?"; 1127SET @a = 0; 1128EXECUTE stmt USING @a; 1129SET @a = 1; 1130EXECUTE stmt USING @a; 1131SET @a = 0; 1132EXECUTE stmt USING @a; 1133 1134DEALLOCATE PREPARE stmt; 1135DROP TABLE t1; 1136 1137# 1138# Bug#19182: CREATE TABLE bar (m INT) SELECT n FROM foo; doesn't work 1139# from stored procedure. 1140# 1141# The cause of a bug was that cached LEX::create_list was modified, 1142# and then together with LEX::key_list was reset. 1143# 1144--disable_warnings ONCE 1145DROP TABLE IF EXISTS t1, t2; 1146 1147CREATE TABLE t1 (i INT); 1148 1149PREPARE st_19182 1150FROM "CREATE TABLE t2 (i INT, j INT, KEY (i), KEY(j)) SELECT i FROM t1"; 1151 1152EXECUTE st_19182; 1153DESC t2; 1154 1155DROP TABLE t2; 1156 1157# Check that on second execution we don't loose 'j' column and the keys 1158# on 'i' and 'j' columns. 1159EXECUTE st_19182; 1160DESC t2; 1161 1162DEALLOCATE PREPARE st_19182; 1163DROP TABLE t2, t1; 1164 1165# 1166# Bug #22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server" 1167# 1168# Code which implemented CREATE/ALTER TABLE and CREATE DATABASE 1169# statement modified HA_CREATE_INFO structure in LEX, making these 1170# statements PS/SP-unsafe (their re-execution might have resulted 1171# in incorrect results). 1172# 1173--disable_warnings 1174drop database if exists mysqltest; 1175drop table if exists t1, t2; 1176--enable_warnings 1177# CREATE TABLE and CREATE TABLE ... SELECT 1178create database mysqltest character set utf8; 1179prepare stmt1 from "create table mysqltest.t1 (c char(10))"; 1180prepare stmt2 from "create table mysqltest.t2 select 'test'"; 1181execute stmt1; 1182--disable_warnings ONCE 1183execute stmt2; 1184show create table mysqltest.t1; 1185show create table mysqltest.t2; 1186drop table mysqltest.t1; 1187drop table mysqltest.t2; 1188alter database mysqltest character set latin1; 1189execute stmt1; 1190--disable_warnings ONCE 1191execute stmt2; 1192show create table mysqltest.t1; 1193show create table mysqltest.t2; 1194drop database mysqltest; 1195deallocate prepare stmt1; 1196deallocate prepare stmt2; 1197# 1198# CREATE TABLE with DATA DIRECTORY option 1199# 1200--disable_warnings 1201--disable_query_log ONCE 1202eval prepare stmt from "create table t1 (c char(10)) data directory='$MYSQLTEST_VARDIR/tmp'"; 1203execute stmt; 1204# 1205# DATA DIRECTORY option does not always work: if the operating 1206# system does not support symlinks, have_symlinks option is automatically 1207# disabled. 1208# In this case DATA DIRECTORY is silently ignored when 1209# creating a table, and is not output by SHOW CREATE TABLE. 1210# 1211--disable_result_log ONCE 1212show create table t1; 1213drop table t1; 1214execute stmt; 1215--disable_result_log ONCE 1216show create table t1; 1217drop table t1; 1218deallocate prepare stmt; 1219# 1220 1221# 1222# Bug #27937: crash on the second execution for prepared statement 1223# from UNION with ORDER BY an expression containing RAND() 1224# 1225 1226CREATE TABLE t1(a int); 1227INSERT INTO t1 VALUES (2), (3), (1); 1228 1229PREPARE st1 FROM 1230 '(SELECT a FROM t1) UNION (SELECT a+10 FROM t1) ORDER BY RAND()*0+a'; 1231 1232EXECUTE st1; 1233EXECUTE st1; 1234 1235DEALLOCATE PREPARE st1; 1236DROP TABLE t1; 1237 1238 1239# 1240# Bug #32137: prepared statement crash with str_to_date in update clause 1241# 1242create table t1 (a int, b tinyint); 1243prepare st1 from 'update t1 set b= (str_to_date(a, a))'; 1244execute st1; 1245deallocate prepare st1; 1246drop table t1; 1247 1248--echo End of 4.1 tests. 1249 1250############################# 5.0 tests start ################################ 1251# 1252# 1253# Bug#6102 "Server crash with prepared statement and blank after 1254# function name" 1255# ensure that stored functions are cached when preparing a statement 1256# before we open tables 1257# 1258create table t1 (a varchar(20)); 1259insert into t1 values ('foo'); 1260prepare stmt FROM 'SELECT char_length (a) FROM t1'; 1261-- error ER_SP_DOES_NOT_EXIST 1262prepare stmt2 FROM 'SELECT not_a_function (a) FROM t1'; 1263drop table t1; 1264 1265# 1266# Bug#8115: equality propagation and prepared statements 1267# 1268 1269create table t1 (a char(3) not null, b char(3) not null, 1270 c char(3) not null, primary key (a, b, c)); 1271create table t2 like t1; 1272 1273# reduced query 1274prepare stmt from 1275 "select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) 1276 where t1.a=1"; 1277execute stmt; 1278execute stmt; 1279execute stmt; 1280 1281# original query 1282prepare stmt from 1283"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from 1284(t1 left outer join t2 on t2.a=? and t1.b=t2.b) 1285left outer join t2 t3 on t3.a=? where t1.a=?"; 1286 1287set @a:=1, @b:=1, @c:=1; 1288 1289execute stmt using @a, @b, @c; 1290execute stmt using @a, @b, @c; 1291execute stmt using @a, @b, @c; 1292 1293deallocate prepare stmt; 1294 1295drop table t1,t2; 1296 1297 1298# 1299# Bug#9383: INFORMATION_SCHEMA.COLUMNS, JOIN, Crash, prepared statement 1300# 1301 1302eval SET @aux= "SELECT COUNT(*) 1303 FROM INFORMATION_SCHEMA.COLUMNS A, 1304 INFORMATION_SCHEMA.COLUMNS B 1305 WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA 1306 AND A.TABLE_NAME = B.TABLE_NAME 1307 AND A.COLUMN_NAME = B.COLUMN_NAME AND 1308 A.TABLE_NAME = 'user'"; 1309 1310let $exec_loop_count= 3; 1311eval prepare my_stmt from @aux; 1312while ($exec_loop_count) 1313{ 1314 eval execute my_stmt; 1315 dec $exec_loop_count; 1316} 1317deallocate prepare my_stmt; 1318 1319# Test CALL in prepared mode 1320delimiter |; 1321--disable_warnings 1322drop procedure if exists p1| 1323drop table if exists t1| 1324--enable_warnings 1325create table t1 (id int)| 1326insert into t1 values(1)| 1327create procedure p1(a int, b int) 1328begin 1329 declare c int; 1330 select max(id)+1 into c from t1; 1331 insert into t1 select a+b; 1332 insert into t1 select a-b; 1333 insert into t1 select a-c; 1334end| 1335set @a= 3, @b= 4| 1336prepare stmt from "call p1(?, ?)"| 1337execute stmt using @a, @b| 1338execute stmt using @a, @b| 1339select * from t1| 1340deallocate prepare stmt| 1341drop procedure p1| 1342drop table t1| 1343delimiter ;| 1344 1345 1346# 1347# Bug#7306 LIMIT ?, ? and also WL#1785 " Prepared statements: implement 1348# support for placeholders in LIMIT clause." 1349# Add basic test coverage for the feature. 1350# 1351create table t1 (a int); 1352insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); 1353prepare stmt from "select * from t1 limit ?, ?"; 1354set @offset=0, @limit=1; 1355execute stmt using @offset, @limit; 1356select * from t1 limit 0, 1; 1357set @offset=3, @limit=2; 1358execute stmt using @offset, @limit; 1359select * from t1 limit 3, 2; 1360prepare stmt from "select * from t1 limit ?"; 1361execute stmt using @limit; 1362--error 1235 1363prepare stmt from "select * from t1 where a in (select a from t1 limit ?)"; 1364prepare stmt from "select * from t1 union all select * from t1 limit ?, ?"; 1365set @offset=9; 1366set @limit=2; 1367execute stmt using @offset, @limit; 1368prepare stmt from "(select * from t1 limit ?, ?) union all 1369 (select * from t1 limit ?, ?) order by a limit ?"; 1370execute stmt using @offset, @limit, @offset, @limit, @limit; 1371 1372drop table t1; 1373deallocate prepare stmt; 1374 1375# 1376# Bug#12651 1377# (Crash on a PS including a subquery which is a select from a simple view) 1378# 1379CREATE TABLE b12651_T1(a int) ENGINE=MYISAM; 1380CREATE TABLE b12651_T2(b int) ENGINE=MYISAM; 1381CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2; 1382 1383PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)'; 1384EXECUTE b12651; 1385 1386DROP VIEW b12651_V1; 1387DROP TABLE b12651_T1, b12651_T2; 1388DEALLOCATE PREPARE b12651; 1389 1390 1391 1392# 1393# Bug #14956: ROW_COUNT() returns incorrect result after EXECUTE of prepared 1394# statement 1395# 1396create table t1 (id int); 1397prepare ins_call from "insert into t1 (id) values (1)"; 1398execute ins_call; 1399select row_count(); 1400drop table t1; 1401 1402# 1403# BUG#16474: SP crashed MySQL 1404# (when using "order by localvar", where 'localvar' is just that. 1405# The actual bug test is in sp.test, this is just testing that we get the 1406# expected result for prepared statements too, i.e. place holders work as 1407# textual substitution. If it's a single integer, it works as the (deprecated) 1408# "order by column#", otherwise it's an expression. 1409# 1410create table t1 (a int, b int); 1411insert into t1 (a,b) values (2,8),(1,9),(3,7); 1412 1413# Will order by index 1414prepare stmt from "select * from t1 order by ?"; 1415set @a=NULL; 1416execute stmt using @a; 1417set @a=1; 1418execute stmt using @a; 1419set @a=2; 1420execute stmt using @a; 1421deallocate prepare stmt; 1422# For reference: 1423select * from t1 order by 1; 1424 1425# Will not order by index. 1426prepare stmt from "select * from t1 order by ?+1"; 1427set @a=0; 1428execute stmt using @a; 1429set @a=1; 1430execute stmt using @a; 1431deallocate prepare stmt; 1432# For reference: 1433select * from t1 order by 1+1; 1434 1435drop table t1; 1436 1437# 1438# Bug#19308 "REPAIR/OPTIMIZE/ANALYZE supported in SP but not in PS". 1439# Add test coverage for the added commands. 1440# 1441create table t1 (a int) engine=myisam; 1442create table t2 like t1; 1443create table t3 like t2; 1444prepare stmt from "repair table t1"; 1445execute stmt; 1446execute stmt; 1447prepare stmt from "optimize table t1"; 1448execute stmt; 1449execute stmt; 1450prepare stmt from "analyze table t1"; 1451execute stmt; 1452execute stmt; 1453prepare stmt from "repair table t1, t2, t3"; 1454execute stmt; 1455execute stmt; 1456prepare stmt from "optimize table t1, t2, t3"; 1457execute stmt; 1458execute stmt; 1459prepare stmt from "analyze table t1, t2, t3"; 1460execute stmt; 1461execute stmt; 1462prepare stmt from "repair table t1, t4, t3"; 1463execute stmt; 1464execute stmt; 1465prepare stmt from "optimize table t1, t3, t4"; 1466execute stmt; 1467execute stmt; 1468prepare stmt from "analyze table t4, t1"; 1469execute stmt; 1470execute stmt; 1471deallocate prepare stmt; 1472drop table t1, t2, t3; 1473 1474# 1475# Bug#17199 "Table not found" error occurs if the query contains a call 1476# to a function from another database. 1477# Test prepared statements- related behaviour. 1478# 1479# 1480# ALTER TABLE RENAME and Prepared Statements: wrong DB name buffer was used 1481# in ALTER ... RENAME which caused memory corruption in prepared statements. 1482# No need to fix this problem in 4.1 as ALTER TABLE is not allowed in 1483# Prepared Statements in 4.1. 1484# 1485create database mysqltest_long_database_name_to_thrash_heap; 1486use test; 1487create table t1 (i int); 1488prepare stmt from "alter table test.t1 rename t1"; 1489use mysqltest_long_database_name_to_thrash_heap; 1490execute stmt; 1491show tables like 't1'; 1492prepare stmt from "alter table test.t1 rename t1"; 1493use test; 1494execute stmt; 1495show tables like 't1'; 1496use mysqltest_long_database_name_to_thrash_heap; 1497show tables like 't1'; 1498deallocate prepare stmt; 1499# 1500# Check that a prepared statement initializes its current database at 1501# PREPARE, and then works correctly even if the current database has been 1502# changed. 1503# 1504use mysqltest_long_database_name_to_thrash_heap; 1505# Necessary for preparation of INSERT/UPDATE/DELETE to succeed 1506prepare stmt_create from "create table t1 (i int)"; 1507prepare stmt_insert from "insert into t1 (i) values (1)"; 1508prepare stmt_update from "update t1 set i=2"; 1509prepare stmt_delete from "delete from t1 where i=2"; 1510prepare stmt_select from "select * from t1"; 1511prepare stmt_alter from "alter table t1 add column (b int)"; 1512prepare stmt_alter1 from "alter table t1 drop column b"; 1513prepare stmt_analyze from "analyze table t1"; 1514prepare stmt_optimize from "optimize table t1"; 1515prepare stmt_show from "show tables like 't1'"; 1516prepare stmt_truncate from "truncate table t1"; 1517prepare stmt_drop from "drop table t1"; 1518# Drop the table that was used to prepare INSERT/UPDATE/DELETE: we will 1519# create a new one by executing stmt_create 1520drop table t1; 1521# Switch the current database 1522use test; 1523# Check that all prepared statements operate on the database that was 1524# active at PREPARE 1525execute stmt_create; 1526# should return empty set 1527show tables like 't1'; 1528use mysqltest_long_database_name_to_thrash_heap; 1529show tables like 't1'; 1530use test; 1531execute stmt_insert; 1532select * from mysqltest_long_database_name_to_thrash_heap.t1; 1533execute stmt_update; 1534select * from mysqltest_long_database_name_to_thrash_heap.t1; 1535execute stmt_delete; 1536execute stmt_select; 1537execute stmt_alter; 1538show columns from mysqltest_long_database_name_to_thrash_heap.t1; 1539execute stmt_alter1; 1540show columns from mysqltest_long_database_name_to_thrash_heap.t1; 1541execute stmt_analyze; 1542execute stmt_optimize; 1543execute stmt_show; 1544execute stmt_truncate; 1545execute stmt_drop; 1546show tables like 't1'; 1547use mysqltest_long_database_name_to_thrash_heap; 1548show tables like 't1'; 1549# 1550# Attempt a statement PREPARE when there is no current database: 1551# is expected to return an error. 1552# 1553drop database mysqltest_long_database_name_to_thrash_heap; 1554--error ER_NO_DB_ERROR 1555prepare stmt_create from "create table t1 (i int)"; 1556--error ER_NO_DB_ERROR 1557prepare stmt_insert from "insert into t1 (i) values (1)"; 1558--error ER_NO_DB_ERROR 1559prepare stmt_update from "update t1 set i=2"; 1560--error ER_NO_DB_ERROR 1561prepare stmt_delete from "delete from t1 where i=2"; 1562--error ER_NO_DB_ERROR 1563prepare stmt_select from "select * from t1"; 1564--error ER_NO_DB_ERROR 1565prepare stmt_alter from "alter table t1 add column (b int)"; 1566--error ER_NO_DB_ERROR 1567prepare stmt_alter1 from "alter table t1 drop column b"; 1568--error ER_NO_DB_ERROR 1569prepare stmt_analyze from "analyze table t1"; 1570--error ER_NO_DB_ERROR 1571prepare stmt_optimize from "optimize table t1"; 1572--error ER_NO_DB_ERROR 1573prepare stmt_show from "show tables like 't1'"; 1574--error ER_NO_DB_ERROR 1575prepare stmt_truncate from "truncate table t1"; 1576--error ER_NO_DB_ERROR 1577prepare stmt_drop from "drop table t1"; 1578# 1579# The above has automatically deallocated all our statements. 1580# 1581# Attempt to CREATE a temporary table when no DB used: it should fail 1582# This proves that no table can be used without explicit specification of 1583# its database if there is no current database. 1584# 1585--error ER_NO_DB_ERROR 1586create temporary table t1 (i int); 1587# 1588# Restore the old environemnt 1589# 1590use test; 1591 1592 1593# 1594# BUG#21166: Prepared statement causes signal 11 on second execution 1595# 1596# Changes in an item tree done by optimizer weren't properly 1597# registered and went unnoticed, which resulted in preliminary freeing 1598# of used memory. 1599# 1600--disable_warnings ONCE 1601DROP TABLE IF EXISTS t1, t2, t3; 1602 1603CREATE TABLE t1 (i BIGINT, j BIGINT); 1604CREATE TABLE t2 (i BIGINT); 1605CREATE TABLE t3 (i BIGINT, j BIGINT); 1606 1607PREPARE 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 = ?"; 1610 1611SET @a= 1; 1612EXECUTE stmt USING @a; 1613EXECUTE stmt USING @a; 1614 1615DEALLOCATE PREPARE stmt; 1616DROP TABLE IF EXISTS t1, t2, t3; 1617 1618 1619# 1620# BUG#21081: SELECT inside stored procedure returns wrong results 1621# 1622--disable_warnings ONCE 1623DROP TABLE IF EXISTS t1, t2; 1624 1625CREATE TABLE t1 (i INT KEY); 1626CREATE TABLE t2 (i INT); 1627 1628INSERT INTO t1 VALUES (1), (2); 1629INSERT INTO t2 VALUES (1); 1630 1631PREPARE stmt FROM "SELECT t2.i FROM t1 LEFT JOIN t2 ON t2.i = t1.i 1632 WHERE t1.i = ?"; 1633 1634SET @arg= 1; 1635EXECUTE stmt USING @arg; 1636SET @arg= 2; 1637EXECUTE stmt USING @arg; 1638SET @arg= 1; 1639EXECUTE stmt USING @arg; 1640 1641DEALLOCATE PREPARE stmt; 1642DROP TABLE t1, t2; 1643 1644 1645# 1646# BUG#20327: Marking of a wrong field leads to a wrong result on select with 1647# view, prepared statement and subquery. 1648# 1649CREATE TABLE t1 (i INT); 1650CREATE VIEW v1 AS SELECT * FROM t1; 1651 1652INSERT INTO t1 VALUES (1), (2); 1653 1654let $query = SELECT t1.i FROM t1 JOIN v1 ON t1.i = v1.i 1655 WHERE EXISTS (SELECT * FROM t1 WHERE v1.i = 1); 1656eval $query; 1657eval PREPARE stmt FROM "$query"; 1658# Statement execution should return '1'. 1659EXECUTE stmt; 1660# Check re-execution. 1661EXECUTE stmt; 1662 1663DEALLOCATE PREPARE stmt; 1664DROP VIEW v1; 1665DROP TABLE t1; 1666 1667 1668# 1669# BUG#21856: Prepared Statments: crash if bad create 1670# 1671--disable_warnings ONCE 1672DROP PROCEDURE IF EXISTS p1; 1673 1674let $iterations= 100; 1675--disable_query_log 1676--disable_result_log 1677while ($iterations) 1678{ 1679 --error ER_PARSE_ERROR 1680 PREPARE stmt FROM "CREATE PROCEDURE p1()"; 1681 dec $iterations; 1682} 1683--enable_query_log 1684--enable_result_log 1685 1686# 1687# Bug 19764: SHOW commands end up in the slow log as table scans 1688# 1689 1690flush status; 1691prepare sq from 'show status like "slow_queries"'; 1692execute sq; 1693prepare no_index from 'select 1 from information_schema.tables limit 1'; 1694execute sq; 1695execute no_index; 1696execute sq; 1697deallocate prepare no_index; 1698deallocate prepare sq; 1699 1700 1701# 1702# Bug 25027: query with a single-row non-correlated subquery 1703# and IS NULL predicate 1704# 1705 1706CREATE TABLE t1 (a int); 1707INSERT INTO t1 VALUES (1), (2); 1708CREATE TABLE t2 (b int); 1709INSERT INTO t2 VALUES (NULL); 1710 1711SELECT a FROM t1 WHERE (SELECT b FROM t2) IS NULL; 1712PREPARE stmt FROM 'SELECT a FROM t1 WHERE (SELECT b FROM t2) IS NULL'; 1713 1714EXECUTE stmt; 1715DEALLOCATE PREPARE stmt; 1716 1717PREPARE stmt FROM 'SELECT a FROM t1 WHERE (SELECT b FROM t2 limit ?) IS NULL'; 1718SET @arg=1; 1719EXECUTE stmt USING @arg; 1720DEALLOCATE PREPARE stmt; 1721 1722DROP TABLE t1,t2; 1723# 1724# Bug#4968 "Stored procedure crash if cursor opened on altered table" 1725# The bug is not repeatable any more after the fix for 1726# Bug#15217 "Bug #15217 Using a SP cursor on a table created with PREPARE 1727# fails with weird error", however ALTER TABLE is not re-execution friendly 1728# and that caused a valgrind warning. Check that the warning is gone. 1729# 1730--disable_warnings ONCE 1731drop table if exists t1; 1732create table t1 (s1 char(20)); 1733prepare stmt from "alter table t1 modify s1 int"; 1734execute stmt; 1735execute stmt; 1736drop table t1; 1737deallocate prepare stmt; 1738 1739# 1740# Bug#6895 "Prepared Statements: ALTER TABLE DROP COLUMN does nothing" 1741# 1742--disable_warnings ONCE 1743drop table if exists t1; 1744create table t1 (a int, b int); 1745prepare s_6895 from "alter table t1 drop column b"; 1746execute s_6895; 1747show columns from t1; 1748drop table t1; 1749create table t1 (a int, b int); 1750execute s_6895; 1751show columns from t1; 1752drop table t1; 1753create table t1 (a int, b int); 1754execute s_6895; 1755show columns from t1; 1756deallocate prepare s_6895; 1757drop table t1; 1758 1759# 1760# Bug #22060 "ALTER TABLE x AUTO_INCREMENT=y in SP crashes server" 1761# 1762# 5.0 part of the test. 1763# 1764 1765# ALTER TABLE 1766create table t1 (i int primary key auto_increment) comment='comment for table t1'; 1767create table t2 (i int, j int, k int); 1768prepare stmt from "alter table t1 auto_increment=100"; 1769execute stmt; 1770show create table t1; 1771# Let us trash table-cache's memory 1772flush tables; 1773select * from t2; 1774execute stmt; 1775show create table t1; 1776deallocate prepare stmt; 1777drop table t1, t2; 1778# 5.1 part of the test. 1779# CREATE DATABASE 1780set @old_character_set_server= @@character_set_server; 1781set @@character_set_server= latin1; 1782prepare stmt from "create database mysqltest_1"; 1783execute stmt; 1784show create database mysqltest_1; 1785drop database mysqltest_1; 1786set @@character_set_server= utf8; 1787execute stmt; 1788show create database mysqltest_1; 1789drop database mysqltest_1; 1790deallocate prepare stmt; 1791set @@character_set_server= @old_character_set_server; 1792 1793 1794# 1795# BUG#24491 "using alias from source table in insert ... on duplicate key" 1796# 1797--disable_warnings ONCE 1798drop tables if exists t1; 1799create table t1 (id int primary key auto_increment, value varchar(10)); 1800insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD'); 1801# Prepare INSERT ... SELECT ... ON DUPLICATE KEY UPDATE statement 1802# which in its ON DUPLICATE KEY clause erroneously tries to assign value 1803# to a column which is mentioned only in SELECT part. This is now caught 1804# during preparation. 1805--error ER_BAD_FIELD_ERROR 1806prepare stmt from "insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP'"; 1807# 1808# And now the same test for more complex case which is more close 1809# to the one that was reported originally. 1810--error ER_BAD_FIELD_ERROR 1811prepare 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'"; 1812drop tables t1; 1813 1814# 1815# Bug #28509: strange behaviour: passing a decimal value to PS 1816# 1817prepare stmt from "create table t1 select ?"; 1818set @a=1.0; 1819execute stmt using @a; 1820show create table t1; 1821drop table t1; 1822 1823# 1824# Bug#33798: prepared statements improperly handle large unsigned ints 1825# 1826--disable_warnings ONCE 1827drop table if exists t1; 1828create table t1 (a bigint unsigned, b bigint(20) unsigned); 1829prepare stmt from "insert into t1 values (?,?)"; 1830set @a= 9999999999999999; 1831set @b= 14632475938453979136; 1832insert into t1 values (@a, @b); 1833select * from t1 where a = @a and b = @b; 1834execute stmt using @a, @b; 1835select * from t1 where a = @a and b = @b; 1836deallocate prepare stmt; 1837drop table t1; 1838 1839# 1840# Bug#32890 Crash after repeated create and drop of tables and views 1841# 1842 1843--disable_warnings 1844drop view if exists v1; 1845drop table if exists t1; 1846--enable_warnings 1847 1848create table t1 (a int, b int); 1849insert into t1 values (1,1), (2,2), (3,3); 1850insert into t1 values (3,1), (1,2), (2,3); 1851 1852prepare stmt from "create view v1 as select * from t1"; 1853execute stmt; 1854drop table t1; 1855create table t1 (a int, b int); 1856drop view v1; 1857execute stmt; 1858show create view v1; 1859drop view v1; 1860 1861prepare stmt from "create view v1 (c,d) as select a,b from t1"; 1862execute stmt; 1863show create view v1; 1864select * from v1; 1865drop view v1; 1866execute stmt; 1867deallocate prepare stmt; 1868show create view v1; 1869select * from v1; 1870drop view v1; 1871 1872prepare stmt from "create view v1 (c) as select b+1 from t1"; 1873execute stmt; 1874show create view v1; 1875select * from v1; 1876drop view v1; 1877execute stmt; 1878deallocate prepare stmt; 1879show create view v1; 1880select * from v1; 1881drop view v1; 1882 1883prepare 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"; 1884execute stmt; 1885show create view v1; 1886select * from v1; 1887drop view v1; 1888execute stmt; 1889deallocate prepare stmt; 1890show create view v1; 1891select * from v1; 1892drop view v1; 1893 1894prepare stmt from "create or replace view v1 as select 1"; 1895execute stmt; 1896show create view v1; 1897select * from v1; 1898execute stmt; 1899show create view v1; 1900deallocate prepare stmt; 1901show create view v1; 1902select * from v1; 1903drop view v1; 1904 1905prepare stmt from "create view v1 as select 1, 1"; 1906execute stmt; 1907show create view v1; 1908select * from v1; 1909drop view v1; 1910execute stmt; 1911deallocate prepare stmt; 1912show create view v1; 1913select * from v1; 1914drop view v1; 1915 1916prepare stmt from "create view v1 (x) as select a from t1 where a > 1"; 1917execute stmt; 1918show create view v1; 1919select * from v1; 1920drop view v1; 1921execute stmt; 1922deallocate prepare stmt; 1923show create view v1; 1924select * from v1; 1925drop view v1; 1926 1927prepare stmt from "create view v1 as select * from `t1` `b`"; 1928execute stmt; 1929show create view v1; 1930select * from v1; 1931drop view v1; 1932execute stmt; 1933deallocate prepare stmt; 1934show create view v1; 1935select * from v1; 1936drop view v1; 1937 1938prepare stmt from "create view v1 (a,b,c) as select * from t1"; 1939--error ER_VIEW_WRONG_LIST 1940execute stmt; 1941--error ER_VIEW_WRONG_LIST 1942execute stmt; 1943deallocate prepare stmt; 1944 1945drop table t1; 1946create temporary table t1 (a int, b int); 1947 1948prepare stmt from "create view v1 as select * from t1"; 1949--error ER_VIEW_SELECT_TMPTABLE 1950execute stmt; 1951--error ER_VIEW_SELECT_TMPTABLE 1952execute stmt; 1953deallocate prepare stmt; 1954 1955drop table t1; 1956 1957--error ER_NO_SUCH_TABLE 1958prepare stmt from "create view v1 as select * from t1"; 1959--error ER_NO_SUCH_TABLE 1960prepare stmt from "create view v1 as select * from `t1` `b`"; 1961 1962# 1963# Bug#33851: Passing UNSIGNED param to EXECUTE returns ERROR 1210 1964# 1965 1966prepare stmt from "select ?"; 1967set @arg= 123456789.987654321; 1968select @arg; 1969execute stmt using @arg; 1970set @arg= "string"; 1971select @arg; 1972execute stmt using @arg; 1973set @arg= 123456; 1974select @arg; 1975execute stmt using @arg; 1976set @arg= cast(-12345.54321 as decimal(20, 10)); 1977select @arg; 1978execute stmt using @arg; 1979deallocate prepare stmt; 1980 1981--echo # 1982--echo # Bug#48508: Crash on prepared statement re-execution. 1983--echo # 1984create table t1(b int); 1985insert into t1 values (0); 1986create view v1 AS select 1 as a from t1 where b; 1987prepare stmt from "select * from v1 where a"; 1988execute stmt; 1989execute stmt; 1990deallocate prepare stmt; 1991drop table t1; 1992drop view v1; 1993 1994create table t1(a bigint); 1995create table t2(b tinyint); 1996insert into t2 values (null); 1997prepare stmt from "select 1 from t1 join t2 on a xor b where b > 1 and a =1"; 1998execute stmt; 1999execute stmt; 2000deallocate prepare stmt; 2001drop table t1,t2; 2002--echo # 2003 2004 2005--echo # 2006--echo # Bug #49570: Assertion failed: !(order->used & map) 2007--echo # on re-execution of prepared statement 2008--echo # 2009CREATE TABLE t1(a INT PRIMARY KEY); 2010INSERT INTO t1 VALUES(0), (1); 2011PREPARE stmt FROM 2012 "SELECT 1 FROM t1 JOIN t1 t2 USING(a) GROUP BY t2.a, t1.a"; 2013EXECUTE stmt; 2014EXECUTE stmt; 2015EXECUTE stmt; 2016DEALLOCATE PREPARE stmt; 2017DROP TABLE t1; 2018 2019 2020--echo End of 5.0 tests. 2021 2022# 2023# Bug #20665: All commands supported in Stored Procedures should work in 2024# Prepared Statements 2025# 2026create procedure proc_1() reset query cache; 2027call proc_1(); 2028call proc_1(); 2029call proc_1(); 2030delimiter |; 2031--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2032create function func_1() returns int deterministic begin reset query cache; return 1; end| 2033create function func_1() returns int deterministic begin call proc_1(); return 1; end| 2034delimiter ;| 2035--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2036select func_1(), func_1(), func_1() from dual; 2037drop function func_1; 2038drop procedure proc_1; 2039prepare abc from "reset query cache"; 2040execute abc; 2041execute abc; 2042execute abc; 2043deallocate prepare abc; 2044 2045 2046create procedure proc_1() reset master; 2047delimiter |; 2048--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2049create function func_1() returns int begin reset master; return 1; end| 2050create function func_1() returns int begin call proc_1(); return 1; end| 2051delimiter ;| 2052--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2053select func_1(), func_1(), func_1() from dual; 2054drop function func_1; 2055drop procedure proc_1; 2056prepare abc from "reset master"; 2057execute abc; 2058execute abc; 2059execute abc; 2060deallocate prepare abc; 2061 2062 2063create procedure proc_1() reset slave; 2064call proc_1(); 2065call proc_1(); 2066call proc_1(); 2067delimiter |; 2068--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2069create function func_1() returns int begin reset slave; return 1; end| 2070create function func_1() returns int begin call proc_1(); return 1; end| 2071delimiter ;| 2072--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2073select func_1(), func_1(), func_1() from dual; 2074drop function func_1; 2075drop procedure proc_1; 2076prepare abc from "reset slave"; 2077execute abc; 2078execute abc; 2079execute abc; 2080deallocate prepare abc; 2081 2082 2083create procedure proc_1(a integer) kill a; 2084--error ER_NO_SUCH_THREAD 2085call proc_1(0); 2086--error ER_NO_SUCH_THREAD 2087call proc_1(0); 2088--error ER_NO_SUCH_THREAD 2089call proc_1(0); 2090drop procedure proc_1; 2091delimiter |; 2092create function func_1() returns int begin kill 0; return 1; end| 2093delimiter ;| 2094--error ER_NO_SUCH_THREAD 2095select func_1() from dual; 2096--error ER_NO_SUCH_THREAD 2097select func_1() from dual; 2098--error ER_NO_SUCH_THREAD 2099select func_1() from dual; 2100drop function func_1; 2101prepare abc from "kill 0"; 2102--error ER_NO_SUCH_THREAD 2103execute abc; 2104--error ER_NO_SUCH_THREAD 2105execute abc; 2106--error ER_NO_SUCH_THREAD 2107execute abc; 2108deallocate prepare abc; 2109 2110 2111create procedure proc_1() flush hosts; 2112call proc_1(); 2113call proc_1(); 2114call proc_1(); 2115call proc_1(); 2116delimiter |; 2117--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2118create function func_1() returns int begin flush hosts; return 1; end| 2119create function func_1() returns int begin call proc_1(); return 1; end| 2120delimiter ;| 2121--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2122select func_1(), func_1(), func_1() from dual; 2123drop function func_1; 2124drop procedure proc_1; 2125prepare abc from "flush hosts"; 2126execute abc; 2127execute abc; 2128execute abc; 2129deallocate prepare abc; 2130 2131 2132create procedure proc_1() flush privileges; 2133call proc_1(); 2134call proc_1(); 2135call proc_1(); 2136delimiter |; 2137--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2138create function func_1() returns int begin flush privileges; return 1; end| 2139create function func_1() returns int begin call proc_1(); return 1; end| 2140delimiter ;| 2141--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2142select func_1(), func_1(), func_1() from dual; 2143drop function func_1; 2144drop procedure proc_1; 2145prepare abc from "flush privileges"; 2146deallocate prepare abc; 2147 2148 2149create procedure proc_1() flush tables with read lock; 2150call proc_1(); 2151unlock tables; 2152call proc_1(); 2153unlock tables; 2154call proc_1(); 2155unlock tables; 2156delimiter |; 2157--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2158create function func_1() returns int begin flush tables with read lock; return 1; end| 2159create function func_1() returns int begin call proc_1(); return 1; end| 2160delimiter ;| 2161--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2162select func_1(), func_1(), func_1() from dual; 2163drop function func_1; 2164drop procedure proc_1; 2165prepare abc from "flush tables with read lock"; 2166execute abc; 2167execute abc; 2168execute abc; 2169deallocate prepare abc; 2170unlock tables; 2171 2172 2173create procedure proc_1() flush tables; 2174call proc_1(); 2175call proc_1(); 2176call proc_1(); 2177delimiter |; 2178--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2179create function func_1() returns int begin flush tables; return 1; end| 2180create function func_1() returns int begin call proc_1(); return 1; end| 2181delimiter ;| 2182--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2183select func_1(), func_1(), func_1() from dual; 2184drop function func_1; 2185drop procedure proc_1; 2186prepare abc from "flush tables"; 2187execute abc; 2188execute abc; 2189execute abc; 2190deallocate prepare abc; 2191 2192 2193create procedure proc_1() flush tables; 2194flush tables; 2195show open tables from mysql; 2196select Host, User from mysql.user limit 0; 2197select Host, Db from mysql.db limit 0; 2198show open tables from mysql; 2199call proc_1(); 2200show open tables from mysql; 2201select Host, User from mysql.user limit 0; 2202select Host, Db from mysql.db limit 0; 2203show open tables from mysql; 2204call proc_1(); 2205show open tables from mysql; 2206select Host, User from mysql.user limit 0; 2207select Host, Db from mysql.db limit 0; 2208show open tables from mysql; 2209call proc_1(); 2210show open tables from mysql; 2211select Host, User from mysql.user limit 0; 2212select Host, Db from mysql.db limit 0; 2213show open tables from mysql; 2214flush tables; 2215delimiter |; 2216--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2217create function func_1() returns int begin flush tables; return 1; end| 2218create function func_1() returns int begin call proc_1(); return 1; end| 2219delimiter ;| 2220--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2221select func_1(), func_1(), func_1() from dual; 2222drop function func_1; 2223drop procedure proc_1; 2224 2225# make the output deterministic: 2226# the order used in SHOW OPEN TABLES 2227# is too much implementation dependent 2228--disable_ps_protocol 2229flush tables; 2230select Host, User from mysql.user limit 0; 2231select Host, Db from mysql.db limit 0; 2232show open tables from mysql; 2233--enable_ps_protocol 2234 2235prepare abc from "flush tables"; 2236execute abc; 2237show open tables from mysql; 2238select Host, User from mysql.user limit 0; 2239select Host, Db from mysql.db limit 0; 2240show open tables from mysql; 2241execute abc; 2242show open tables from mysql; 2243select Host, User from mysql.user limit 0; 2244select Host, Db from mysql.db limit 0; 2245show open tables from mysql; 2246execute abc; 2247show open tables from mysql; 2248select Host, User from mysql.user limit 0; 2249select Host, Db from mysql.db limit 0; 2250show open tables from mysql; 2251flush tables; 2252deallocate prepare abc; 2253 2254 2255create procedure proc_1() flush logs; 2256call proc_1(); 2257call proc_1(); 2258call proc_1(); 2259delimiter |; 2260--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2261create function func_1() returns int begin flush logs; return 1; end| 2262create function func_1() returns int begin call proc_1(); return 1; end| 2263delimiter ;| 2264--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2265select func_1(), func_1(), func_1() from dual; 2266drop function func_1; 2267drop procedure proc_1; 2268prepare abc from "flush logs"; 2269execute abc; 2270execute abc; 2271execute abc; 2272deallocate prepare abc; 2273 2274 2275create procedure proc_1() flush status; 2276call proc_1(); 2277call proc_1(); 2278call proc_1(); 2279delimiter |; 2280--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2281create function func_1() returns int begin flush status; return 1; end| 2282create function func_1() returns int begin call proc_1(); return 1; end| 2283delimiter ;| 2284--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2285select func_1(), func_1(), func_1() from dual; 2286drop function func_1; 2287drop procedure proc_1; 2288prepare abc from "flush status"; 2289execute abc; 2290execute abc; 2291execute abc; 2292deallocate prepare abc; 2293 2294 2295create procedure proc_1() flush des_key_file; 2296call proc_1(); 2297call proc_1(); 2298call proc_1(); 2299delimiter |; 2300--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2301create function func_1() returns int begin flush des_key_file; return 1; end| 2302create function func_1() returns int begin call proc_1(); return 1; end| 2303delimiter ;| 2304--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2305select func_1(), func_1(), func_1() from dual; 2306drop function func_1; 2307drop procedure proc_1; 2308prepare abc from "flush des_key_file"; 2309execute abc; 2310execute abc; 2311execute abc; 2312deallocate prepare abc; 2313 2314 2315create procedure proc_1() flush user_resources; 2316call proc_1(); 2317call proc_1(); 2318call proc_1(); 2319delimiter |; 2320--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2321create function func_1() returns int begin flush user_resources; return 1; end| 2322create function func_1() returns int begin call proc_1(); return 1; end| 2323delimiter ;| 2324--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 2325select func_1(), func_1(), func_1() from dual; 2326drop function func_1; 2327drop procedure proc_1; 2328prepare abc from "flush user_resources"; 2329execute abc; 2330execute abc; 2331execute abc; 2332deallocate prepare abc; 2333 2334 2335create procedure proc_1() start slave; 2336drop procedure proc_1; 2337delimiter |; 2338--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2339create function func_1() returns int begin start slave; return 1; end| 2340delimiter ;| 2341 2342prepare abc from "start slave"; 2343deallocate prepare abc; 2344 2345 2346create procedure proc_1() stop slave; 2347drop procedure proc_1; 2348delimiter |; 2349--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2350create function func_1() returns int begin stop slave; return 1; end| 2351delimiter ;| 2352 2353prepare abc from "stop slave"; 2354deallocate prepare abc; 2355 2356 2357create procedure proc_1() show binlog events; 2358drop procedure proc_1; 2359delimiter |; 2360--error ER_SP_NO_RETSET 2361create function func_1() returns int begin show binlog events; return 1; end| 2362delimiter ;| 2363--error ER_SP_DOES_NOT_EXIST 2364select func_1(), func_1(), func_1() from dual; 2365--error ER_SP_DOES_NOT_EXIST 2366drop function func_1; 2367prepare abc from "show binlog events"; 2368deallocate prepare abc; 2369 2370 2371create procedure proc_1() show slave status; 2372drop procedure proc_1; 2373delimiter |; 2374--error ER_SP_NO_RETSET 2375create function func_1() returns int begin show slave status; return 1; end| 2376delimiter ;| 2377--error ER_SP_DOES_NOT_EXIST 2378select func_1(), func_1(), func_1() from dual; 2379--error ER_SP_DOES_NOT_EXIST 2380drop function func_1; 2381prepare abc from "show slave status"; 2382deallocate prepare abc; 2383 2384 2385create procedure proc_1() show master status; 2386drop procedure proc_1; 2387delimiter |; 2388--error ER_SP_NO_RETSET 2389create function func_1() returns int begin show master status; return 1; end| 2390delimiter ;| 2391--error ER_SP_DOES_NOT_EXIST 2392select func_1(), func_1(), func_1() from dual; 2393--error ER_SP_DOES_NOT_EXIST 2394drop function func_1; 2395prepare abc from "show master status"; 2396deallocate prepare abc; 2397 2398 2399create procedure proc_1() show master logs; 2400drop procedure proc_1; 2401delimiter |; 2402--error ER_SP_NO_RETSET 2403create function func_1() returns int begin show master logs; return 1; end| 2404delimiter ;| 2405--error ER_SP_DOES_NOT_EXIST 2406select func_1(), func_1(), func_1() from dual; 2407--error ER_SP_DOES_NOT_EXIST 2408drop function func_1; 2409prepare abc from "show master logs"; 2410deallocate prepare abc; 2411 2412 2413create procedure proc_1() show events; 2414call proc_1(); 2415call proc_1(); 2416call proc_1(); 2417drop procedure proc_1; 2418delimiter |; 2419--error ER_SP_NO_RETSET 2420create function func_1() returns int begin show events; return 1; end| 2421delimiter ;| 2422--error ER_SP_DOES_NOT_EXIST 2423select func_1(), func_1(), func_1() from dual; 2424--error ER_SP_DOES_NOT_EXIST 2425drop function func_1; 2426prepare abc from "show events"; 2427execute abc; 2428execute abc; 2429execute abc; 2430deallocate prepare abc; 2431 2432 2433--disable_warnings ONCE 2434drop procedure if exists a; 2435create procedure a() select 42; 2436create procedure proc_1(a char(2)) show create procedure a; 2437call proc_1("bb"); 2438call proc_1("bb"); 2439call proc_1("bb"); 2440drop procedure proc_1; 2441delimiter |; 2442--error ER_SP_NO_RETSET 2443create function func_1() returns int begin show create procedure a; return 1; end| 2444delimiter ;| 2445--error ER_SP_DOES_NOT_EXIST 2446select func_1(), func_1(), func_1() from dual; 2447--error ER_SP_DOES_NOT_EXIST 2448drop function func_1; 2449prepare abc from "show create procedure a"; 2450execute abc; 2451execute abc; 2452execute abc; 2453deallocate prepare abc; 2454drop procedure a; 2455 2456 2457--disable_warnings ONCE 2458drop function if exists a; 2459create function a() returns int return 42+13; 2460create procedure proc_1(a char(2)) show create function a; 2461call proc_1("bb"); 2462call proc_1("bb"); 2463call proc_1("bb"); 2464drop procedure proc_1; 2465delimiter |; 2466--error ER_SP_NO_RETSET 2467create function func_1() returns int begin show create function a; return 1; end| 2468delimiter ;| 2469--error ER_SP_DOES_NOT_EXIST 2470select func_1(), func_1(), func_1() from dual; 2471--error ER_SP_DOES_NOT_EXIST 2472drop function func_1; 2473prepare abc from "show create function a"; 2474execute abc; 2475execute abc; 2476execute abc; 2477deallocate prepare abc; 2478drop function a; 2479 2480 2481--disable_warnings ONCE 2482drop table if exists tab1; 2483create table tab1(a int, b char(1), primary key(a,b)); 2484create procedure proc_1() show create table tab1; 2485call proc_1(); 2486call proc_1(); 2487call proc_1(); 2488drop procedure proc_1; 2489delimiter |; 2490--error ER_SP_NO_RETSET 2491create function func_1() returns int begin show create table tab1; return 1; end| 2492delimiter ;| 2493--error ER_SP_DOES_NOT_EXIST 2494select func_1(), func_1(), func_1() from dual; 2495--error ER_SP_DOES_NOT_EXIST 2496drop function func_1; 2497prepare abc from "show create table tab1"; 2498execute abc; 2499execute abc; 2500execute abc; 2501deallocate prepare abc; 2502drop table tab1; 2503 2504 2505--disable_warnings 2506drop view if exists v1; 2507drop table if exists t1; 2508--enable_warnings 2509create table t1(a int, b char(5)); 2510insert into t1 values (1, "one"), (1, "edno"), (2, "two"), (2, "dve"); 2511create view v1 as 2512 (select a, count(*) from t1 group by a) 2513 union all 2514 (select b, count(*) from t1 group by b); 2515create procedure proc_1() show create view v1; 2516call proc_1(); 2517call proc_1(); 2518call proc_1(); 2519drop procedure proc_1; 2520delimiter |; 2521--error ER_SP_NO_RETSET 2522create function func_1() returns int begin show create view v1; return 1; end| 2523delimiter ;| 2524--error ER_SP_DOES_NOT_EXIST 2525select func_1(), func_1(), func_1() from dual; 2526--error ER_SP_DOES_NOT_EXIST 2527drop function func_1; 2528prepare abc from "show create view v1"; 2529execute abc; 2530execute abc; 2531execute abc; 2532deallocate prepare abc; 2533drop view v1; 2534drop table t1; 2535 2536 2537create procedure proc_1() install plugin my_plug soname 'some_plugin.so'; 2538--replace_regex /(Can\'t open shared library).*$/\1/ 2539--error ER_CANT_OPEN_LIBRARY,ER_FEATURE_DISABLED 2540call proc_1(); 2541--replace_regex /(Can\'t open shared library).*$/\1/ 2542--error ER_CANT_OPEN_LIBRARY,ER_FEATURE_DISABLED 2543call proc_1(); 2544--replace_regex /(Can\'t open shared library).*$/\1/ 2545--error ER_CANT_OPEN_LIBRARY,ER_FEATURE_DISABLED 2546call proc_1(); 2547drop procedure proc_1; 2548delimiter |; 2549--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2550create function func_1() returns int begin install plugin my_plug soname '/tmp/plugin'; return 1; end| 2551delimiter ;| 2552--error ER_SP_DOES_NOT_EXIST 2553select func_1(), func_1(), func_1() from dual; 2554--error ER_SP_DOES_NOT_EXIST 2555drop function func_1; 2556prepare abc from "install plugin my_plug soname 'some_plugin.so'"; 2557deallocate prepare abc; 2558 2559 2560create procedure proc_1() uninstall plugin my_plug; 2561--error ER_SP_DOES_NOT_EXIST 2562call proc_1(); 2563--error ER_SP_DOES_NOT_EXIST 2564call proc_1(); 2565--error ER_SP_DOES_NOT_EXIST 2566call proc_1(); 2567drop procedure proc_1; 2568delimiter |; 2569--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2570create function func_1() returns int begin uninstall plugin my_plug; return 1; end| 2571delimiter ;| 2572--error ER_SP_DOES_NOT_EXIST 2573select func_1(), func_1(), func_1() from dual; 2574--error ER_SP_DOES_NOT_EXIST 2575drop function func_1; 2576prepare abc from "uninstall plugin my_plug"; 2577--error ER_SP_DOES_NOT_EXIST 2578execute abc; 2579--error ER_SP_DOES_NOT_EXIST 2580execute abc; 2581--error ER_SP_DOES_NOT_EXIST 2582execute abc; 2583deallocate prepare abc; 2584 2585 2586--disable_warnings ONCE 2587drop database if exists mysqltest_xyz; 2588create procedure proc_1() create database mysqltest_xyz; 2589call proc_1(); 2590drop database if exists mysqltest_xyz; 2591call proc_1(); 2592--error ER_DB_CREATE_EXISTS 2593call proc_1(); 2594drop database if exists mysqltest_xyz; 2595call proc_1(); 2596drop database if exists mysqltest_xyz; 2597drop procedure proc_1; 2598delimiter |; 2599--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2600create function func_1() returns int begin create database mysqltest_xyz; return 1; end| 2601delimiter ;| 2602--error ER_SP_DOES_NOT_EXIST 2603select func_1(), func_1(), func_1() from dual; 2604--error ER_SP_DOES_NOT_EXIST 2605drop function func_1; 2606prepare abc from "create database mysqltest_xyz"; 2607execute abc; 2608drop database if exists mysqltest_xyz; 2609execute abc; 2610--error ER_DB_CREATE_EXISTS 2611execute abc; 2612drop database if exists mysqltest_xyz; 2613execute abc; 2614drop database if exists mysqltest_xyz; 2615deallocate prepare abc; 2616 2617 2618--disable_warnings ONCE 2619drop table if exists t1; 2620create table t1 (a int, b char(5)); 2621insert into t1 values (1, "one"), (2, "two"), (3, "three"); 2622create procedure proc_1() checksum table xyz; 2623call proc_1(); 2624call proc_1(); 2625call proc_1(); 2626drop procedure proc_1; 2627delimiter |; 2628--error ER_SP_NO_RETSET 2629create function func_1() returns int begin checksum table t1; return 1; end| 2630delimiter ;| 2631--error ER_SP_DOES_NOT_EXIST 2632select func_1(), func_1(), func_1() from dual; 2633--error ER_SP_DOES_NOT_EXIST 2634drop function func_1; 2635prepare abc from "checksum table t1"; 2636execute abc; 2637execute abc; 2638execute abc; 2639deallocate prepare abc; 2640 2641 2642create procedure proc_1() create user pstest_xyz@localhost; 2643call proc_1(); 2644drop user pstest_xyz@localhost; 2645call proc_1(); 2646--error ER_CANNOT_USER 2647call proc_1(); 2648drop user pstest_xyz@localhost; 2649call proc_1(); 2650drop user pstest_xyz@localhost; 2651drop procedure proc_1; 2652delimiter |; 2653--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2654create function func_1() returns int begin create user pstest_xyz@localhost; return 1; end| 2655delimiter ;| 2656--error ER_SP_DOES_NOT_EXIST 2657select func_1(), func_1(), func_1() from dual; 2658--error ER_SP_DOES_NOT_EXIST 2659drop function func_1; 2660prepare abc from "create user pstest_xyz@localhost"; 2661execute abc; 2662drop user pstest_xyz@localhost; 2663execute abc; 2664--error ER_CANNOT_USER 2665execute abc; 2666drop user pstest_xyz@localhost; 2667execute abc; 2668drop user pstest_xyz@localhost; 2669deallocate prepare abc; 2670 2671 2672--disable_warnings ONCE 2673drop event if exists xyz; 2674#create procedure proc_1() create event xyz on schedule every 5 minute disable do select 123; 2675#call proc_1(); 2676#drop event xyz; 2677#call proc_1(); 2678#--error ER_EVENT_ALREADY_EXISTS 2679#call proc_1(); 2680#drop event xyz; 2681#call proc_1(); 2682#drop event xyz; 2683#drop procedure proc_1; 2684delimiter |; 2685--error ER_EVENT_RECURSION_FORBIDDEN 2686create function func_1() returns int begin create event xyz on schedule at now() do select 123; return 1; end| 2687delimiter ;| 2688--error ER_SP_DOES_NOT_EXIST 2689select func_1(), func_1(), func_1() from dual; 2690--error ER_SP_DOES_NOT_EXIST 2691drop function func_1; 2692--error ER_UNSUPPORTED_PS 2693prepare abc from "create event xyz on schedule at now() do select 123"; 2694--error ER_UNKNOWN_STMT_HANDLER 2695deallocate prepare abc; 2696 2697 2698--disable_warnings 2699drop event if exists xyz; 2700create event xyz on schedule every 5 minute disable do select 123; 2701--enable_warnings 2702create procedure proc_1() alter event xyz comment 'xyz'; 2703call proc_1(); 2704drop event xyz; 2705create event xyz on schedule every 5 minute disable do select 123; 2706call proc_1(); 2707drop event xyz; 2708create event xyz on schedule every 5 minute disable do select 123; 2709call proc_1(); 2710drop event xyz; 2711drop procedure proc_1; 2712delimiter |; 2713--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2714create function func_1() returns int begin alter event xyz comment 'xyz'; return 1; end| 2715delimiter ;| 2716--error ER_UNSUPPORTED_PS 2717prepare abc from "alter event xyz comment 'xyz'"; 2718--error ER_UNKNOWN_STMT_HANDLER 2719deallocate prepare abc; 2720 2721 2722--disable_warnings 2723drop event if exists xyz; 2724create event xyz on schedule every 5 minute disable do select 123; 2725--enable_warnings 2726create procedure proc_1() drop event xyz; 2727call proc_1(); 2728create event xyz on schedule every 5 minute disable do select 123; 2729call proc_1(); 2730--error ER_EVENT_DOES_NOT_EXIST 2731call proc_1(); 2732drop procedure proc_1; 2733delimiter |; 2734--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2735create function func_1() returns int begin drop event xyz; return 1; end| 2736delimiter ;| 2737--error ER_UNSUPPORTED_PS 2738prepare abc from "drop event xyz"; 2739--error ER_UNKNOWN_STMT_HANDLER 2740deallocate prepare abc; 2741 2742 2743--disable_warnings 2744drop table if exists t1; 2745create table t1 (a int, b char(5)) engine=myisam; 2746insert into t1 values (1, "one"), (2, "two"), (3, "three"); 2747--enable_warnings 2748SET GLOBAL new_cache.key_buffer_size=128*1024; 2749create procedure proc_1() cache index t1 in new_cache; 2750call proc_1(); 2751call proc_1(); 2752call proc_1(); 2753drop procedure proc_1; 2754SET GLOBAL second_cache.key_buffer_size=128*1024; 2755prepare abc from "cache index t1 in second_cache"; 2756execute abc; 2757execute abc; 2758execute abc; 2759deallocate prepare abc; 2760drop table t1; 2761 2762--disable_warnings 2763drop table if exists t1; 2764drop table if exists t2; 2765create table t1 (a int, b char(5)) engine=myisam; 2766insert into t1 values (1, "one"), (2, "two"), (3, "three"); 2767create table t2 (a int, b char(5)) engine=myisam; 2768insert into t2 values (1, "one"), (2, "two"), (3, "three"); 2769--enable_warnings 2770create procedure proc_1() load index into cache t1 ignore leaves; 2771call proc_1(); 2772call proc_1(); 2773call proc_1(); 2774drop procedure proc_1; 2775delimiter |; 2776--error ER_SP_NO_RETSET 2777create function func_1() returns int begin load index into cache t1 ignore leaves; return 1; end| 2778delimiter ;| 2779prepare abc from "load index into cache t2 ignore leaves"; 2780execute abc; 2781execute abc; 2782execute abc; 2783deallocate prepare abc; 2784drop table t1, t2; 2785 2786# 2787# Bug #21422: GRANT/REVOKE possible inside stored function, probably in a trigger 2788# This is disabled for now till it is resolved in 5.0 2789# 2790 2791#create procedure proc_1() grant all on *.* to abc@host; 2792#drop procedure proc_1; 2793#delimiter |; 2794#--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2795#create function func_1() returns int begin grant all on *.* to abc@host; return 1; end| 2796#delimiter ;| 2797#prepare abc from "grant all on *.* to abc@host"; 2798# 2799#create procedure proc_1() revoke all on *.* from abc@host; 2800#drop procedure proc_1; 2801#delimiter |;#--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 2802#create function func_1() returns int begin revoke all on *.* from abc@host; return 1; end| 2803#delimiter ;| 2804#prepare abc from "revoke all on *.* from abc@host"; 2805 2806create procedure proc_1() show errors; 2807call proc_1(); 2808call proc_1(); 2809call proc_1(); 2810drop procedure proc_1; 2811delimiter |; 2812--error ER_SP_NO_RETSET 2813create function func_1() returns int begin show errors; return 1; end| 2814delimiter ;| 2815# WL#5928: prepare of diagnostics statements fails now, cos the standard says it should. 2816--error ER_UNSUPPORTED_PS 2817prepare abc from "show errors"; 2818# deallocate prepare abc; 2819 2820--disable_warnings 2821drop table if exists t1; 2822drop table if exists t2; 2823--enable_warnings 2824create procedure proc_1() show warnings; 2825drop table if exists t1; 2826call proc_1(); 2827drop table if exists t2; 2828call proc_1(); 2829drop table if exists t1, t2; 2830call proc_1(); 2831drop procedure proc_1; 2832delimiter |; 2833--error ER_SP_NO_RETSET 2834create function func_1() returns int begin show warnings; return 1; end| 2835delimiter ;| 2836# WL#5928: prepare of diagnostics statements fails now, cos the standard says it should. 2837--error ER_UNSUPPORTED_PS 2838prepare abc from "show warnings"; 2839 2840# 2841# Bug#22684: The Functions ENCODE, DECODE and FORMAT are not real functions 2842# 2843 2844set @my_password="password"; 2845set @my_data="clear text to encode"; 2846 2847prepare stmt1 from 'select decode(encode(?, ?), ?)'; 2848execute stmt1 using @my_data, @my_password, @my_password; 2849set @my_data="more text to encode"; 2850execute stmt1 using @my_data, @my_password, @my_password; 2851set @my_password="new password"; 2852execute stmt1 using @my_data, @my_password, @my_password; 2853deallocate prepare stmt1; 2854 2855set @to_format="123456789.123456789"; 2856set @dec=0; 2857 2858prepare stmt2 from 'select format(?, ?)'; 2859execute stmt2 using @to_format, @dec; 2860set @dec=4; 2861execute stmt2 using @to_format, @dec; 2862set @dec=6; 2863execute stmt2 using @to_format, @dec; 2864set @dec=2; 2865execute stmt2 using @to_format, @dec; 2866set @to_format="100"; 2867execute stmt2 using @to_format, @dec; 2868set @to_format="1000000"; 2869execute stmt2 using @to_format, @dec; 2870set @to_format="10000"; 2871execute stmt2 using @to_format, @dec; 2872deallocate prepare stmt2; 2873 2874 2875# 2876# BUG#18326: Do not lock table for writing during prepare of statement 2877# 2878--disable_warnings ONCE 2879DROP TABLE IF EXISTS t1, t2; 2880 2881CREATE TABLE t1 (i INT); 2882INSERT INTO t1 VALUES (1); 2883CREATE TABLE t2 (i INT); 2884INSERT INTO t2 VALUES (2); 2885 2886LOCK TABLE t1 READ, t2 WRITE; 2887 2888connect (conn1, localhost, root, , ); 2889 2890# Prepare never acquires the lock, and thus should not block. 2891PREPARE stmt1 FROM "SELECT i FROM t1"; 2892PREPARE stmt2 FROM "INSERT INTO t2 (i) VALUES (3)"; 2893 2894# This should not block because READ lock on t1 is shared. 2895EXECUTE stmt1; 2896 2897# This should block because WRITE lock on t2 is exclusive. 2898send EXECUTE stmt2; 2899 2900connection default; 2901 2902SELECT * FROM t2; 2903UNLOCK TABLES; 2904let $wait_condition= SELECT COUNT(*) = 2 FROM t2; 2905--source include/wait_condition.inc 2906SELECT * FROM t2; 2907 2908# DDL and DML works even if some client have a prepared statement 2909# referencing the table. 2910ALTER TABLE t1 ADD COLUMN j INT; 2911ALTER TABLE t2 ADD COLUMN j INT; 2912INSERT INTO t1 VALUES (4, 5); 2913INSERT INTO t2 VALUES (4, 5); 2914 2915connection conn1; 2916 2917reap; 2918EXECUTE stmt1; 2919EXECUTE stmt2; 2920SELECT * FROM t2; 2921 2922disconnect conn1; 2923 2924connection default; 2925 2926DROP TABLE t1, t2; 2927 2928# 2929# Bug #24879 Prepared Statements: CREATE TABLE (UTF8 KEY) produces a growing 2930# key length 2931# 2932# Test that parse information is not altered by subsequent executions of a 2933# prepared statement 2934# 2935drop table if exists t1; 2936prepare stmt 2937from "create table t1 (c char(100) character set utf8, key (c(10)))"; 2938execute stmt; 2939show create table t1; 2940drop table t1; 2941execute stmt; 2942show create table t1; 2943drop table t1; 2944 2945# 2946# Bug #32030 DELETE does not return an error and deletes rows if error 2947# evaluating WHERE 2948# 2949# Test that there is an error for prepared delete just like for the normal 2950# one. 2951# 2952--disable_warnings ONCE 2953drop table if exists t1, t2; 2954create table t1 (a int, b int); 2955create table t2 like t1; 2956 2957insert into t1 (a, b) values (1,1), (1,2), (1,3), (1,4), (1,5), 2958 (2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6); 2959 2960insert into t2 select a, max(b) from t1 group by a; 2961 2962prepare stmt from "delete from t2 where (select (select max(b) from t1 group 2963by a having a < 2) x from t1) > 10000"; 2964 2965--error ER_SUBQUERY_NO_1_ROW 2966delete from t2 where (select (select max(b) from t1 group 2967by a having a < 2) x from t1) > 10000; 2968--error ER_SUBQUERY_NO_1_ROW 2969execute stmt; 2970--error ER_SUBQUERY_NO_1_ROW 2971execute stmt; 2972 2973deallocate prepare stmt; 2974drop table t1, t2; 2975 2976--echo # 2977--echo # Bug#27430 Crash in subquery code when in PS and table DDL changed 2978--echo # after PREPARE 2979--echo # 2980--echo # This part of the test doesn't work in embedded server, this is 2981--echo # why it's here. For the main test see ps_ddl*.test 2982--echo 2983--disable_warnings ONCE 2984drop table if exists t1; 2985create table t1 (a int); 2986prepare stmt from "show events where (1) in (select * from t1)"; 2987execute stmt; 2988drop table t1; 2989create table t1 (x int); 2990execute stmt; 2991drop table t1; 2992deallocate prepare stmt; 2993 2994--echo # 2995--echo # Bug#49141: Encode function is significantly slower in 5.1 compared to 5.0 2996--echo # 2997 2998prepare encode from "select encode(?, ?) into @ciphertext"; 2999prepare decode from "select decode(?, ?) into @plaintext"; 3000set @str="abc", @key="cba"; 3001execute encode using @str, @key; 3002execute decode using @ciphertext, @key; 3003select @plaintext; 3004set @str="bcd", @key="dcb"; 3005execute encode using @str, @key; 3006execute decode using @ciphertext, @key; 3007select @plaintext; 3008deallocate prepare encode; 3009deallocate prepare decode; 3010 3011--echo # 3012--echo # Bug#52124 memory leaks like a sieve in datetime, timestamp, time, date fields + warnings 3013--echo # 3014CREATE TABLE t1 (a DATETIME NOT NULL, b TINYINT); 3015INSERT IGNORE INTO t1 VALUES (0, 0),(0, 0); 3016PREPARE stmt FROM "SELECT 1 FROM t1 WHERE 3017ROW(a, b) >= ROW('1', (SELECT 1 FROM t1 WHERE a > 1234))"; 3018--disable_warnings 3019EXECUTE stmt; 3020EXECUTE stmt; 3021--enable_warnings 3022DEALLOCATE PREPARE stmt; 3023DROP TABLE t1; 3024 3025--echo # 3026--echo # Bug#54494 crash with explain extended and prepared statements 3027--echo # 3028CREATE TABLE t1(a INT); 3029INSERT INTO t1 VALUES (1),(2); 3030PREPARE stmt FROM 'EXPLAIN EXTENDED SELECT 1 FROM t1 RIGHT JOIN t1 t2 ON 1'; 3031EXECUTE stmt; 3032EXECUTE stmt; 3033DEALLOCATE PREPARE stmt; 3034DROP TABLE t1; 3035 3036--echo # 3037--echo # Bug#54488 crash when using explain and prepared statements with subqueries 3038--echo # 3039CREATE TABLE t1(f1 INT); 3040INSERT INTO t1 VALUES (1),(1); 3041PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 WHERE (SELECT (SELECT 1 FROM t1 GROUP BY f1))'; 3042EXECUTE stmt; 3043EXECUTE stmt; 3044DEALLOCATE PREPARE stmt; 3045DROP TABLE t1; 3046 3047--echo 3048--echo End of 5.1 tests. 3049 3050########################################################################### 3051 3052--echo 3053--echo # 3054--echo # WL#4435: Support OUT-parameters in prepared statements. 3055--echo # 3056--echo 3057 3058# The idea of this test case is to check that 3059# - OUT-parameters of four allowed types (string, double, int, decimal) work 3060# properly; 3061# - INOUT and OUT parameters work properly; 3062# - A mix of IN and OUT parameters work properly; 3063 3064--disable_warnings 3065DROP PROCEDURE IF EXISTS p_string; 3066DROP PROCEDURE IF EXISTS p_double; 3067DROP PROCEDURE IF EXISTS p_int; 3068DROP PROCEDURE IF EXISTS p_decimal; 3069--enable_warnings 3070 3071delimiter |; 3072 3073--echo 3074CREATE PROCEDURE p_string( 3075 IN v0 INT, 3076 OUT v1 CHAR(32), 3077 IN v2 CHAR(32), 3078 INOUT v3 CHAR(32)) 3079BEGIN 3080 SET v0 = -1; 3081 SET v1 = 'test_v1'; 3082 SET v2 = 'n/a'; 3083 SET v3 = 'test_v3'; 3084END| 3085 3086--echo 3087CREATE PROCEDURE p_double( 3088 IN v0 INT, 3089 OUT v1 DOUBLE(4, 2), 3090 IN v2 DOUBLE(4, 2), 3091 INOUT v3 DOUBLE(4, 2)) 3092BEGIN 3093 SET v0 = -1; 3094 SET v1 = 12.34; 3095 SET v2 = 98.67; 3096 SET v3 = 56.78; 3097END| 3098 3099--echo 3100CREATE PROCEDURE p_int( 3101 IN v0 CHAR(10), 3102 OUT v1 INT, 3103 IN v2 INT, 3104 INOUT v3 INT) 3105BEGIN 3106 SET v0 = 'n/a'; 3107 SET v1 = 1234; 3108 SET v2 = 9876; 3109 SET v3 = 5678; 3110END| 3111 3112--echo 3113CREATE PROCEDURE p_decimal( 3114 IN v0 INT, 3115 OUT v1 DECIMAL(4, 2), 3116 IN v2 DECIMAL(4, 2), 3117 INOUT v3 DECIMAL(4, 2)) 3118BEGIN 3119 SET v0 = -1; 3120 SET v1 = 12.34; 3121 SET v2 = 98.67; 3122 SET v3 = 56.78; 3123END| 3124 3125delimiter ;| 3126 3127--echo 3128PREPARE stmt_str FROM 'CALL p_string(?, ?, ?, ?)'; 3129PREPARE stmt_dbl FROM 'CALL p_double(?, ?, ?, ?)'; 3130PREPARE stmt_int FROM 'CALL p_int(?, ?, ?, ?)'; 3131PREPARE stmt_dec FROM 'CALL p_decimal(?, ?, ?, ?)'; 3132 3133--echo 3134SET @x_str_1 = NULL; 3135SET @x_str_2 = NULL; 3136SET @x_str_3 = NULL; 3137SET @x_dbl_1 = NULL; 3138SET @x_dbl_2 = NULL; 3139SET @x_dbl_3 = NULL; 3140SET @x_int_1 = NULL; 3141SET @x_int_2 = NULL; 3142SET @x_int_3 = NULL; 3143SET @x_dec_1 = NULL; 3144SET @x_dec_2 = NULL; 3145SET @x_dec_3 = NULL; 3146 3147--echo 3148--echo -- Testing strings... 3149 3150--echo 3151EXECUTE stmt_str USING @x_int_1, @x_str_1, @x_str_2, @x_str_3; 3152SELECT @x_int_1, @x_str_1, @x_str_2, @x_str_3; 3153 3154--echo 3155EXECUTE stmt_str USING @x_int_1, @x_str_1, @x_str_2, @x_str_3; 3156SELECT @x_int_1, @x_str_1, @x_str_2, @x_str_3; 3157 3158--echo 3159--echo -- Testing doubles... 3160 3161--echo 3162EXECUTE stmt_dbl USING @x_int_1, @x_dbl_1, @x_dbl_2, @x_dbl_3; 3163SELECT @x_int_1, @x_dbl_1, @x_dbl_2, @x_dbl_3; 3164 3165--echo 3166EXECUTE stmt_dbl USING @x_int_1, @x_dbl_1, @x_dbl_2, @x_dbl_3; 3167SELECT @x_int_1, @x_dbl_1, @x_dbl_2, @x_dbl_3; 3168 3169--echo 3170--echo -- Testing ints... 3171 3172--echo 3173EXECUTE stmt_int USING @x_str_1, @x_int_1, @x_int_2, @x_int_3; 3174SELECT @x_str_1, @x_int_1, @x_int_2, @x_int_3; 3175 3176--echo 3177EXECUTE stmt_int USING @x_str_1, @x_int_1, @x_int_2, @x_int_3; 3178SELECT @x_str_1, @x_int_1, @x_int_2, @x_int_3; 3179 3180--echo 3181--echo -- Testing decs... 3182 3183--echo 3184EXECUTE stmt_dec USING @x_int_1, @x_dec_1, @x_dec_2, @x_dec_3; 3185SELECT @x_int_1, @x_dec_1, @x_dec_2, @x_dec_3; 3186 3187--echo 3188EXECUTE stmt_dec USING @x_int_1, @x_dec_1, @x_dec_2, @x_dec_3; 3189SELECT @x_int_1, @x_dec_1, @x_dec_2, @x_dec_3; 3190 3191--echo 3192DEALLOCATE PREPARE stmt_str; 3193DEALLOCATE PREPARE stmt_dbl; 3194DEALLOCATE PREPARE stmt_int; 3195DEALLOCATE PREPARE stmt_dec; 3196 3197--echo 3198DROP PROCEDURE p_string; 3199DROP PROCEDURE p_double; 3200DROP PROCEDURE p_int; 3201DROP PROCEDURE p_decimal; 3202 3203# 3204# Another test case for WL#4435: check out parameters in Dynamic SQL. 3205# 3206 3207--echo 3208--disable_warnings 3209DROP PROCEDURE IF EXISTS p1; 3210DROP PROCEDURE IF EXISTS p2; 3211--enable_warnings 3212 3213--echo 3214 3215CREATE PROCEDURE p1(OUT v1 CHAR(10)) 3216 SET v1 = 'test1'; 3217 3218--echo 3219 3220delimiter |; 3221CREATE PROCEDURE p2(OUT v2 CHAR(10)) 3222BEGIN 3223 SET @query = 'CALL p1(?)'; 3224 PREPARE stmt1 FROM @query; 3225 EXECUTE stmt1 USING @u1; 3226 DEALLOCATE PREPARE stmt1; 3227 3228 SET v2 = @u1; 3229END| 3230delimiter ;| 3231 3232--echo 3233 3234CALL p2(@a); 3235SELECT @a; 3236 3237--echo 3238 3239DROP PROCEDURE p1; 3240DROP PROCEDURE p2; 3241 3242########################################################################### 3243 3244--source t/wl4435_generated.inc 3245 3246########################################################################### 3247 3248--echo 3249--echo # End of WL#4435. 3250 3251########################################################################### 3252 3253 3254--echo # 3255--echo # WL#4284: Transactional DDL locking 3256--echo # 3257 3258--disable_warnings ONCE 3259DROP TABLE IF EXISTS t1; 3260CREATE TABLE t1 (a INT); 3261BEGIN; 3262SELECT * FROM t1; 3263--echo # Test that preparing a CREATE TABLE does not take a exclusive metdata lock. 3264PREPARE stmt1 FROM "CREATE TABLE t1 AS SELECT 1"; 3265--error ER_TABLE_EXISTS_ERROR 3266EXECUTE stmt1; 3267DEALLOCATE PREPARE stmt1; 3268DROP TABLE t1; 3269 3270--echo # 3271--echo # WL#4284: Transactional DDL locking 3272--echo # 3273--echo # Test that metadata locks taken during prepare are released. 3274--echo # 3275 3276connect(con1,localhost,root,,); 3277connection default; 3278--disable_warnings ONCE 3279DROP TABLE IF EXISTS t1; 3280CREATE TABLE t1 (a INT); 3281connection con1; 3282BEGIN; 3283PREPARE stmt1 FROM "SELECT * FROM t1"; 3284connection default; 3285DROP TABLE t1; 3286disconnect con1; 3287 3288--echo 3289--echo # 3290--echo # Bug#56115: invalid memory reads when PS selecting from 3291--echo # information_schema tables 3292--echo # Bug#58701: crash in Field::make_field, cursor-protocol 3293--echo # 3294--echo # NOTE: MTR should be run both with --ps-protocol and --cursor-protocol. 3295--echo # 3296--echo 3297 3298SELECT * 3299FROM (SELECT 1 UNION SELECT 2) t; 3300 3301--echo 3302--echo # Bug#13805127: Stored program cache produces wrong result in same THD 3303--echo 3304 3305PREPARE s1 FROM 3306" 3307SELECT c1, t2.c2, count(c3) 3308FROM 3309 ( 3310 SELECT 3 as c2 FROM dual WHERE @x = 1 3311 UNION 3312 SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 3313 ) AS t1, 3314 ( 3315 SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual 3316 UNION 3317 SELECT '2012-03-01 02:00:00', 3, 2 FROM dual 3318 UNION 3319 SELECT '2012-03-01 01:00:00', 2, 1 FROM dual 3320 ) AS t2 3321WHERE t2.c2 = t1.c2 3322GROUP BY c1, c2 3323"; 3324 3325--echo 3326SET @x = 1; 3327SELECT c1, t2.c2, count(c3) 3328FROM 3329 ( 3330 SELECT 3 as c2 FROM dual WHERE @x = 1 3331 UNION 3332 SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 3333 ) AS t1, 3334 ( 3335 SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual 3336 UNION 3337 SELECT '2012-03-01 02:00:00', 3, 2 FROM dual 3338 UNION 3339 SELECT '2012-03-01 01:00:00', 2, 1 FROM dual 3340 ) AS t2 3341WHERE t2.c2 = t1.c2 3342GROUP BY c1, c2; 3343--echo 3344EXECUTE s1; 3345 3346--echo 3347SET @x = 2; 3348SELECT c1, t2.c2, count(c3) 3349FROM 3350 ( 3351 SELECT 3 as c2 FROM dual WHERE @x = 1 3352 UNION 3353 SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 3354 ) AS t1, 3355 ( 3356 SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual 3357 UNION 3358 SELECT '2012-03-01 02:00:00', 3, 2 FROM dual 3359 UNION 3360 SELECT '2012-03-01 01:00:00', 2, 1 FROM dual 3361 ) AS t2 3362WHERE t2.c2 = t1.c2 3363GROUP BY c1, c2; 3364--echo 3365EXECUTE s1; 3366 3367--echo 3368SET @x = 1; 3369SELECT c1, t2.c2, count(c3) 3370FROM 3371 ( 3372 SELECT 3 as c2 FROM dual WHERE @x = 1 3373 UNION 3374 SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 3375 ) AS t1, 3376 ( 3377 SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual 3378 UNION 3379 SELECT '2012-03-01 02:00:00', 3, 2 FROM dual 3380 UNION 3381 SELECT '2012-03-01 01:00:00', 2, 1 FROM dual 3382 ) AS t2 3383WHERE t2.c2 = t1.c2 3384GROUP BY c1, c2; 3385--echo 3386EXECUTE s1; 3387 3388DEALLOCATE PREPARE s1; 3389 3390--echo # 3391--echo # End of 5.5 tests. 3392 3393--echo # 3394--echo # Bug#12603141: JOIN::flatten_subqueries asrt/simplify_joins sig11/... 3395--echo # Bug#12603457: SEGFAULT IN REINIT_STMT_BEFORE_USE 3396--echo # 3397 3398CREATE TABLE t1(a INTEGER); 3399CREATE TABLE t2(a INTEGER); 3400 3401PREPARE stmt FROM ' 3402SELECT (SELECT 1 FROM t2 WHERE ot.a) AS d 3403FROM t1 AS ot 3404GROUP BY d'; 3405 3406EXECUTE stmt; 3407EXECUTE stmt; 3408 3409INSERT INTO t1 VALUES (0),(1),(2); 3410INSERT INTO t2 VALUES (1); 3411 3412EXECUTE stmt; 3413EXECUTE stmt; 3414 3415DEALLOCATE PREPARE stmt; 3416DROP TABLE t1, t2; 3417 3418--echo # 3419--echo # Bug#12582849 3420--echo # ASSERTION FAILURE IN __CXA_PURE_VIRTUAL/ITEM_COND::FIX_FIELDS 3421--echo # 3422 3423CREATE TABLE t1 ( 3424 pk INTEGER AUTO_INCREMENT, 3425 col_int_nokey INTEGER, 3426 col_int_key INTEGER, 3427 3428 col_varchar_key VARCHAR(1), 3429 col_varchar_nokey VARCHAR(1), 3430 3431 PRIMARY KEY (pk), 3432 KEY (col_int_key), 3433 KEY (col_varchar_key, col_int_key) 3434); 3435 3436INSERT INTO t1 ( 3437 col_int_key, col_int_nokey, 3438 col_varchar_key, col_varchar_nokey 3439) VALUES 3440(4, 2, 'v', 'v'), 3441(62, 150, 'v', 'v'); 3442 3443CREATE TABLE t2 ( 3444 pk INTEGER AUTO_INCREMENT, 3445 col_int_nokey INTEGER, 3446 col_int_key INTEGER, 3447 3448 col_varchar_key VARCHAR(1), 3449 col_varchar_nokey VARCHAR(1), 3450 3451 PRIMARY KEY (pk), 3452 KEY (col_int_key), 3453 KEY (col_varchar_key, col_int_key) 3454); 3455 3456INSERT INTO t2 ( 3457 col_int_key, col_int_nokey, 3458 col_varchar_key, col_varchar_nokey 3459) VALUES 3460(8, NULL, 'x', 'x'), 3461(7, 8, 'd', 'd'); 3462 3463PREPARE stmt FROM ' 3464SELECT 3465 ( SELECT MAX( SQ1_alias2 .col_int_nokey ) AS SQ1_field1 3466 FROM ( t2 AS SQ1_alias1 RIGHT JOIN t1 AS SQ1_alias2 3467 ON ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ) 3468 ) 3469 WHERE SQ1_alias2.pk < alias1.col_int_nokey OR alias1.pk 3470 ) AS field1 3471FROM ( t1 AS alias1 JOIN t2 AS alias2 ON alias2.pk ) 3472GROUP BY field1 3473'; 3474 3475EXECUTE stmt; 3476EXECUTE stmt; 3477 3478DEALLOCATE PREPARE stmt; 3479 3480DROP TABLE t1, t2; 3481 3482--echo # 3483--echo # Bug#16820562: Bad column names are not rejected at 'prepare' 3484--echo # 3485 3486--echo Resolver errors should be given at prepare time in insert select 3487 3488CREATE TABLE t1 (a INTEGER); 3489CREATE TABLE t2 (b INTEGER); 3490 3491--error ER_BAD_FIELD_ERROR 3492PREPARE s FROM "INSERT INTO t1 VALUES(1) ON DUPLICATE KEY UPDATE absent=2"; 3493--error ER_BAD_FIELD_ERROR 3494PREPARE s FROM "INSERT INTO t1 VALUES(1) ON DUPLICATE KEY UPDATE a=absent"; 3495--error ER_BAD_FIELD_ERROR 3496PREPARE s FROM "INSERT INTO t1 SELECT 1 ON DUPLICATE KEY UPDATE absent=2"; 3497--error ER_BAD_FIELD_ERROR 3498PREPARE s FROM "INSERT INTO t1 SELECT 1 ON DUPLICATE KEY UPDATE a=absent"; 3499 3500--error ER_BAD_FIELD_ERROR 3501PREPARE s FROM "INSERT INTO t1(absent) VALUES(1) ON DUPLICATE KEY UPDATE a=1"; 3502--error ER_BAD_FIELD_ERROR 3503PREPARE s FROM "INSERT INTO t1(absent) SELECT 1 ON DUPLICATE KEY UPDATE a=1"; 3504 3505--echo Resolver errors should be given at prepare time in multi-table update 3506 3507--error ER_BAD_FIELD_ERROR 3508PREPARE s FROM "UPDATE t1 JOIN t2 ON t1.a=t2.b SET t1.a=absent"; 3509--error ER_BAD_FIELD_ERROR 3510PREPARE s FROM "UPDATE t1 JOIN t2 ON t1.a=t2.b SET t1.a=t1.absent"; 3511--error ER_BAD_FIELD_ERROR 3512PREPARE s FROM "UPDATE t1 JOIN t2 ON t1.a=t2.b SET t1.a=t2.absent"; 3513--error ER_BAD_FIELD_ERROR 3514PREPARE s FROM "UPDATE t1 JOIN t2 ON t1.a=t2.b SET t1.a=absent.absent"; 3515 3516DROP TABLE t1, t2; 3517 3518 3519--echo # 3520--echo # Bug#19894382 - SERVER SIDE PREPARED STATEMENTS LEADS TO POTENTIAL OFF-BY-SECOND 3521--echo # TIMESTAMP ON SLAVE. 3522--echo # 3523 3524CREATE TABLE bug19894382(f1 CHAR(64) DEFAULT 'slave', 3525 f2 TIME, f3 TIMESTAMP NULL, f4 DATETIME, 3526 f5 TIME(3), f6 TIMESTAMP(3) NULL, f7 DATETIME(3)); 3527 3528--echo # Execute prepared statements from mysql_client_test. 3529--exec echo "$MYSQL_CLIENT_TEST" > $MYSQLTEST_VARDIR/log/bug19894382.out.log 2>&1 3530--exec $MYSQL_CLIENT_TEST -d -u root test_bug19894382 >> $MYSQLTEST_VARDIR/log/bug19894382.out.log 2>&1 3531 3532--echo # Insert tuples from the client_test_db.bug19894382 to the test.bug19894382. 3533--echo # Tuples in the client_test_db.bug19894382 are inserted from the mysql_client_test. 3534INSERT INTO bug19894382 SELECT * FROM client_test_db.bug19894382; 3535 3536--echo # Replay binlog events 3537let $MYSQLD_DATADIR= `select @@datadir`; 3538--let $master_log_file= query_get_value(SHOW MASTER STATUS, File, 1) 3539--exec $MYSQL_BINLOG --force-if-open -d client_test_db $MYSQLD_DATADIR/$master_log_file > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug19894382.binlog 3540--exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug19894382.binlog" 3541 3542--echo # Insert tuples from the client_test_db.bug19894382 to the test.bug19894382. 3543--echo # Tuples in the client_test_db.bug19894382 are inserted from the binlog. 3544INSERT INTO bug19894382(f2, f3, f4, f5, f6, f7) 3545 SELECT f2, f3, f4, f5, f6, f7 FROM client_test_db.bug19894382; 3546--echo # With fix, tuples of "master" and "slave" will be same. There will not be any difference 3547--echo # in values inserted for time, timestamp and datetime type columns. 3548SELECT * FROM bug19894382 ORDER BY f2; 3549 3550--echo # Cleanup 3551DROP DATABASE client_test_db; 3552DROP TABLE bug19894382; 3553--remove_file $MYSQLTEST_VARDIR/log/bug19894382.out.log 3554--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug19894382.binlog 3555