1drop procedure if exists p1| 2drop procedure if exists p2| 3create procedure p1() 4begin 5prepare stmt from "select 1"; 6execute stmt; 7execute stmt; 8execute stmt; 9deallocate prepare stmt; 10end| 11call p1()| 121 131 141 151 161 171 18call p1()| 191 201 211 221 231 241 25call p1()| 261 271 281 291 301 311 32drop procedure p1| 33create procedure p1() 34begin 35execute stmt; 36end| 37prepare stmt from "call p1()"| 38set @SAVE_SP_RECURSION_LEVELS=@@max_sp_recursion_depth| 39set @@max_sp_recursion_depth=100| 40execute stmt| 41ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 42execute stmt| 43ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 44execute stmt| 45ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 46call p1()| 47ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 48call p1()| 49ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 50call p1()| 51ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 52set @@max_sp_recursion_depth=@SAVE_SP_RECURSION_LEVELS| 53call p1()| 54ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine p1 55call p1()| 56ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine p1 57call p1()| 58ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine p1 59drop procedure p1| 60create procedure p1() 61begin 62prepare stmt from "create procedure p2() begin select 1; end"; 63execute stmt; 64deallocate prepare stmt; 65end| 66call p1()| 67ERROR HY000: This command is not supported in the prepared statement protocol yet 68call p1()| 69ERROR HY000: This command is not supported in the prepared statement protocol yet 70drop procedure p1| 71create procedure p1() 72begin 73prepare stmt from "drop procedure p2"; 74execute stmt; 75deallocate prepare stmt; 76end| 77call p1()| 78ERROR HY000: This command is not supported in the prepared statement protocol yet 79call p1()| 80ERROR HY000: This command is not supported in the prepared statement protocol yet 81drop procedure p1| 82create procedure p1() 83begin 84prepare stmt_drop from "drop table if exists t1"; 85execute stmt_drop; 86prepare stmt from "create table t1 (a int)"; 87execute stmt; 88insert into t1 (a) values (1); 89select * from t1; 90prepare stmt_alter from "alter table t1 add (b int)"; 91execute stmt_alter; 92insert into t1 (a,b) values (2,1); 93deallocate prepare stmt_alter; 94deallocate prepare stmt; 95deallocate prepare stmt_drop; 96end| 97call p1()| 98a 991 100call p1()| 101a 1021 103drop procedure p1| 104create procedure p1() 105begin 106set @tab_name=concat("tab_", replace(curdate(), '-', '_')); 107set @drop_sql=concat("drop table if exists ", @tab_name); 108set @create_sql=concat("create table ", @tab_name, " (a int)"); 109set @insert_sql=concat("insert into ", @tab_name, " values (1), (2), (3)"); 110set @select_sql=concat("select * from ", @tab_name); 111select @tab_name; 112select @drop_sql; 113select @create_sql; 114select @insert_sql; 115select @select_sql; 116prepare stmt_drop from @drop_sql; 117execute stmt_drop; 118prepare stmt from @create_sql; 119execute stmt; 120prepare stmt from @insert_sql; 121execute stmt; 122prepare stmt from @select_sql; 123execute stmt; 124execute stmt_drop; 125deallocate prepare stmt; 126deallocate prepare stmt_drop; 127end| 128call p1()| 129call p1()| 130drop procedure p1| 131create procedure p1() 132begin 133prepare stmt_drop from "drop table if exists t1"; 134execute stmt_drop; 135prepare stmt from "create table t1 (a int)"; 136execute stmt; 137deallocate prepare stmt; 138deallocate prepare stmt_drop; 139end| 140drop function if exists f1| 141create function f1(a int) returns int 142begin 143call p1(); 144return 1; 145end| 146select f1(0)| 147ERROR 0A000: Dynamic SQL is not allowed in stored function or trigger 148select f1(f1(0))| 149ERROR 0A000: Dynamic SQL is not allowed in stored function or trigger 150select f1(f1(f1(0)))| 151ERROR 0A000: Dynamic SQL is not allowed in stored function or trigger 152drop function f1| 153drop procedure p1| 154create procedure p1() 155begin 156drop table if exists t1; 157create table t1 (id integer not null primary key, 158name varchar(20) not null); 159insert into t1 (id, name) values (1, 'aaa'), (2, 'bbb'), (3, 'ccc'); 160prepare stmt from "select name from t1"; 161execute stmt; 162select name from t1; 163execute stmt; 164prepare stmt from 165"select name from t1 where name=(select name from t1 where id=2)"; 166execute stmt; 167select name from t1 where name=(select name from t1 where id=2); 168execute stmt; 169end| 170call p1()| 171name 172aaa 173bbb 174ccc 175name 176aaa 177bbb 178ccc 179name 180aaa 181bbb 182ccc 183name 184bbb 185name 186bbb 187name 188bbb 189call p1()| 190name 191aaa 192bbb 193ccc 194name 195aaa 196bbb 197ccc 198name 199aaa 200bbb 201ccc 202name 203bbb 204name 205bbb 206name 207bbb 208drop procedure p1| 209prepare stmt from "select * from t1"| 210create procedure p1() 211begin 212execute stmt; 213deallocate prepare stmt; 214end| 215call p1()| 216id name 2171 aaa 2182 bbb 2193 ccc 220call p1()| 221ERROR HY000: Unknown prepared statement handler (stmt) given to EXECUTE 222drop procedure p1| 223SET sql_mode = 'NO_ENGINE_SUBSTITUTION'| 224Warnings: 225Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release. 226create procedure p1() 227begin 228declare a char(10); 229set a="sp-variable"; 230set @a="mysql-variable"; 231prepare stmt from "select 'dynamic sql:', @a, a"; 232execute stmt; 233end| 234call p1()| 235ERROR 42S22: Unknown column 'a' in 'field list' 236call p1()| 237ERROR 42S22: Unknown column 'a' in 'field list' 238drop procedure p1| 239SET sql_mode = default| 240create procedure p1() 241begin 242prepare stmt from 'select ? as a'; 243execute stmt using @a; 244end| 245set @a=1| 246call p1()| 247a 2481 249call p1()| 250a 2511 252drop procedure p1| 253drop table if exists t1| 254drop table if exists t2| 255Warnings: 256Note 1051 Unknown table 'test.t2' 257create table t1 (id integer primary key auto_increment, 258stmt_text char(35), status varchar(20))| 259insert into t1 (stmt_text) values 260("select 1"), ("flush tables"), ("handler t1 open as ha"), 261("analyze table t1"), ("check table t1"), ("checksum table t1"), 262("check table t1"), ("optimize table t1"), ("repair table t1"), 263("describe extended select * from t1"), 264("help help"), ("show databases"), ("show tables"), 265("show table status"), ("show open tables"), ("show storage engines"), 266("insert into t1 (id) values (1)"), ("update t1 set status=''"), 267("delete from t1"), ("truncate t1"), ("call p1()"), ("foo bar"), 268("create view v1 as select 1"), ("alter view v1 as select 2"), 269("drop view v1"),("create table t2 (a int)"),("alter table t2 add (b int)"), 270("drop table t2")| 271create procedure p1() 272begin 273declare v_stmt_text varchar(255); 274declare v_id integer; 275declare done int default 0; 276declare c cursor for select id, stmt_text from t1; 277declare continue handler for 1295 -- ER_UNSUPPORTED_PS 278set @status='not supported'; 279declare continue handler for 1064 -- ER_SYNTAX_ERROR 280set @status='syntax error'; 281declare continue handler for sqlstate '02000' set done = 1; 282prepare update_stmt from "update t1 set status=? where id=?"; 283open c; 284repeat 285if not done then 286fetch c into v_id, v_stmt_text; 287set @id=v_id, @stmt_text=v_stmt_text; 288set @status="supported"; 289prepare stmt from @stmt_text; 290execute update_stmt using @status, @id; 291end if; 292until done end repeat; 293deallocate prepare update_stmt; 294end| 295call p1()| 296select * from t1| 297id stmt_text status 2981 select 1 supported 2992 flush tables supported 3003 handler t1 open as ha not supported 3014 analyze table t1 supported 3025 check table t1 not supported 3036 checksum table t1 supported 3047 check table t1 not supported 3058 optimize table t1 supported 3069 repair table t1 supported 30710 describe extended select * from t1 supported 30811 help help not supported 30912 show databases supported 31013 show tables supported 31114 show table status supported 31215 show open tables supported 31316 show storage engines supported 31417 insert into t1 (id) values (1) supported 31518 update t1 set status='' supported 31619 delete from t1 supported 31720 truncate t1 supported 31821 call p1() supported 31922 foo bar syntax error 32023 create view v1 as select 1 supported 32124 alter view v1 as select 2 not supported 32225 drop view v1 supported 32326 create table t2 (a int) supported 32427 alter table t2 add (b int) supported 32528 drop table t2 supported 326drop procedure p1| 327drop table t1| 328prepare stmt from 'select 1'| 329create procedure p1() execute stmt| 330call p1()| 3311 3321 333call p1()| 3341 3351 336drop procedure p1| 337create function f1() returns int 338begin 339deallocate prepare stmt; 340return 1; 341end| 342ERROR 0A000: Dynamic SQL is not allowed in stored function or trigger 343create procedure p1() 344begin 345prepare stmt from 'select 1 A'; 346execute stmt; 347end| 348prepare stmt from 'call p1()'| 349execute stmt| 350ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 351execute stmt| 352ERROR HY000: The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner 353drop procedure p1| 354drop table if exists t1, t2| 355create procedure p1 (a int) language sql deterministic 356begin 357declare rsql varchar(100); 358drop table if exists t1, t2; 359set @rsql= "create table t1 (a int)"; 360select @rsql; 361prepare pst from @rsql; 362execute pst; 363set @rsql= null; 364set @rsql= "create table t2 (a int)"; 365select @rsql; 366prepare pst from @rsql; 367execute pst; 368drop table if exists t1, t2; 369end| 370set @a:=0| 371call p1(@a)| 372@rsql 373create table t1 (a int) 374@rsql 375create table t2 (a int) 376select @a| 377@a 3780 379call p1(@a)| 380@rsql 381create table t1 (a int) 382@rsql 383create table t2 (a int) 384select @a| 385@a 3860 387drop procedure if exists p1| 388