1
# Test case(s) in this file contain(s) GRANT/REVOKE statements, which are not
2
# supported in embedded server. So, this test should not be run on embedded
5
-- source include/not_embedded.inc
7
###########################################################################
10
# - Check that triggers created w/o DEFINER information work well:
11
# - create the first trigger;
12
# - manually remove definer information from corresponding TRG file;
13
# - create the second trigger (the first trigger will be reloaded; check
14
# that we receive a warning);
15
# - check that the triggers loaded correctly;
17
###########################################################################
20
# Prepare environment.
23
DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
24
DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
25
DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
26
DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
30
DROP DATABASE IF EXISTS mysqltest_db1;
33
CREATE DATABASE mysqltest_db1;
35
CREATE USER mysqltest_dfn@localhost;
36
CREATE USER mysqltest_inv@localhost;
38
GRANT CREATE, TRIGGER ON mysqltest_db1.* TO mysqltest_dfn@localhost;
41
# Create a table and the first trigger.
44
--connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1)
45
--connection wl2818_definer_con
47
--echo ---> connection: wl2818_definer_con
49
CREATE TABLE t1(num_value INT);
50
CREATE TABLE t2(user_str TEXT);
52
CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES(CURRENT_USER());
55
# Remove definers from TRG file.
59
--echo ---> patching t1.TRG...
61
# Here we remove definers. This is somewhat complex than the original test
62
# Previously, the test only used grep -v 'definers=' t1.TRG, but grep is not
63
# portable and we have to load the file into a table, exclude the definers line,
64
# then load the data to an outfile to accomplish the same effect
68
CREATE TABLE patch (a blob);
69
let $MYSQLD_DATADIR = `select @@datadir`;
70
eval LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/mysqltest_db1/t1.TRG' INTO TABLE patch;
71
# remove original t1.TRG file so SELECT INTO OUTFILE won't fail
72
--remove_file $MYSQLD_DATADIR/mysqltest_db1/t1.TRG
73
eval SELECT SUBSTRING_INDEX(a,'definers=',1) INTO OUTFILE
74
'$MYSQLD_DATADIR/mysqltest_db1/t1.TRG'
77
--connection wl2818_definer_con
81
# Create a new trigger.
86
CREATE TRIGGER wl2818_trg2 AFTER INSERT ON t1
88
INSERT INTO t2 VALUES(CURRENT_USER());
92
SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
96
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
99
DROP TRIGGER wl2818_trg1;
100
DROP TRIGGER wl2818_trg2;
101
disconnect wl2818_definer_con;
106
DROP USER mysqltest_dfn@localhost;
107
DROP USER mysqltest_inv@localhost;
108
DROP DATABASE mysqltest_db1;
113
--echo # Bug#45235: 5.1 does not support 5.0-only syntax triggers in any way
115
let $MYSQLD_DATADIR=`SELECT @@datadir`;
118
DROP TABLE IF EXISTS t1, t2, t3;
121
CREATE TABLE t1 ( a INT );
122
CREATE TABLE t2 ( a INT );
123
CREATE TABLE t3 ( a INT );
124
INSERT INTO t1 VALUES (1), (2), (3);
125
INSERT INTO t2 VALUES (1), (2), (3);
126
INSERT INTO t3 VALUES (1), (2), (3);
128
--echo # We simulate importing a trigger from 5.0 by writing a .TRN file for
129
--echo # each trigger plus a .TRG file the way MySQL 5.0 would have done it,
130
--echo # with syntax allowed in 5.0 only.
132
--echo # Note that in 5.0 the following lines are missing from t1.TRG:
134
--echo # client_cs_names='latin1'
135
--echo # connection_cl_names='latin1_swedish_ci'
136
--echo # db_cl_names='latin1_swedish_ci'
138
--write_file $MYSQLD_DATADIR/test/tr11.TRN
143
--write_file $MYSQLD_DATADIR/test/tr12.TRN
148
--write_file $MYSQLD_DATADIR/test/tr13.TRN
153
--write_file $MYSQLD_DATADIR/test/tr14.TRN
158
--write_file $MYSQLD_DATADIR/test/tr15.TRN
163
--write_file $MYSQLD_DATADIR/test/t1.TRG
165
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'
167
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
170
--write_file $MYSQLD_DATADIR/test/t2.TRG
172
triggers='Not allowed syntax here, and trigger name cant be extracted either.'
174
definers='root@localhost'
180
--echo # We will get parse errors for most DDL and DML statements when the table
181
--echo # has broken triggers. The parse error refers to the first broken
183
--error ER_PARSE_ERROR
184
CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1);
185
--error ER_PARSE_ERROR
186
CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table;
188
--error ER_PARSE_ERROR
189
INSERT INTO t1 VALUES (1);
190
--error ER_PARSE_ERROR
191
INSERT INTO t2 VALUES (1);
192
--error ER_PARSE_ERROR
194
--error ER_PARSE_ERROR
195
UPDATE t1 SET a = 1 WHERE a = 1;
197
--error ER_PARSE_ERROR
198
RENAME TABLE t1 TO t1_2;
209
--echo # Make sure there is no trigger file left.
210
--list_files $MYSQLD_DATADIR/test/ tr*
212
--echo # We write the same trigger files one more time to test DROP TABLE.
213
--write_file $MYSQLD_DATADIR/test/tr11.TRN
218
--write_file $MYSQLD_DATADIR/test/tr12.TRN
223
--write_file $MYSQLD_DATADIR/test/tr13.TRN
228
--write_file $MYSQLD_DATADIR/test/tr14.TRN
233
--write_file $MYSQLD_DATADIR/test/tr15.TRN
238
--write_file $MYSQLD_DATADIR/test/t1.TRG
240
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'
242
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
252
--echo # Make sure there is no trigger file left.
254
--list_files $MYSQLD_DATADIR/test/ tr*
256
CREATE TABLE t1 ( a INT );
257
CREATE TABLE t2 ( a INT );
258
INSERT INTO t1 VALUES (1), (2), (3);
259
INSERT INTO t2 VALUES (1), (2), (3);
261
--echo # We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct
262
--echo # and last trigger is broken.
263
--echo # Next we try to execute SHOW CREATE TRGGIR command for broken trigger and then try to drop one.
264
--write_file $MYSQLD_DATADIR/test/tr11.TRN
269
--write_file $MYSQLD_DATADIR/test/tr12.TRN
274
--write_file $MYSQLD_DATADIR/test/t1.TRG
276
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'
278
definers='root@localhost' 'root@localhost' 'root@localhost'
283
SHOW CREATE TRIGGER tr12;
284
SHOW CREATE TRIGGER tr11;