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