1
#======================================================================
4
# (test case numbering refer to requirement document TP v1.1)
5
#======================================================================
7
--disable_abort_on_error
9
# General setup for Trigger tests
10
let $message= Testcase: 3.5:;
11
--source include/show_msg.inc
13
--disable_abort_on_error
15
create User test_general@localhost;
16
set password for test_general@localhost = password('PWD');
17
revoke ALL PRIVILEGES, GRANT OPTION FROM test_general@localhost;
19
create User test_super@localhost;
20
set password for test_super@localhost = password('PWD');
21
grant ALL on *.* to test_super@localhost with grant OPTION;
22
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
23
connect (con1_general,localhost,test_general,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
24
--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
25
connect (con1_super,localhost,test_super,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
28
####################################
29
############ Section 3.5.4 #########
30
# Drop Trigger Checkes: #
31
####################################
32
let $message= Testcase 3.5.4:;
33
--source include/show_msg.inc
39
# Testcase: Ensure that the DROP TRIGGER statement cleanly drops its target trigger.
40
let $message= Testcase 3.5.4.1:;
41
--source include/show_msg.inc
43
connection con1_super;
44
create database db_drop;
46
eval create table t1 (f1 char(30)) engine=$engine_type;
47
grant INSERT, SELECT on db_drop.t1 to test_general;
49
Create trigger trg1 BEFORE INSERT on t1
50
for each row set new.f1='Trigger 3.5.4.1';
51
connection con1_general;
53
Insert into t1 values ('Insert error 3.5.4.1');
54
Select * from t1 order by f1;
55
connection con1_super;
57
select trigger_schema, trigger_name, event_object_table
58
from information_schema.triggers order by trigger_name;
59
connection con1_general;
60
Insert into t1 values ('Insert no trigger 3.5.4.1');
61
Select * from t1 order by f1;
65
connection con1_super;
69
drop database if exists db_drop;
70
revoke ALL PRIVILEGES, GRANT OPTION FROM 'test_general'@'localhost';
74
# Test case: Ensure that DROP TRIGGER <trigger name> fails, with an appropriate error
75
# message, if the trigger name does not exist.
76
let $message= Testcase 3.5.4.2:;
77
--source include/show_msg.inc
79
connection con1_super;
80
create database db_drop2;
83
drop table if exists t1_432 ;
85
eval create table t1_432 (f1 char (30)) engine=$engine_type;
87
Drop trigger tr_does_not_exit;
90
drop table if exists t1_432 ;
91
drop database if exists db_drop2;
95
# Test case: Ensure that DROP TRIGGER <trigger name> fails, with an appropriate
96
# error message, if <trigger name> is not a qualified name.
97
let $message= Testcase 3.5.4.3:;
98
--source include/show_msg.inc
100
connection con1_super;
101
create database db_drop3;
104
drop table if exists t1_433 ;
105
drop table if exists t1_433a ;
107
eval create table t1_433 (f1 char (30)) engine=$engine_type;
108
eval create table t1_433a (f1a char (5)) engine=$engine_type;
110
CREATE TRIGGER trg3 BEFORE INSERT on t1_433 for each row
111
set new.f1 = 'Trigger 3.5.4.3';
115
Drop trigger t1.433.trg3;
117
# Using database.table
119
Drop trigger db_drop3.t1.433.trg3;
123
Drop trigger mysql.trg3;
125
# database does not exist
127
Drop trigger tbx.trg3;
130
Drop trigger db_drop3.trg3;
131
drop table if exists t1_433;
132
drop table if exists t1_433a;
133
drop database if exists db_drop3;
136
# Test case: Ensure that when a database is dropped, all triggers created within
137
# that database are also cleanly dropped.
138
let $message= Testcase 3.5.4.4:;
139
--source include/show_msg.inc
141
connection con1_super;
142
create database db_drop4;
144
eval create table t1 (f1 char(30)) engine=$engine_type;
145
grant INSERT, SELECT on db_drop4.t1 to test_general;
146
Create trigger trg4 BEFORE INSERT on t1
147
for each row set new.f1='Trigger 3.5.4.4';
148
connection con1_general;
150
Insert into t1 values ('Insert 3.5.4.4');
152
connection con1_super;
153
Drop database db_drop4;
155
select trigger_schema, trigger_name, event_object_table
156
from information_schema.triggers
157
where information_schema.triggers.trigger_name='trg4';
158
create database db_drop4;
160
eval create table t1 (f1 char(30)) engine=$engine_type;
161
grant INSERT, SELECT on db_drop4.t1 to test_general;
162
connection con1_general;
163
Insert into t1 values ('2nd Insert 3.5.4.4');
167
connection con1_super;
171
drop database if exists db_drop4;
173
revoke ALL PRIVILEGES, GRANT OPTION FROM 'test_general'@'localhost';
176
# Test case: Ensure that when a table is dropped, all triggers for which it is the
177
# subject table are also cleanly dropped.
178
let $message= Testcase 3.5.4.5:;
179
--source include/show_msg.inc
181
connection con1_super;
182
create database db_drop5;
184
eval create table t1 (f1 char(50)) engine=$engine_type;
185
grant INSERT, SELECT on t1 to test_general;
186
Create trigger trg5 BEFORE INSERT on t1
187
for each row set new.f1='Trigger 3.5.4.5';
188
connection con1_general;
190
Insert into t1 values ('Insert 3.5.4.5');
192
connection con1_super;
195
select trigger_schema, trigger_name, event_object_table
196
from information_schema.triggers
197
where information_schema.triggers.trigger_name='trg5';
198
eval create table t1 (f1 char(50)) engine=$engine_type;
199
grant INSERT, SELECT on t1 to test_general;
200
connection con1_general;
201
Insert into t1 values ('2nd Insert 3.5.4.5');
205
connection con1_super;
209
drop database if exists db_drop5;
211
revoke ALL PRIVILEGES, GRANT OPTION FROM 'test_general'@'localhost';
214
##################################
215
######### Section 3.5.5 ##########
216
# Checks on the Subject Table #
217
##################################
219
let $message= Testcase 3.5.5:;
220
--source include/show_msg.inc
226
# Test case: Ensure that, if CREATE TRIGGER is executed with a non-existent
227
# subject table, the statement fails with an appropriate error message.
228
let $message= Testcase 3.5.5.1:;
229
--source include/show_msg.inc
232
Create trigger trg1 before INSERT on t100 for each row set new.f2=1000;
236
# Test case: Ensure that, if CREATE TRIGGER is executed with a temporary table
237
# as the subject table, the statement fails with an appropriate error message.
238
let $message= Testcase 3.5.5.2:;
239
--source include/show_msg.inc
241
Create temporary table t1_temp (f1 bigint signed, f2 bigint unsigned);
244
Create trigger trg2 before INSERT
245
on t1_temp for each row set new.f2=9999;
254
# Test case: Ensure that, if CREATE TRIGGER is executed with a view as the subject
255
# table, the statement fails with an appropriate error message.
256
let $message= Testcase 3.5.5.3:;
257
--source include/show_msg.inc
259
Create view vw3 as select f118 from tb3;
261
# OBN Not sure why the server is returning error 1347
263
Create trigger trg3 before INSERT
264
on vw3 for each row set new.f118='s';
273
# Test case: Ensure that, if CREATE TRIGGER is executed with a table that resides
274
# in a different database than in which the trigger will reside, the
275
# statement fails with an appropriate error message; that is, ensure that
276
# the trigger and its subject table must reside in the same database.
277
let $message= Testcase 3.5.5.4:;
278
--source include/show_msg.inc
280
connection con1_super;
281
create database dbtest_one;
282
create database dbtest_two;
284
eval create table t2 (f1 char(15)) engine=$engine_type;
287
create trigger trg4 before INSERT
288
on dbtest_two.t2 for each row set new.f1='trig 3.5.5.4';
289
grant INSERT, SELECT on dbtest_two.t2 to test_general;
290
grant SELECT on dbtest_one.* to test_general;
291
connection con1_general;
293
Insert into t2 values ('1st Insert 3.5.5.4');
296
Insert into dbtest_two.t2 values ('2nd Insert 3.5.5.4');
297
Select * from dbtest_two.t2 order by f1;
300
connection con1_super;
302
revoke ALL PRIVILEGES, GRANT OPTION FROM 'test_general'@'localhost';
303
DROP DATABASE if exists dbtest_one;
304
drop database if EXISTS dbtest_two;
307
#####################################
308
########### Section 3.5.6 ###########
309
# Check on the Trigger Action Time #
310
#####################################
312
let $message= Testcase 3.5.6:;
313
--source include/show_msg.inc
319
# Test case: Ensure that a trigger definition can specify a trigger action time of BEFORE.
320
# See section 3.5.1.1
321
let $message= Testcase 3.5.6.1 (see Testcase 3.5.1.1);
322
--source include/show_msg.inc
325
# Test case: Ensure that a trigger definition can specify a trigger action time of AFTER.
326
# See section 3.5.1.1
327
let $message= Testcase 3.5.6.2 (see Testcase 3.5.1.1);
328
--source include/show_msg.inc
331
# Test case: Ensure that a trigger definition that specifies a trigger action
332
# time that is not either BEFORE or AFTER fails, with an appropriate
333
# error message, at CREATE TRIGGER time.
334
let $message= Testcase 3.5.6.3:;
335
--source include/show_msg.inc
338
Create trigger trg3_1 DURING UPDATE on tb3 for each row set new.f132=25;
340
Create trigger trg3_2 TIME INSERT on tb3 for each row set new.f132=15;
343
# OBN - Although none of the above should have been created we should do a cleanup
344
# since if they have been created, not dropping them will affect following
348
drop trigger tb3.trg3_1;
350
drop trigger tb3.trg3_2;
354
# Test case: Ensure that a trigger defined with a trigger action time of BEFORE
355
# always executes its triggered action immediately before the trigger event.
356
# See section 3.5.1.1
357
let $message= Testcase 3.5.6.4 (see Testcase 3.5.1.1);
358
--source include/show_msg.inc
361
# Test case: Ensure that a trigger defined with a trigger action time of AFTER
362
# always executes its triggered action immediately after the trigger event.
363
let $message= Testcase 3.5.6.5 (see Testcase 3.5.1.1);
364
--source include/show_msg.inc
366
#############################
367
####### Section 3.5.7 #######
368
# Check on Trigger Event #
369
#############################
372
#Test case: Ensure that a trigger definition can specify a trigger event of INSERT.
373
let $message= Testcase 3.5.7.1 (see Testcase 3.5.1.1);
374
--source include/show_msg.inc
377
# Test case: Ensure that a trigger definition can specify a trigger event of UPDATE.
378
let $message= Testcase 3.5.7.2 (see Testcase 3.5.1.1);
379
--source include/show_msg.inc
382
# Test case: Ensure that a trigger definition can specify a trigger event of DELETE.
383
let $message= Testcase 3.5.7.3 (see Testcase 3.5.1.1);
384
--source include/show_msg.inc
387
# Test case: Ensure that a trigger definition that specifies a trigger event that
388
# is not either INSERT, UPDATE or DELETE fails, with an appropriate error
389
# message, at CREATE TRIGGER time.
390
let $message= Testcase 3.5.7.4:;
391
--source include/show_msg.inc
394
Create trigger trg4_1 BEFORE SELECT on tb3 for each row set new.f132=5;
396
Create trigger trg4_2 AFTER VALUE on tb3 for each row set new.f132=1;
399
# OBN - Although none of the above should have been created we should do a cleanup
400
# since if they have been created, not dropping them will affect following
404
drop trigger tb3.trg4_1;
406
drop trigger tb3.trg4_2;
409
#Section 3.5.7.5 / 3.5.7.6
410
# Test case: Ensure that it is not possible to create multiple BEFORE INSERT triggers
411
# on the same table, even if the triggers have different names / different
413
let $message= Testcase 3.5.7.5 / 3.5.7.6:;
414
--source include/show_msg.inc
416
Create trigger trg5_1 BEFORE INSERT
417
on tb3 for each row set new.f122='Trigger1 3.5.7.5/6';
419
--error ER_NOT_SUPPORTED_YET
420
Create trigger trg5_2 BEFORE INSERT
421
on tb3 for each row set new.f122='Trigger2 3.5.7.5';
423
Insert into tb3 (f121,f122) values ('Test 3.5.7.5/6','Insert 3.5.7.5');
424
Select f121,f122 from tb3 where f121='Test 3.5.7.5/6';
425
update tb3 set f122='Update 3.5.7.6' where f121= 'Test 3.5.7.5/6';
426
Select f121,f122 from tb3 where f121='Test 3.5.7.5/6';
433
delete from tb3 where f121='Test 3.5.7.5/6';
437
#Section 3.5.7.7 / 3.5.7.8
438
# Test case: Ensure that it is not possible to create multiple AFTER INSERT triggers
439
# on the same table, even if the triggers have different names / different
441
let $message= Testcase 3.5.7.7 / 3.5.7.8:;
442
--source include/show_msg.inc
444
set @test_var='Before trig 3.5.7.7';
445
Create trigger trg6_1 AFTER INSERT
446
on tb3 for each row set @test_var='Trigger1 3.5.7.7/8';
448
--error ER_NOT_SUPPORTED_YET
449
Create trigger trg6_2 AFTER INSERT
450
on tb3 for each row set @test_var='Trigger2 3.5.7.7';
453
Insert into tb3 (f121,f122) values ('Test 3.5.7.7/8','Insert 3.5.7.7');
454
Select f121,f122 from tb3 where f121='Test 3.5.7.7/8';
456
update tb3 set f122='Update 3.5.7.8' where f121= 'Test 3.5.7.7/8';
457
Select f121,f122 from tb3 where f121='Test 3.5.7.7/8';
465
delete from tb3 where f121='Test 3.5.7.7/8';
469
#Section 3.5.7.9 / 3.5.7.10
470
# Test case: Ensure that it is not possible to create multiple BEFORE UPDATE triggers
471
# on the same table, even if the triggers have different names / different
473
let $message= Testcase 3.5.7.9/10:;
474
--source include/show_msg.inc
476
Create trigger trg7_1 BEFORE UPDATE
477
on tb3 for each row set new.f122='Trigger1 3.5.7.9/10';
479
--error ER_NOT_SUPPORTED_YET
480
Create trigger trg7_2 BEFORE UPDATE
481
on tb3 for each row set new.f122='Trigger2 3.5.7.9';
483
Insert into tb3 (f121,f122) values ('Test 3.5.7.9/10','Insert 3.5.7.9');
484
Select f121,f122 from tb3 where f121='Test 3.5.7.9/10';
485
update tb3 set f122='update 3.5.7.10' where f121='Test 3.5.7.9/10';
486
Select f121,f122 from tb3 where f121='Test 3.5.7.9/10';
493
delete from tb3 where f121='Test 3.5.7.9/10';
495
#Section 3.5.7.11 / 3.5.7.12
496
# Test case: Ensure that it is not possible to create multiple AFTER UPDATE triggers
497
# on the same table, even if the triggers have different names / different
499
let $message= Testcase 3.5.7.11/12:;
500
--source include/show_msg.inc
502
set @test_var='Before trig 3.5.7.11';
503
Create trigger trg8_1 AFTER UPDATE
504
on tb3 for each row set @test_var='Trigger 3.5.7.11/12';
506
--error ER_NOT_SUPPORTED_YET
507
Create trigger trg8_2 AFTER UPDATE
508
on tb3 for each row set @test_var='Trigger2 3.5.7.11';
512
Insert into tb3 (f121,f122) values ('Test 3.5.7.11/12','Insert 3.5.7.11/12');
514
Select f121,f122 from tb3 where f121='Test 3.5.7.11/12';
515
update tb3 set f122='update 3.5.7.12' where f121='Test 3.5.7.11/12';
516
Select f121,f122 from tb3 where f121='Test 3.5.7.11/12';
518
delete from tb3 where f121='Test 3.5.7.11/12';
525
delete from tb3 where f121='Test 3.5.7.11/12';
527
#Section 3.5.7.13 / 3.5.7.14
528
# Test case: Ensure that it is not possible to create multiple BEFORE DELETE triggers
529
# on the same table, even if the triggers have different names / different
531
let $message= Testcase 3.5.7.13/14:;
532
--source include/show_msg.inc
535
Create trigger trg9_1 BEFORE DELETE
536
on tb3 for each row set @test_var=@test_var+1;
538
--error ER_NOT_SUPPORTED_YET
539
Create trigger trg9_2 BEFORE DELETE
540
on tb3 for each row set @test_var=@test_var+10;
543
Insert into tb3 (f121,f122) values ('Test 3.5.7.13/14','Insert 3.5.7.13');
544
Select f121,f122 from tb3 where f121='Test 3.5.7.13/14';
546
delete from tb3 where f121='Test 3.5.7.13/14';
547
Select f121,f122 from tb3 where f121='Test 3.5.7.13/14';
549
delete from tb3 where f121='Test 3.5.7.13/14';
557
delete from tb3 where f121='Test 3.5.7.13/14';
559
#Section 3.5.7.15 / 3.5.7.16
560
# Test case: Ensure that it is not possible to create multiple AFTER DELETE triggers
561
# on the same table, even if the triggers have different names / different
563
let $message= Testcase 3.5.7.15/16:;
564
--source include/show_msg.inc
567
Create trigger trg_3_406010_1 AFTER DELETE
568
on tb3 for each row set @test_var=@test_var+5;
570
--error ER_NOT_SUPPORTED_YET
571
Create trigger trg_3_406010_2 AFTER DELETE
572
on tb3 for each row set @test_var=@test_var+50;
575
Create trigger trg_3_406010_1 AFTER INSERT
576
on tb3 for each row set @test_var=@test_var+1;
579
Insert into tb3 (f121,f122) values ('Test 3.5.7.15/16','Insert 3.5.7.15/16');
580
Select f121,f122 from tb3 where f121='Test 3.5.7.15/16';
582
delete from tb3 where f121='Test 3.5.7.15/16';
583
Select f121,f122 from tb3 where f121='Test 3.5.7.15/16';
585
delete from tb3 where f121='Test 3.5.7.15/16';
590
drop trigger trg_3_406010_1;
592
drop trigger trg_3_406010_2;
593
delete from tb3 where f121='Test 3.5.7.15/16';
598
# Test case: Ensure that it is possible to have a BEFORE INSERT, an AFTER INSERT,
599
# a BEFORE UPDATE, an AFTER UPDATE, a BEFORE DELETE, and an AFTER DELETE
600
# trigger on the same table; that is, ensure that every persistent base
601
# table may be the subject table for exactly six triggers
602
let $message= Testcase 3.5.7.17 (see Testcase 3.5.1.1);
603
--source include/show_msg.inc
606
# Cleanup section 3.5
608
drop user test_general@localhost;
609
drop user test_general;
610
drop user test_super@localhost;