mariadb/mysql-test/t/compound.test
Monty 9cba6c5aa3 Updated mtr files to support different compiled in options
This allows one to run the test suite even if any of the following
options are changed:
- character-set-server
- collation-server
- join-cache-level
- log-basename
- max-allowed-packet
- optimizer-switch
- query-cache-size and query-cache-type
- skip-name-resolve
- table-definition-cache
- table-open-cache
- Some innodb options
etc

Changes:
- Don't print out the value of system variables as one can't depend on
  them to being constants.
- Don't set global variables to 'default' as the default may not
  be the same as the test was started with if there was an additional
  option file. Instead save original value and reset it at end of test.
- Test that depends on the latin1 character set should include
  default_charset.inc or set the character set to latin1
- Test that depends on the original optimizer switch, should include
  default_optimizer_switch.inc
- Test that depends on the value of a specific system variable should
  set it in the test (like optimizer_use_condition_selectivity)
- Split subselect3.test into subselect3.test and subselect3.inc to
  make it easier to set and reset system variables.
- Added .opt files for test that required specfic options that could
  be changed by external configuration files.
- Fixed result files in rockdsb & tokudb that had not been updated for
  a while.
2019-09-01 19:17:35 +03:00

161 lines
3.5 KiB
Text

#
# MDEV-5317 Compound statement / anonymous blocks
#
source include/have_log_bin.inc;
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|
reset master|
EXECUTE stmt USING @val|
SELECT * FROM t1|
# see how ?-placeholder was replaced with the value
delimiter ;|
source include/show_binlog_events.inc;
delimiter |;
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
# see how ?-placeholder and SP variables are replaced with values
create table t1 (x int)|
create function fn(a int) returns int
begin
insert t1 values (a+7);
return a+8;
end|
reset master|
/**/ if fn(9) > 5 then
select 1;
end if|
prepare stmt from "if fn(?) > 6 then
begin
declare a int;
set a=?*2;
insert t1 values(a+?);
end;
end if"|
set @a=1, @b=2, @c=3|
execute stmt using @a, @b, @c|
delimiter ;|
source include/show_binlog_events.inc;
delimiter |;
drop function fn|
drop table t1|
#
# MDEV-6606 Server crashes in String::append on selecting sql_mode inside anonymous block
# MDEV-6609 SQL inside an anonymous block is executed with wrong SQL_MODE
#
set @@sql_mode="STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
begin not atomic select @@sql_mode; end|
create table t1 (a int)|
select a from t1 having a > 1|
begin not atomic select a from t1 having a > 1; end|
drop table t1|
--echo #
--echo # MDEV-8615: Assertion `m_cpp_buf <= begin_ptr &&
--echo # begin_ptr <= m_cpp_buf + m_buf_length' failed in
--echo # Lex_input_stream::body_utf8_start
--echo #
--error ER_PARSE_ERROR
--query b'