Browse Source
MDEV-5317 Compound statement / anonymous blocks
MDEV-5317 Compound statement / anonymous blocks
originally based on the patch by Antony T Curtispull/69/head
87 changed files with 523 additions and 106 deletions
-
121mysql-test/r/compound.result
-
2mysql-test/r/mysqld--help.result
-
2mysql-test/suite/perfschema/r/ortho_iter.result
-
2mysql-test/suite/perfschema/r/privilege_table_io.result
-
10mysql-test/suite/perfschema/r/rpl_gtid_func.result
-
2mysql-test/suite/perfschema/r/start_server_disable_idle.result
-
2mysql-test/suite/perfschema/r/start_server_disable_stages.result
-
2mysql-test/suite/perfschema/r/start_server_disable_statements.result
-
2mysql-test/suite/perfschema/r/start_server_disable_waits.result
-
2mysql-test/suite/perfschema/r/start_server_innodb.result
-
2mysql-test/suite/perfschema/r/start_server_no_account.result
-
2mysql-test/suite/perfschema/r/start_server_no_cond_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_cond_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_file_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_file_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_host.result
-
2mysql-test/suite/perfschema/r/start_server_no_mutex_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_mutex_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_rwlock_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_rwlock_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_setup_actors.result
-
2mysql-test/suite/perfschema/r/start_server_no_setup_objects.result
-
2mysql-test/suite/perfschema/r/start_server_no_socket_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_socket_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_stage_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_stages_history.result
-
2mysql-test/suite/perfschema/r/start_server_no_stages_history_long.result
-
2mysql-test/suite/perfschema/r/start_server_no_statements_history.result
-
2mysql-test/suite/perfschema/r/start_server_no_statements_history_long.result
-
2mysql-test/suite/perfschema/r/start_server_no_table_hdl.result
-
2mysql-test/suite/perfschema/r/start_server_no_table_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_thread_class.result
-
2mysql-test/suite/perfschema/r/start_server_no_thread_inst.result
-
2mysql-test/suite/perfschema/r/start_server_no_user.result
-
2mysql-test/suite/perfschema/r/start_server_no_waits_history.result
-
2mysql-test/suite/perfschema/r/start_server_no_waits_history_long.result
-
2mysql-test/suite/perfschema/r/start_server_off.result
-
2mysql-test/suite/perfschema/r/start_server_on.result
-
41mysql-test/suite/perfschema/r/statement_digest.result
-
44mysql-test/suite/perfschema/r/statement_digest_consumers.result
-
7mysql-test/suite/perfschema/r/statement_digest_long_query.result
-
2mysql-test/suite/perfschema/r/table_aggregate_global_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_global_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_global_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_global_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_hist_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_hist_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_hist_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_hist_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_off.result
-
2mysql-test/suite/perfschema/r/table_aggregate_thread_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_thread_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_thread_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_aggregate_thread_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_global_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_global_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_global_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_global_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_hist_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_hist_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_hist_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_hist_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_thread_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_thread_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_thread_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_io_aggregate_thread_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_global_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_global_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_global_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_global_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_hist_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_hist_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_hist_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_hist_4u_3t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_thread_2u_2t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_thread_2u_3t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_thread_4u_2t.result
-
2mysql-test/suite/perfschema/r/table_lock_aggregate_thread_4u_3t.result
-
115mysql-test/t/compound.test
-
1sql/lex.h
-
1sql/mysqld.cc
-
10sql/sp_head.cc
-
1sql/sql_cmd.h
-
23sql/sql_lex.cc
-
9sql/sql_parse.cc
-
17sql/sql_prepare.cc
-
83sql/sql_yacc.yy
@ -0,0 +1,121 @@ |
|||
CREATE TABLE t1 (a INT PRIMARY KEY)| |
|||
BEGIN NOT ATOMIC |
|||
INSERT INTO t1 VALUES (1); |
|||
INSERT INTO t1 VALUES (2); |
|||
INSERT INTO t1 VALUES (3); |
|||
END| |
|||
SELECT * FROM t1| |
|||
a |
|||
1 |
|||
2 |
|||
3 |
|||
PREPARE stmt FROM "BEGIN NOT ATOMIC |
|||
INSERT INTO t1 VALUES (4); |
|||
INSERT INTO t1 VALUES (5); |
|||
INSERT INTO t1 VALUES (?); |
|||
END"; |
|||
SET @val = 6| |
|||
EXECUTE stmt USING @val| |
|||
SELECT * FROM t1| |
|||
a |
|||
1 |
|||
2 |
|||
3 |
|||
4 |
|||
5 |
|||
6 |
|||
PREPARE stmt FROM "BEGIN NOT ATOMIC |
|||
DECLARE v_res INT; |
|||
SELECT COUNT(*) INTO v_res FROM t1; |
|||
SELECT 'Hello World', v_res INTO ?,?; |
|||
END"| |
|||
SET @val="", @val2=""| |
|||
EXECUTE stmt USING @val, @val2| |
|||
SELECT @val, @val2| |
|||
@val @val2 |
|||
Hello World 6 |
|||
DROP TABLE t1| |
|||
CREATE DATABASE mysqltest1| |
|||
CREATE PROCEDURE mysqltest1.sp1() |
|||
BEGIN |
|||
PREPARE stmt FROM "BEGIN NOT ATOMIC CREATE TABLE t1 AS SELECT DATABASE(); END"; |
|||
EXECUTE stmt; |
|||
END| |
|||
CALL mysqltest1.sp1()| |
|||
SELECT * FROM mysqltest1.t1| |
|||
DATABASE() |
|||
mysqltest1 |
|||
USE mysqltest1| |
|||
DROP DATABASE mysqltest1| |
|||
BEGIN NOT ATOMIC CREATE TABLE t1(a int); END| |
|||
ERROR 3D000: No database selected |
|||
BEGIN NOT ATOMIC SET @a=1; CREATE TABLE test.t1(a int); END| |
|||
USE test| |
|||
show tables| |
|||
Tables_in_test |
|||
t1 |
|||
drop table t1| |
|||
/**/ if (select count(*) from information_schema.tables |
|||
where table_schema='test' and table_name='t1') = 0 |
|||
then |
|||
create table t1 (a int); |
|||
end if| |
|||
show tables| |
|||
Tables_in_test |
|||
t1 |
|||
/**/ if (select count(*) from information_schema.tables |
|||
where table_schema='test' and table_name='t1') = 0 |
|||
then |
|||
create table t1 (a int); |
|||
end if| |
|||
show tables| |
|||
Tables_in_test |
|||
t1 |
|||
case (select table_name from information_schema.tables where table_schema='test') |
|||
when 't1' then create table t2 (b int); |
|||
when 't2' then create table t3 (b int); |
|||
else signal sqlstate '42S02'; |
|||
end case| |
|||
show tables| |
|||
Tables_in_test |
|||
t1 |
|||
t2 |
|||
case |
|||
when database() = 'test' then create table t3 (test text); |
|||
when now() < date'2001-02-03' then create table oops (machine time); |
|||
end case| |
|||
show tables| |
|||
Tables_in_test |
|||
t1 |
|||
t2 |
|||
t3 |
|||
loop |
|||
create table t4 (a int); |
|||
end loop| |
|||
ERROR 42S01: Table 't4' already exists |
|||
show tables| |
|||
Tables_in_test |
|||
t1 |
|||
t2 |
|||
t3 |
|||
t4 |
|||
set @a=0; |
|||
repeat |
|||
set @a = @a + 1; |
|||
until @a > 5 |
|||
end repeat| |
|||
select @a| |
|||
@a |
|||
6 |
|||
/**/ while (select count(*) from information_schema.tables where table_schema='test') |
|||
do |
|||
select concat('drop table ', table_name) into @a |
|||
from information_schema.tables where table_schema='test' limit 1; |
|||
select @a as 'executing:'; |
|||
prepare dt from @a; |
|||
execute dt; |
|||
end while| |
|||
executing: drop table t1 |
|||
executing: drop table t2 |
|||
executing: drop table t3 |
|||
executing: drop table t4 |
|||
@ -0,0 +1,115 @@ |
|||
# |
|||
# MDEV-5317 Compound statement / anonymous blocks |
|||
# |
|||
delimiter |; |
|||
|
|||
CREATE TABLE t1 (a INT PRIMARY KEY)| |
|||
|
|||
BEGIN NOT ATOMIC |
|||
INSERT INTO t1 VALUES (1); |
|||
INSERT INTO t1 VALUES (2); |
|||
INSERT INTO t1 VALUES (3); |
|||
END| |
|||
|
|||
SELECT * FROM t1| |
|||
PREPARE stmt FROM "BEGIN NOT ATOMIC |
|||
INSERT INTO t1 VALUES (4); |
|||
INSERT INTO t1 VALUES (5); |
|||
INSERT INTO t1 VALUES (?); |
|||
END"; |
|||
SET @val = 6| |
|||
EXECUTE stmt USING @val| |
|||
SELECT * FROM t1| |
|||
|
|||
PREPARE stmt FROM "BEGIN NOT ATOMIC |
|||
DECLARE v_res INT; |
|||
SELECT COUNT(*) INTO v_res FROM t1; |
|||
SELECT 'Hello World', v_res INTO ?,?; |
|||
END"| |
|||
SET @val="", @val2=""| |
|||
EXECUTE stmt USING @val, @val2| |
|||
SELECT @val, @val2| |
|||
DROP TABLE t1| |
|||
|
|||
# |
|||
# test for default database |
|||
# |
|||
# * SP db is different from the current db |
|||
CREATE DATABASE mysqltest1| |
|||
CREATE PROCEDURE mysqltest1.sp1() |
|||
BEGIN |
|||
PREPARE stmt FROM "BEGIN NOT ATOMIC CREATE TABLE t1 AS SELECT DATABASE(); END"; |
|||
EXECUTE stmt; |
|||
END| |
|||
|
|||
CALL mysqltest1.sp1()| |
|||
SELECT * FROM mysqltest1.t1| |
|||
|
|||
USE mysqltest1| |
|||
DROP DATABASE mysqltest1| |
|||
|
|||
# * no current db |
|||
--error ER_NO_DB_ERROR |
|||
BEGIN NOT ATOMIC CREATE TABLE t1(a int); END| |
|||
|
|||
BEGIN NOT ATOMIC SET @a=1; CREATE TABLE test.t1(a int); END| |
|||
|
|||
USE test| |
|||
show tables| |
|||
drop table t1| |
|||
|
|||
# IF (without /**/ mysqltest treats if as its own command) |
|||
/**/ if (select count(*) from information_schema.tables |
|||
where table_schema='test' and table_name='t1') = 0 |
|||
then |
|||
create table t1 (a int); |
|||
end if| |
|||
show tables| |
|||
/**/ if (select count(*) from information_schema.tables |
|||
where table_schema='test' and table_name='t1') = 0 |
|||
then |
|||
create table t1 (a int); |
|||
end if| |
|||
show tables| |
|||
|
|||
# CASE simple |
|||
case (select table_name from information_schema.tables where table_schema='test') |
|||
when 't1' then create table t2 (b int); |
|||
when 't2' then create table t3 (b int); |
|||
else signal sqlstate '42S02'; |
|||
end case| |
|||
show tables| |
|||
|
|||
# CASE searched |
|||
case |
|||
when database() = 'test' then create table t3 (test text); |
|||
when now() < date'2001-02-03' then create table oops (machine time); |
|||
end case| |
|||
show tables| |
|||
|
|||
# LOOP |
|||
--error ER_TABLE_EXISTS_ERROR |
|||
loop |
|||
create table t4 (a int); |
|||
end loop| |
|||
show tables| |
|||
|
|||
# REPEAT |
|||
set @a=0; |
|||
repeat |
|||
set @a = @a + 1; |
|||
until @a > 5 |
|||
end repeat| |
|||
select @a| |
|||
|
|||
# WHILE |
|||
--vertical_results |
|||
/**/ while (select count(*) from information_schema.tables where table_schema='test') |
|||
do |
|||
select concat('drop table ', table_name) into @a |
|||
from information_schema.tables where table_schema='test' limit 1; |
|||
select @a as 'executing:'; |
|||
prepare dt from @a; |
|||
execute dt; |
|||
end while| |
|||
--horizontal_results |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue