diff options
Diffstat (limited to 'mysql-test/t')
-rw-r--r-- | mysql-test/t/create.test | 1 | ||||
-rw-r--r-- | mysql-test/t/create_drop_trigger.test | 1 | ||||
-rw-r--r-- | mysql-test/t/features.test | 1 | ||||
-rw-r--r-- | mysql-test/t/information_schema.test | 4 | ||||
-rw-r--r-- | mysql-test/t/merge.test | 1 | ||||
-rw-r--r-- | mysql-test/t/mysql_comments.test | 2 | ||||
-rw-r--r-- | mysql-test/t/mysqldump.test | 11 | ||||
-rw-r--r-- | mysql-test/t/show_check.test | 33 | ||||
-rw-r--r-- | mysql-test/t/trigger-compat.test | 6 | ||||
-rw-r--r-- | mysql-test/t/trigger.test | 44 | ||||
-rw-r--r-- | mysql-test/t/trigger_notembedded.test | 2 | ||||
-rw-r--r-- | mysql-test/t/trigger_wl3253.test | 428 |
12 files changed, 526 insertions, 8 deletions
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 0fd3e31a5b4..d619fed240f 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1297,7 +1297,6 @@ BEGIN UPDATE A SET `pk`=1 WHERE `pk`=0 ; END ;| ---error ER_NOT_SUPPORTED_YET CREATE TRIGGER f1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN UPDATE A SET `pk`=1 WHERE `pk`=0 ; diff --git a/mysql-test/t/create_drop_trigger.test b/mysql-test/t/create_drop_trigger.test index a8afc8716d6..0f19f5cf09f 100644 --- a/mysql-test/t/create_drop_trigger.test +++ b/mysql-test/t/create_drop_trigger.test @@ -6,7 +6,6 @@ SET @sum=0; INSERT INTO t1 VALUES (10), (20), (30); SELECT @sum; ---error ER_NOT_SUPPORTED_YET CREATE TRIGGER IF NOT EXISTS val_sum_new BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val; CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + 1 + NEW.val; diff --git a/mysql-test/t/features.test b/mysql-test/t/features.test index 63e923a772b..1241bd50bdd 100644 --- a/mysql-test/t/features.test +++ b/mysql-test/t/features.test @@ -98,6 +98,7 @@ set @a:=0; select @a; insert into t1 values (1),(2); select @a; +--replace_column 6 # SHOW TRIGGERS IN test like 't1'; drop trigger trg; drop table t1; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 13f368b6dbe..1443f654809 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -576,7 +576,9 @@ begin end if; end| delimiter ;| +--replace_column 6 # show triggers; +--replace_column 17 # select * from information_schema.triggers where trigger_schema in ('mysql', 'information_schema', 'test', 'mysqltest'); drop trigger trg1; @@ -1034,12 +1036,14 @@ grant select(b) on mysqltest.t1 to mysqltest_1@localhost; select trigger_name from information_schema.triggers where event_object_table='t1'; +--replace_column 6 # show triggers from mysqltest; connect (con27629,localhost,mysqltest_1,,mysqltest); show columns from t1; select column_name from information_schema.columns where table_name='t1'; +--replace_column 6 # show triggers; select trigger_name from information_schema.triggers where event_object_table='t1'; diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index faa420fd275..689c52faabc 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -1678,6 +1678,7 @@ CREATE TABLE t1(a int); CREATE TABLE t2(a int); CREATE TABLE t3(a int) ENGINE = MERGE UNION(t1, t2); CREATE TRIGGER tr1 AFTER INSERT ON t3 FOR EACH ROW CALL foo(); +--replace_column 7 # SHOW CREATE TRIGGER tr1; DROP TRIGGER tr1; DROP TABLE t1, t2, t3; diff --git a/mysql-test/t/mysql_comments.test b/mysql-test/t/mysql_comments.test index 7b00f17e259..fb0e5f94950 100644 --- a/mysql-test/t/mysql_comments.test +++ b/mysql-test/t/mysql_comments.test @@ -30,10 +30,12 @@ drop trigger if exists t1_bi; # Test without comments --echo "Pass 1 : --disable-comments" +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL --disable-comments test 2>&1 < "./t/mysql_comments.sql" # Test with comments --echo "Pass 2 : --enable-comments" +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL --enable-comments test 2>&1 < "./t/mysql_comments.sql" diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index ccc68485bd6..299698ed04b 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1007,6 +1007,7 @@ SELECT * FROM `test2`; #DROP TABLE test2; # restore --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump.sql +--replace_column 6 # SHOW TRIGGERS; SELECT * FROM `test1`; SELECT * FROM `test2`; @@ -2053,6 +2054,7 @@ CREATE PROCEDURE pr1 () SELECT "Meow"; CREATE EVENT ev1 ON SCHEDULE AT '2030-01-01 00:00:00' DO SELECT "Meow"; --echo +--replace_column 6 # SHOW TRIGGERS; SHOW EVENTS; SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; @@ -2071,6 +2073,7 @@ DROP PROCEDURE pr1; --echo --echo reload table; this should restore table and trigger --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/t1.sql +--replace_column 6 # SHOW TRIGGERS; SHOW EVENTS; SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; @@ -2078,6 +2081,7 @@ SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; --echo --echo reload db; this should restore routines and events --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/test_34861.sql +--replace_column 6 # SHOW TRIGGERS; SHOW EVENTS; SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; @@ -2311,13 +2315,13 @@ CREATE VIEW v2 AS SELECT * FROM t2; --echo # Dumping BUG52792 database in xml format. --echo --echo # Running 'replace_regex on timestamp' ---replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/--TIME--/ +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL_DUMP --user=root --compact -R -E --triggers -X BUG52792 --echo --echo # Dumping BUG52792 database in xml format with comments. --echo --echo # Running 'replace_regex on timestamp' ---replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/--TIME--/ +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL_DUMP --comments --user=root -R -E --triggers -X BUG52792 --echo @@ -2330,7 +2334,8 @@ connect (conn_1, localhost, user1, , BUG52792, $MASTER_MYPORT, $MASTER_MYSOCK); connection conn_1; --echo # Running 'replace_regex on timestamp' ---replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/--TIME--/ +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ + --replace_result mysqldump.exe mysqldump --error 2 --exec $MYSQL_DUMP --user=user1 -R -E --triggers -X BUG52792 diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index a14c42d8ade..13ca9a528c6 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -774,6 +774,7 @@ SHOW COLUMNS FROM t1; --echo ---------------------------------------------------------------- +--replace_column 6 # SHOW TRIGGERS LIKE 't1'; --echo ---------------------------------------------------------------- @@ -799,6 +800,14 @@ SELECT FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 't1_bi'; +# Metadata is different for the field "CREATED" with and without --ps +# So test it separately. + +--disable_ps_protocol +--replace_column 1 # +SELECT CREATED FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name='t1_bi'; +--enable_ps_protocol + --echo ---------------------------------------------------------------- SHOW CREATE VIEW v1; @@ -1092,32 +1101,53 @@ CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a = 1; # Test. +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; CREATE PROCEDURE p1() SHOW CREATE TRIGGER t1_bi; +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); PREPARE stmt1 FROM 'SHOW CREATE TRIGGER t1_bi'; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; # Cleanup. @@ -1178,6 +1208,7 @@ SHOW CREATE PROCEDURE p1; SHOW CREATE FUNCTION f1; +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; SHOW CREATE EVENT ev1; @@ -1291,6 +1322,7 @@ LOCK TABLE t1 WRITE; connection default; # Should not block. +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; connection con1; @@ -1300,6 +1332,7 @@ UNLOCK TABLES; connection default; START TRANSACTION; +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; connection con1; diff --git a/mysql-test/t/trigger-compat.test b/mysql-test/t/trigger-compat.test index 2d949b0c91e..437df89b4b1 100644 --- a/mysql-test/t/trigger-compat.test +++ b/mysql-test/t/trigger-compat.test @@ -90,6 +90,7 @@ SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_n --echo +--replace_column 17 # SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; # Clean up @@ -181,6 +182,7 @@ FLUSH TABLE t2; CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1); --error ER_PARSE_ERROR CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table; +--replace_column 6 # SHOW TRIGGERS; --error ER_PARSE_ERROR INSERT INTO t1 VALUES (1); @@ -193,6 +195,7 @@ UPDATE t1 SET a = 1 WHERE a = 1; SELECT * FROM t1; --error ER_PARSE_ERROR RENAME TABLE t1 TO t1_2; +--replace_column 6 # SHOW TRIGGERS; DROP TRIGGER tr11; @@ -201,6 +204,7 @@ DROP TRIGGER tr13; DROP TRIGGER tr14; DROP TRIGGER tr15; +--replace_column 6 # SHOW TRIGGERS; --echo # Make sure there is no trigger file left. @@ -257,7 +261,7 @@ INSERT INTO t2 VALUES (1), (2), (3); --echo # We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct --echo # and last trigger is broken. ---echo # Next we try to execute SHOW CREATE TRGGIR command for broken trigger and then try to drop one. +--echo # Next we try to execute SHOW CREATE TRIGGER command for broken trigger and then try to drop one. --write_file $MYSQLD_DATADIR/test/tr11.TRN TYPE=TRIGGERNAME trigger_table=t1 diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index a02dce34837..050bd5ea56e 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -324,8 +324,8 @@ create trigger trg before insert on t2 for each row set @a:=1; create trigger trg before insert on t1 for each row set @a:=1; --error ER_TRG_ALREADY_EXISTS create trigger trg after insert on t1 for each row set @a:=1; ---error ER_NOT_SUPPORTED_YET create trigger trg2 before insert on t1 for each row set @a:=1; +drop trigger trg2; --error ER_TRG_ALREADY_EXISTS create trigger trg before insert on t3 for each row set @a:=1; create trigger trg2 before insert on t3 for each row set @a:=1; @@ -2238,9 +2238,9 @@ create table t1 (i int, j int); create trigger t1_bi before insert on t1 for each row begin end; --error ER_TRG_ALREADY_EXISTS create trigger t1_bi before insert on t1 for each row begin end; ---error ER_NOT_SUPPORTED_YET create trigger t1_bi2 before insert on t1 for each row begin end; drop trigger t1_bi; +drop trigger t1_bi2; --error ER_TRG_DOES_NOT_EXIST drop trigger t1_bi; @@ -2392,6 +2392,7 @@ CREATE TABLE t2 (a INT); CREATE TRIGGER trg1 BEFORE INSERT ON t2 FOR EACH ROW INSERT/*!INTO*/t1 VALUES (1); --echo # Used to crash +--replace_column 6 # SHOW TRIGGERS IN db1; --error ER_PARSE_ERROR INSERT INTO t2 VALUES (1); @@ -2614,8 +2615,11 @@ DROP TABLE t1, t2; # # MDEV-4829 BEFORE INSERT triggers dont issue 1406 error +# Also check timestamp for trigger # +set time_zone="+00:00"; +SET TIMESTAMP=UNIX_TIMESTAMP('2001-01-01 10:20:30'); SET @@session.sql_mode = 'STRICT_ALL_TABLES,STRICT_TRANS_TABLES'; CREATE TABLE t1 (c CHAR(1) NOT NULL); DELIMITER |; @@ -2631,6 +2635,42 @@ DELIMITER ;| SET @@session.sql_mode = default; --error ER_DATA_TOO_LONG INSERT INTO t1 VALUES ('a'); +show create trigger t1_bi; DROP TRIGGER t1_bi; DROP TABLE t1; +SET TIMESTAMP=DEFAULT; +set time_zone= @@global.time_zone; + +# +# MDEV-10915 Count number of exceuted triggers +# + +create table t1 (i int); +create trigger tr1 after insert on t1 for each row set @a=@a+1; +create trigger tr2 after insert on t1 for each row set @a=@a+1; +create trigger tr3 after insert on t1 for each row set @a=@a+1; +flush status; +show status like 'Executed_triggers'; +set @a=0; +insert into t1 values (1); +show status like 'Executed_triggers'; +select @a; +drop table t1; + +# +# MDEV-10916 In trigger's CREATED time microseconds are misinterpreted +# +create table t1 (i int); +set time_zone="+0:00"; +SET TIMESTAMP=UNIX_TIMESTAMP('2016-01-01 10:10:10.33'); +select now(2); +create or replace trigger tr1 after insert on t1 for each row set @a=@a+1; +SET TIMESTAMP=UNIX_TIMESTAMP('2016-01-01 10:10:10.99'); +select now(2); +create or replace trigger tr2 after insert on t1 for each row set @a=@a+1; +select now(2); +select trigger_name, action_order, created from information_schema.triggers + where event_object_table = 't1' and trigger_schema='test'; +drop table t1; +set time_zone= @@global.time_zone; diff --git a/mysql-test/t/trigger_notembedded.test b/mysql-test/t/trigger_notembedded.test index df5637790af..a31594826e7 100644 --- a/mysql-test/t/trigger_notembedded.test +++ b/mysql-test/t/trigger_notembedded.test @@ -281,6 +281,7 @@ INSERT INTO t1 VALUES(6); # Check that SHOW TRIGGERS statement provides "Definer" column. # +--replace_column 6 # SHOW TRIGGERS; # @@ -339,6 +340,7 @@ SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_n --echo +--replace_column 17 # SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; # diff --git a/mysql-test/t/trigger_wl3253.test b/mysql-test/t/trigger_wl3253.test new file mode 100644 index 00000000000..3504eeaf889 --- /dev/null +++ b/mysql-test/t/trigger_wl3253.test @@ -0,0 +1,428 @@ +--echo # +--echo # WL#3253: multiple triggers per table +--echo # + +SET @binlog_format_saved = @@binlog_format; +SET binlog_format=ROW; +SET time_zone='+00:00'; + +--echo # +--echo # Test 1. +--echo # Check that the sequence of triggers for the same combination +--echo # of event type/action type can be created for a table +--echo # and is fired consequently in the order of its creation +--echo # during statement execution. +--echo # In this test we check BEFORE triggers. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); + +INSERT INTO t1 VALUES (1); + +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 2. +--echo # Check that the sequence of triggers for the same combination +--echo # of event type/action type can be created for a table +--echo # and is fired consequently in the order of its creation +--echo # during statement execution. +--echo # In this test we check AFTER triggers. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bi AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); + +INSERT INTO t1 VALUES (1); + +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 3. +--echo # Check that the sequences of triggers for the different event types +--echo # can be created for a table and are fired consequently +--echo # in the order of its creation during statement execution. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); + +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bu BEFORE UPDATE ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 300); + +INSERT INTO t1 VALUES (1); + +SELECT * FROM t2 ORDER BY b; + +UPDATE t1 SET a = 5; + +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 4. +--echo # Check that every new created trigger has unique action_order value +--echo # started from 1 and NOT NULL value for creation timestamp. +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:00'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; + +SELECT trigger_name, created, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 5. +--echo # Check that action_order attribute isn't shown +--echo # in the output of SHOW TRIGGERS and SHOW CREATE TRIGGER +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; + +--replace_column 6 # +SHOW TRIGGERS; + +--replace_column 17 # +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +--replace_column 7 # +SHOW CREATE TRIGGER tr1_bi; + +DROP TABLE t1; + +--echo # +--echo # Test 6. +--echo # Check that action_order attribute is reused when trigger +--echo # are recreated. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TRIGGER tr1_bi; + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 7. +--echo # Check that it is possible to create several triggers with +--echo # the same value for creation timestamp. +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; + +SELECT trigger_name, created, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 8. +--echo # Check that SHOW CREATE TRIGGER outputs the CREATED attribute +--echo # and it is not NULL +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +SHOW CREATE TRIGGER tr1_bi; + +DROP TABLE t1; +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 9. +--echo # Check that SHOW TRIGGERS outputs the CREATED attribute +--echo # and it is not NULL. +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; + +SHOW TRIGGERS; + +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +DROP TABLE t1; + +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 10. +--echo # Check that FOLLOWS clause is supported and works correctly. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 300); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr1_bi INSERT INTO t2 (a) VALUES (NEW.a + 200); + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +INSERT INTO t1 VALUES (1); +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 11. +--echo # Check that PRECEDES clause is supported and works correctly. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 300); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr3_bi INSERT INTO t2 (a) VALUES (NEW.a + 200); + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +INSERT INTO t1 VALUES (1); +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 12. +--echo # Check that the PRECEDES works properly for the 1st trigger in the chain. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); +CREATE TRIGGER tr0_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr1_bi INSERT INTO t2 (a) VALUES (NEW.a); + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +INSERT INTO t1 VALUES (1); +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 13. +--echo # Check that error is reported if the FOLLOWS clause references to +--echo # non-existing trigger +--echo # + +CREATE TABLE t1 (a INT); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr0_bi SET @a:=2; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 14. +--echo # Check that error is reported if the PRECEDES clause references to +--echo # non-existing trigger +--echo # + +CREATE TABLE t1 (a INT); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr0_bi SET @a:=2; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 15. +--echo # Check that action_order value is independent for each type of event +--echo # (INSERT/UPDATE/DELETE) +--echo # + +CREATE TABLE t1 (a INT); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr2_bi SET @a:=3; +CREATE TRIGGER tr2_bu BEFORE UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bu SET @a:=3; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 16. +--echo # Check that the trigger in the clause FOLLOWS/PRECEDES can refences +--echo # only to the trigger for the same ACTION/TIMINMG +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_bu BEFORE UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_au AFTER UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr1_au AFTER UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bu SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr1_ai AFTER INSERT ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=3; + +--replace_column 6 # +SHOW TRIGGERS; + +--replace_column 17 # +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +DROP TABLE t1; + +# Binlog is required +--source include/have_log_bin.inc + +--echo # +--echo # Test 17. Check that table's triggers are dumped correctly. +--echo # +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; + +# dump tables and triggers +--exec $MYSQL_DUMP --compact test + +DROP TABLE t1; + +--echo # +--echo # Test 18. Check that table's triggers are dumped in right order +--echo # taking into account the PRECEDES/FOLLOWS clauses. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr0_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr1_bi SET @a:=0; +CREATE TRIGGER tr1_1_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=0; + +--echo # Expected order of triggers in the dump is: tr0_bi, tr1_bi, tr1_1_bi, tr2_i. +# dump tables and triggers +--exec $MYSQL_DUMP --compact test + +DROP TABLE t1; + +--echo # +--echo # Test 19. Check that table's triggers are dumped correctly in xml. +--echo # + +CREATE TABLE t1 (a INT); +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:00'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; +SET TIMESTAMP=DEFAULT; + +# dump tables and triggers +--exec $MYSQL_DUMP --compact --no-create-info --xml test + +DROP TABLE t1; + +--echo # +--echo # Test 20. Check that the statement CHECK TABLE FOR UPGRADE outputs +--echo # the warnings for triggers created by a server without support for wl3253. +--echo # + +CREATE TABLE t1 (a INT); + +let $MYSQLD_DATADIR=`SELECT @@datadir`; +--write_file $MYSQLD_DATADIR/test/t1.TRG +TYPE=TRIGGERS +triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr1_ai AFTER INSERT ON t1 FOR EACH ROW SET @a:=2' +sql_modes=1073741824 1073741824 +definers='root@localhost' 'root@localhost' +client_cs_names='latin1' 'latin1' +connection_cl_names='latin1_swedish_ci' 'latin1_swedish_ci' +db_cl_names='latin1_swedish_ci' 'latin1_swedish_ci' +EOF + +--write_file $MYSQLD_DATADIR/test/tr1_bi.TRN +TYPE=TRIGGERNAME +trigger_table=t1 +EOF + +--write_file $MYSQLD_DATADIR/test/tr1_ai.TRN +TYPE=TRIGGERNAME +trigger_table=t1 +EOF + +FLUSH TABLE t1; + +CHECK TABLE t1 FOR UPGRADE; + +SHOW TRIGGERS; + +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +SHOW CREATE TRIGGER tr1_bi; +SHOW CREATE TRIGGER tr1_ai; + +DROP TABLE t1; + +SET binlog_format=@binlog_format_saved; + +--echo # End of tests. +--echo # |