--echo # Bug#45235: 5.1 does not support 5.0-only syntax triggers in any way
--echo #
let $MYSQLD_DATADIR=`SELECT @@datadir`;
--disable_warnings
DROP TABLE IF EXISTS t1, t2, t3;
--enable_warnings
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
CREATE TABLE t3 ( a INT );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1), (2), (3);
INSERT INTO t3 VALUES (1), (2), (3);
--echo # We simulate importing a trigger from 5.0 by writing a .TRN file for
--echo # each trigger plus a .TRG file the way MySQL 5.0 would have done it,
--echo # with syntax allowed in 5.0 only.
--echo #
--echo # Note that in 5.0 the following lines are missing from t1.TRG:
--echo #
--echo # client_cs_names='latin1'
--echo # connection_cl_names='latin1_swedish_ci'
--echo # db_cl_names='latin1_swedish_ci'
--write_file $MYSQLD_DATADIR/test/tr11.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr12.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr13.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr14.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr15.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr12 AFTER INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr13 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr14 AFTER DELETE ON t1 FOR EACH ROW DELETE FROM non_existing_table' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr15 BEFORE UPDATE ON t1 FOR EACH ROW DELETE FROM non_existing_table a USING non_existing_table a'
--echo # We write the same trigger files one more time to test DROP TABLE.
--write_file $MYSQLD_DATADIR/test/tr11.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr12.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr13.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr14.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr15.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr12 AFTER INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr13 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr14 AFTER DELETE ON t1 FOR EACH ROW DELETE FROM non_existing_table' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr15 BEFORE UPDATE ON t1 FOR EACH ROW DELETE FROM non_existing_table a USING non_existing_table a'
triggers='CREATE the wrongest trigger_in_the_world' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr12 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t2'
--echo # MDEV-25659 trigger name is empty after upgrade to 10.4
--echo #
--echo # START: Total triggers 1, broken triggers 1, DROP TABLE
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
--write_file $MYSQLD_DATADIR/test/tr1.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW\nBEGIN\n IF unknown_variable\n THEN\n INSERT INTO t2 VALUES (OLD.a);\n END IF;\nEND'
sql_modes=1411383296
definers='root@localhost'
client_cs_names='utf8'
connection_cl_names='utf8_general_ci'
db_cl_names='latin1_swedish_ci'
created=164206218647
EOF
FLUSH TABLES;
--error ER_PARSE_ERROR
DELETE FROM t1 WHERE a=1;
--error ER_PARSE_ERROR
INSERT INTO t1 VALUES (2);
SET time_zone='+00:00';
--vertical_results
SHOW TRIGGERS LIKE 't1';
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='tr1';
--horizontal_results
SET time_zone=DEFAULT;
--echo # Listing trigger files
--list_files $MYSQLD_DATADIR/test *.TR?
--echo # Listing trigger files done
DROP TABLE t1;
--echo # Listing trigger files
--list_files $MYSQLD_DATADIR/test *.TR?
--echo # Listing trigger files done
--echo # END: Total triggers 1, broken triggers 1, DROP TABLE
--echo # START: Total triggers 1, broken triggers 1, DROP TRIGGER
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
--write_file $MYSQLD_DATADIR/test/tr1.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW\nBEGIN\n IF unknown_variable\n THEN\n INSERT INTO t2 VALUES (OLD.a);\n END IF;\nEND'
sql_modes=1411383296
definers='root@localhost'
client_cs_names='utf8'
connection_cl_names='utf8_general_ci'
db_cl_names='latin1_swedish_ci'
created=164206218647
EOF
FLUSH TABLES;
--error ER_PARSE_ERROR
DELETE FROM t1 WHERE a=1;
--error ER_PARSE_ERROR
INSERT INTO t1 VALUES (2);
SET time_zone='+00:00';
--vertical_results
SHOW TRIGGERS LIKE 't1';
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='tr1';
--horizontal_results
SET time_zone=DEFAULT;
--echo # Listing trigger files
--list_files $MYSQLD_DATADIR/test *.TR?
--echo # Listing trigger files done
DROP TRIGGER tr1;
--echo # Listing trigger files
--list_files $MYSQLD_DATADIR/test *.TR?
--echo # Listing trigger files done
DROP TABLE t1;
--echo # END: Total triggers 1, broken triggers 1, DROP TRIGGER
--echo # START: Total triggers 2, broken triggers 1, DROP TABLE
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
--write_file $MYSQLD_DATADIR/test/tr1.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr2.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr2 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NEW.a+100)' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW\nBEGIN\n IF unknown_variable\n THEN\n INSERT INTO t2 VALUES (OLD.a);\n END IF;\nEND'
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='tr1';
--horizontal_results
SET time_zone=DEFAULT;
--echo # Listing trigger files
--list_files $MYSQLD_DATADIR/test *.TR?
--echo # Listing trigger files done
DROP TABLE t1;
--echo # Listing trigger files
--list_files $MYSQLD_DATADIR/test *.TR?
--echo # Listing trigger files done
--echo # END: Total triggers 2, broken triggers 1, using DROP TABLE
--echo # START: Total triggers 2, broken triggers 1, DROP TRIGGER
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
--write_file $MYSQLD_DATADIR/test/tr1.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr2.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr2 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES (NEW.a+100)' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW\nBEGIN\n IF unknown_variable\n THEN\n INSERT INTO t2 VALUES (OLD.a);\n END IF;\nEND'