1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
# Test case(s) in this file contain(s) GRANT/REVOKE statements, which are not
# supported in embedded server. So, this test should not be run on embedded
# server.
--source include/not_embedded.inc
--source include/default_charset.inc
###########################################################################
#
# Tests for WL#2818:
# - Check that triggers created w/o DEFINER information work well:
# - create the first trigger;
# - manually remove definer information from corresponding TRG file;
# - create the second trigger (the first trigger will be reloaded; check
# that we receive a warning);
# - check that the triggers loaded correctly;
#
###########################################################################
#
# Prepare environment.
#
DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
FLUSH PRIVILEGES;
--disable_warnings
DROP DATABASE IF EXISTS mysqltest_db1;
--enable_warnings
CREATE DATABASE mysqltest_db1;
CREATE USER mysqltest_dfn@localhost;
CREATE USER mysqltest_inv@localhost;
GRANT CREATE, TRIGGER ON mysqltest_db1.* TO mysqltest_dfn@localhost;
#
# Create a table and the first trigger.
#
--connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1)
--connection wl2818_definer_con
CREATE TABLE t1(num_value INT);
CREATE TABLE t2(user_str TEXT);
CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES(CURRENT_USER());
#
# Remove definers from TRG file.
#
--echo
--echo ---> patching t1.TRG...
# Here we remove definers. This is somewhat complex than the original test
# Previously, the test only used grep -v 'definers=' t1.TRG, but grep is not
# portable and we have to load the file into a table, exclude the definers line,
# then load the data to an outfile to accomplish the same effect
--disable_query_log
--connection default
CREATE TABLE patch (a blob);
let $MYSQLD_DATADIR = `select @@datadir`;
eval LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/mysqltest_db1/t1.TRG' INTO TABLE patch;
# remove original t1.TRG file so SELECT INTO OUTFILE won't fail
--remove_file $MYSQLD_DATADIR/mysqltest_db1/t1.TRG
--disable_ps2_protocol
eval SELECT SUBSTRING_INDEX(a,'definers=',1) INTO OUTFILE
'$MYSQLD_DATADIR/mysqltest_db1/t1.TRG'
FROM patch;
--enable_ps2_protocol
DROP TABLE patch;
--connection wl2818_definer_con
--enable_query_log
#
# Create a new trigger.
#
--echo
CREATE TRIGGER wl2818_trg2 AFTER INSERT ON t1
FOR EACH ROW
INSERT INTO t2 VALUES(CURRENT_USER());
--echo
SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
--echo
--replace_column 17 #
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
# Clean up
DROP TRIGGER wl2818_trg1;
DROP TRIGGER wl2818_trg2;
disconnect wl2818_definer_con;
connection default;
use mysqltest_db1;
DROP TABLE t1;
DROP TABLE t2;
DROP USER mysqltest_dfn@localhost;
DROP USER mysqltest_inv@localhost;
DROP DATABASE mysqltest_db1;
USE test;
--echo #
--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'
sql_modes=0 0 0 0 0
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
EOF
--write_file $MYSQLD_DATADIR/test/t2.TRG
TYPE=TRIGGERS
triggers='Not allowed syntax here, and trigger name cant be extracted either.'
sql_modes=0
definers='root@localhost'
EOF
FLUSH TABLE t1;
FLUSH TABLE t2;
--echo # We will get parse errors for most DDL and DML statements when the table
--echo # has broken triggers. The parse error refers to the first broken
--echo # trigger.
--error ER_PARSE_ERROR
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);
--error ER_PARSE_ERROR
INSERT INTO t2 VALUES (1);
--error ER_PARSE_ERROR
DELETE FROM t1;
--error ER_PARSE_ERROR
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;
DROP TRIGGER tr12;
DROP TRIGGER tr13;
DROP TRIGGER tr14;
DROP TRIGGER tr15;
--replace_column 6 #
SHOW TRIGGERS;
--echo # Make sure there is no trigger file left.
--list_files $MYSQLD_DATADIR/test/ tr*
--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'
sql_modes=0 0 0 0 0
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
EOF
FLUSH TABLE t1;
FLUSH TABLE t2;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
--echo # Make sure there is no trigger file left.
--list_files $MYSQLD_DATADIR/test/ tr*
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
INSERT INTO t1 VALUES (1), (2), (3);
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 TRIGGER command for broken trigger and then try to drop one.
--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/t1.TRG
TYPE=TRIGGERS
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'
sql_modes=0 0 0
definers='root@localhost' 'root@localhost' 'root@localhost'
EOF
FLUSH TABLE t1;
SHOW CREATE TRIGGER tr12;
SHOW CREATE TRIGGER tr11;
DROP TRIGGER tr12;
DROP TRIGGER tr11;
DROP TABLE t1;
DROP TABLE t2;
--echo #
--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'
sql_modes=1411383296 1411383296
definers='root@localhost' 'root@localhost'
client_cs_names='utf8' 'utf8'
connection_cl_names='utf8_general_ci' 'utf8_general_ci'
db_cl_names='latin1_swedish_ci' 'latin1_swedish_ci'
created=164206810874 164206810873
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 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'
sql_modes=1411383296 1411383296
definers='root@localhost' 'root@localhost'
client_cs_names='utf8' 'utf8'
connection_cl_names='utf8_general_ci' 'utf8_general_ci'
db_cl_names='latin1_swedish_ci' 'latin1_swedish_ci'
created=164206810874 164206810873
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
# Now we dropped the broken trigger. Make sure the good one is fired.
# If everything goes as expected, it will try to insert into t2,
# which does not exists, hence the (expected) error.
--error ER_NO_SUCH_TABLE
INSERT INTO t1 VALUES (100);
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 TRIGGER
|