1DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
2DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
3DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
4DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
5FLUSH PRIVILEGES;
6DROP DATABASE IF EXISTS mysqltest_db1;
7CREATE DATABASE mysqltest_db1;
8CREATE USER mysqltest_dfn@localhost;
9CREATE USER mysqltest_inv@localhost;
10GRANT CREATE, TRIGGER ON mysqltest_db1.* TO mysqltest_dfn@localhost;
11connect  wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1;
12connection wl2818_definer_con;
13CREATE TABLE t1(num_value INT);
14CREATE TABLE t2(user_str TEXT);
15CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES(CURRENT_USER());
16
17---> patching t1.TRG...
18
19CREATE TRIGGER wl2818_trg2 AFTER INSERT ON t1
20FOR EACH ROW
21INSERT INTO t2 VALUES(CURRENT_USER());
22Warnings:
23Warning	1454	No definer attribute for trigger 'mysqltest_db1'.'wl2818_trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger
24
25SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
26trigger_name	definer
27wl2818_trg1
28wl2818_trg2	mysqltest_dfn@localhost
29
30SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
31TRIGGER_CATALOG	TRIGGER_SCHEMA	TRIGGER_NAME	EVENT_MANIPULATION	EVENT_OBJECT_CATALOG	EVENT_OBJECT_SCHEMA	EVENT_OBJECT_TABLE	ACTION_ORDER	ACTION_CONDITION	ACTION_STATEMENT	ACTION_ORIENTATION	ACTION_TIMING	ACTION_REFERENCE_OLD_TABLE	ACTION_REFERENCE_NEW_TABLE	ACTION_REFERENCE_OLD_ROW	ACTION_REFERENCE_NEW_ROW	CREATED	SQL_MODE	DEFINER	CHARACTER_SET_CLIENT	COLLATION_CONNECTION	DATABASE_COLLATION
32def	mysqltest_db1	wl2818_trg1	INSERT	def	mysqltest_db1	t1	1	NULL	INSERT INTO t2 VALUES(CURRENT_USER())	ROW	BEFORE	NULL	NULL	OLD	NEW	#	STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION		latin1	latin1_swedish_ci	latin1_swedish_ci
33def	mysqltest_db1	wl2818_trg2	INSERT	def	mysqltest_db1	t1	1	NULL	INSERT INTO t2 VALUES(CURRENT_USER())	ROW	AFTER	NULL	NULL	OLD	NEW	#	STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION	mysqltest_dfn@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
34DROP TRIGGER wl2818_trg1;
35Warnings:
36Warning	1454	No definer attribute for trigger 'mysqltest_db1'.'wl2818_trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger
37DROP TRIGGER wl2818_trg2;
38disconnect wl2818_definer_con;
39connection default;
40use mysqltest_db1;
41DROP TABLE t1;
42DROP TABLE t2;
43DROP USER mysqltest_dfn@localhost;
44DROP USER mysqltest_inv@localhost;
45DROP DATABASE mysqltest_db1;
46USE test;
47#
48# Bug#45235: 5.1 does not support 5.0-only syntax triggers in any way
49#
50DROP TABLE IF EXISTS t1, t2, t3;
51CREATE TABLE t1 ( a INT );
52CREATE TABLE t2 ( a INT );
53CREATE TABLE t3 ( a INT );
54INSERT INTO t1 VALUES (1), (2), (3);
55INSERT INTO t2 VALUES (1), (2), (3);
56INSERT INTO t3 VALUES (1), (2), (3);
57# We simulate importing a trigger from 5.0 by writing a .TRN file for
58# each trigger plus a .TRG file the way MySQL 5.0 would have done it,
59# with syntax allowed in 5.0 only.
60#
61# Note that in 5.0 the following lines are missing from t1.TRG:
62#
63# client_cs_names='latin1'
64# connection_cl_names='latin1_swedish_ci'
65# db_cl_names='latin1_swedish_ci'
66FLUSH TABLE t1;
67FLUSH TABLE t2;
68# We will get parse errors for most DDL and DML statements when the table
69# has broken triggers. The parse error refers to the first broken
70# trigger.
71CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1);
72ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a USING t1 a' at line 1'
73CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table;
74ERROR 42000: Unknown trigger has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Not allowed syntax here, and trigger name cant be extracted either.' at line 1'
75SHOW TRIGGERS;
76Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer	character_set_client	collation_connection	Database Collation
77tr11	INSERT	t1	DELETE FROM t3	BEFORE	#		root@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
78tr12	INSERT	t1	DELETE FROM t3	AFTER	#		root@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
79tr15	UPDATE	t1	CREATE DEFINER=`root`@`localhost` TRIGGER tr15 BEFORE UPDATE ON t1 FOR EACH ROW DELETE FROM non_existing_table a USING non_existing_table a	BEFORE	#			latin1	latin1_swedish_ci	latin1_swedish_ci
80tr13	DELETE	t1	CREATE DEFINER=`root`@`localhost` TRIGGER tr13 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a	BEFORE	#			latin1	latin1_swedish_ci	latin1_swedish_ci
81tr14	DELETE	t1	DELETE FROM non_existing_table	AFTER	#		root@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
82INSERT INTO t1 VALUES (1);
83ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a USING t1 a' at line 1'
84INSERT INTO t2 VALUES (1);
85ERROR 42000: Unknown trigger has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Not allowed syntax here, and trigger name cant be extracted either.' at line 1'
86DELETE FROM t1;
87ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a USING t1 a' at line 1'
88UPDATE t1 SET a = 1 WHERE a = 1;
89ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a USING t1 a' at line 1'
90SELECT * FROM t1;
91a
921
932
943
95RENAME TABLE t1 TO t1_2;
96ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a USING t1 a' at line 1'
97SHOW TRIGGERS;
98Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer	character_set_client	collation_connection	Database Collation
99tr11	INSERT	t1	DELETE FROM t3	BEFORE	#		root@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
100tr12	INSERT	t1	DELETE FROM t3	AFTER	#		root@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
101tr15	UPDATE	t1	CREATE DEFINER=`root`@`localhost` TRIGGER tr15 BEFORE UPDATE ON t1 FOR EACH ROW DELETE FROM non_existing_table a USING non_existing_table a	BEFORE	#			latin1	latin1_swedish_ci	latin1_swedish_ci
102tr13	DELETE	t1	CREATE DEFINER=`root`@`localhost` TRIGGER tr13 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a	BEFORE	#			latin1	latin1_swedish_ci	latin1_swedish_ci
103tr14	DELETE	t1	DELETE FROM non_existing_table	AFTER	#		root@localhost	latin1	latin1_swedish_ci	latin1_swedish_ci
104DROP TRIGGER tr11;
105Warnings:
106Warning	1603	Triggers for table `test`.`t1` have no creation context
107DROP TRIGGER tr12;
108DROP TRIGGER tr13;
109DROP TRIGGER tr14;
110DROP TRIGGER tr15;
111SHOW TRIGGERS;
112Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer	character_set_client	collation_connection	Database Collation
113# Make sure there is no trigger file left.
114# We write the same trigger files one more time to test DROP TABLE.
115FLUSH TABLE t1;
116FLUSH TABLE t2;
117DROP TABLE t1;
118Warnings:
119Warning	1603	Triggers for table `test`.`t1` have no creation context
120DROP TABLE t2;
121Warnings:
122Warning	1603	Triggers for table `test`.`t2` have no creation context
123DROP TABLE t3;
124# Make sure there is no trigger file left.
125CREATE TABLE t1 ( a INT );
126CREATE TABLE t2 ( a INT );
127INSERT INTO t1 VALUES (1), (2), (3);
128INSERT INTO t2 VALUES (1), (2), (3);
129# We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct
130# and last trigger is broken.
131# Next we try to execute SHOW CREATE TRIGGER command for broken trigger and then try to drop one.
132FLUSH TABLE t1;
133SHOW CREATE TRIGGER tr12;
134Trigger	sql_mode	SQL Original Statement	character_set_client	collation_connection	Database Collation	Created
135tr12		CREATE DEFINER=`root`@`localhost` TRIGGER tr12 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t2	latin1	latin1_swedish_ci	latin1_swedish_ci	NULL
136Warnings:
137Warning	1603	Triggers for table `test`.`t1` have no creation context
138SHOW CREATE TRIGGER tr11;
139Trigger	sql_mode	SQL Original Statement	character_set_client	collation_connection	Database Collation	Created
140tr11		CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a	latin1	latin1_swedish_ci	latin1_swedish_ci	NULL
141DROP TRIGGER tr12;
142DROP TRIGGER tr11;
143DROP TABLE t1;
144DROP TABLE t2;
145