1
#======================================================================
4
# (test case numbering refer to requirement document TP v1.1)
5
#======================================================================
10
###############################################
12
--disable_abort_on_error
14
#####################################################
15
################# Section 3.5.1 #####################
16
# Syntax checks for CREATE TRIGGER and DROP TRIGGER #
17
#####################################################
20
# Testcase: Ensure that all clauses that should be supported are supported.
21
let $message= Testcase: 3.5.1.1:;
22
--source include/show_msg.inc
23
# OBN - This test case tests basic trigger definition and execution
24
# of INSERT/UPDATE/DELETE actions and BEFORE/AFTER timings.
25
# As such it covers the equirements in sections 3.5.6.1, 3.5.6.2,
26
# 3.5.6.4, 3.5.6.5, 3.5.7.1, 3.5.7.2, 3.5.7.3, 3.5.7.17 below.
27
# - Note currently as a result of limitations with locking tables in
28
# triggers, a specifc lockingof the tables is done.
29
# Once fixed, the locking and alias referances should be removed
33
Create trigger trg1_1 BEFORE INSERT
34
on tb3 for each row set @test_before = 2, new.f142 = @test_before;
35
Create trigger trg1_2 AFTER INSERT
36
on tb3 for each row set @test_after = 6;
37
Create trigger trg1_4 BEFORE UPDATE
38
on tb3 for each row set @test_before = 27,
39
new.f142 = @test_before,
40
new.f122 = 'Before Update Trigger';
41
Create trigger trg1_3 AFTER UPDATE
42
on tb3 for each row set @test_after = '15';
43
Create trigger trg1_5 BEFORE DELETE on tb3 for each row
44
select count(*) into @test_before from tb3 as tr_tb3
45
where f121 = 'Test 3.5.1.1';
46
Create trigger trg1_6 AFTER DELETE on tb3 for each row
47
select count(*) into @test_after from tb3 as tr_tb3
48
where f121 = 'Test 3.5.1.1';
49
# Trigger Execution Insert (before and after)
52
select @test_before, @test_after;
53
Insert into tb3 (f121, f122, f142, f144, f134)
54
values ('Test 3.5.1.1', 'First Row', @test_before, @test_after, 1);
55
select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
56
select @test_before, @test_after;
58
# Trigger Execution Update (before and after)
59
set @test_before = 18;
61
select @test_before, @test_after;
62
Update tb3 set tb3.f122 = 'Update',
63
tb3.f142 = @test_before,
64
tb3.f144 = @test_after
65
where tb3.f121 = 'Test 3.5.1.1';
66
select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
67
select @test_before, @test_after;
69
# Trigger Execution Delete (before and after)
70
Insert into tb3 (f121, f122, f142, f144, f134)
71
values ('Test 3.5.1.1', 'Second Row', 5, 6, 2);
74
select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
75
select @test_before, @test_after;
76
Delete from tb3 where f121 = 'Test 3.5.1.1' and f134 = 2;
77
select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
78
select @test_before, @test_after;
95
delete from tb3 where f121='Test 3.5.1.1';
99
# Testcase: Ensure that all clauses that should not be supported are disallowed
100
# with an appropriate error message.
101
let $message= Testcase: 3.5.1.2:;
102
--source include/show_msg.inc
105
Create trigger trg_1 after insert
106
on tb3 for each statement set @x= 1;
116
# Testcase: Ensure that all supported clauses are supported only in the correct order.
117
let $message= Testcase 3.5.1.3:;
118
--source include/show_msg.inc
120
CREATE TRIGGER trg3_1 on tb3 BEFORE INSERT for each row set new.f120 = 't';
123
CREATE trg3_2 TRIGGER AFTER INSERT on tb3 for each row set new.f120 = 's';
126
CREATE TRIGGER trg3_3 Before DELETE on tb3 set @ret1 = 'test' for each row;
129
CREATE TRIGGER trg3_4 DELETE AFTER on tb3 set @ret1 = 'test' for each row;
132
CREATE for each row TRIGGER trg3_5 AFTER UPDATE on tb3 set @ret1 = 'test';
135
# OBN - Although none of the above should have been created we should do a cleanup
136
# since if they have been created, not dropping them will affect following
153
# Testcase: Ensure that an appropriate error message is returned if a clause
154
# is out-of-order in an SQL statement.
155
# OBN - FIXME - Missing 3.5.1.4 need to add
158
# Testcase: Ensure that all clauses that are defined to be mandatory are indeed
159
# required to be mandatory by the MySQL server and tools
160
let $message= Testcase: 3.5.1.5:;
161
--source include/show_msg.inc
164
CREATE TRIGGER trg4_1 AFTER on tb3 for each row set new.f120 = 'e';
167
CREATE TRIGGER trg4_2 INSERT on tb3 for each set row new.f120 = 'f';
170
CREATE TRIGGER trg4_3 BEFORE INSERT tb3 for each row set new.f120 = 'g';
173
CREATE TRIGGER trg4_4 AFTER UPDATE on tb3 for each set new.f120 = 'g';
176
CREATE trg4_5 AFTER DELETE on tb3 for each set new.f120 = 'g';
179
CREATE TRIGGER trg4_6 BEFORE DELETE for each row set new.f120 = 'g';
182
# OBN - Although none of the above should have been created we should do a cleanup
183
# since if they have been created, not dropping them will affect following
201
# Testcase: Ensure that any clauses that are defined to be optional are indeed
202
# trated as optional by MySQL server and tools
203
let $message= Testcase 3.5.1.6: - Need to fix;
204
--source include/show_msg.inc
205
# OBN - FIXME - Missing 3.5.1.6 need to add
208
# Testcase: Ensure that all valid, fully-qualified, and non-qualified,
209
# trigger names are accepted, at creation time.
210
let $message= Testcase 3.5.1.7: - need to fix;
211
--source include/show_msg.inc
214
drop table if exists t1;
216
eval create table t1 (f1 int, f2 char(25),f3 int) engine=$engine_type;
217
CREATE TRIGGER trg5_1 BEFORE INSERT on test.t1
218
for each row set new.f3 = '14';
219
# In 5.0 names to long (more than 64 chars) were trimed without an error
220
# In 5.1 an error is returned. So adding a call with the expected error
221
# and one with a shorter name to validate proper execution
223
CREATE TRIGGER trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
224
BEFORE UPDATE on test.t1 for each row set new.f3 = '42';
225
CREATE TRIGGER trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX
226
BEFORE UPDATE on test.t1 for each row set new.f3 = '42';
228
insert into t1 (f2) values ('insert 3.5.1.7');
230
update t1 set f2='update 3.5.1.7';
232
select trigger_name from information_schema.triggers order by trigger_name;
238
# In 5.1 the long name should generate an error that is to long
240
drop trigger trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ;
241
drop trigger trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX;
245
# Testcase: Ensure that any invalid trigger name is never accepted, and that an
246
# appropriate error message is returned when the name is rejected.
247
let $message= Testcase 3.5.1.8:;
248
--source include/show_msg.inc
251
CREATE TRIGGER trg12* before insert on tb3 for each row set new.f120 = 't';
254
CREATE TRIGGER trigger before insert on tb3 for each row set new.f120 = 't';
257
CREATE TRIGGER 100 before insert on tb3 for each row set new.f120 = 't';
260
CREATE TRIGGER @@view before insert on tb3 for each row set new.f120 = 't';
263
CREATE TRIGGER @name before insert on tb3 for each row set new.f120 = 't';
266
CREATE TRIGGER tb3.trg6_1 BEFORE INSERT on test.tb3
267
for each row set new.f120 ='X';
270
drop database if exists trig_db;
272
create database trig_db;
274
eval create table t1 (f1 integer) engine = $engine_type;
276
# Can't create a trigger in a different database
279
CREATE TRIGGER trig_db.trg6_2 AFTER INSERT on tb3
280
for each row set @ret_trg6_2 = 5;
282
# Can't create a trigger refrencing a table in a different db
285
CREATE TRIGGER trg6_3 AFTER INSERT on test.tb3
286
for each row set @ret_trg6_3 = 18;
292
drop database trig_db;
293
# OBN - Although none of the above should have been created we should do a cleanup
294
# since if they have been created, not dropping them will affect following
303
#Testcase: Ensure that a reference to a non-existent trigger is rejected with
304
# an appropriate error message.
305
let $message= Testcase 3.5.1.9:(cannot be inplemented at this point);
306
--source include/show_msg.inc
310
#Testcase: Ensure that it is not possible to create two triggers with the same name on
312
let $message= Testcase 3.5.1.10:;
313
--source include/show_msg.inc
315
CREATE TRIGGER trg7_1 BEFORE UPDATE on tb3 for each row set new.f120 ='X';
318
CREATE TRIGGER trg7_1 AFTER INSERT on tb3 for each row set @x ='Y';
328
# Testcase: Ensure that it is not possible to create two or more triggers with
329
# the same name, provided each is associated with a different table.
330
let $message= Testcase 3.5.1.?:;
331
--source include/show_msg.inc
334
drop table if exists t1;
335
drop table if exists t2;
337
eval create table t1 (f1 char(50), f2 integer) engine = $engine_type;
338
eval create table t2 (f1 char(50), f2 integer) engine = $engine_type;
340
create trigger trig before insert on t1
341
for each row set new.f1 ='trig t1';
344
create trigger trig before update on t2
345
for each row set new.f1 ='trig t2';
347
insert into t1 value ('insert to t1',1);
349
update t1 set f1='update to t1';
351
insert into t2 value ('insert to t2',2);
352
update t2 set f1='update to t1';
365
# Testcase: Ensure that it is possible to create two or more triggers with
366
# the same name, provided each resides in a different database
367
let $message= Testcase 3.5.1.11:;
368
--source include/show_msg.inc
371
drop database if exists trig_db1;
372
drop database if exists trig_db2;
373
drop database if exists trig_db3;
375
create database trig_db1;
376
create database trig_db2;
377
create database trig_db3;
379
eval create table t1 (f1 char(50), f2 integer) engine = $engine_type;
380
create trigger trig before insert on t1
381
for each row set new.f1 ='trig1', @test_var1='trig1';
383
eval create table t2 (f1 char(50), f2 integer) engine = $engine_type;
384
create trigger trig before insert on t2
385
for each row set new.f1 ='trig2', @test_var2='trig2';
387
eval create table t1 (f1 char(50), f2 integer) engine = $engine_type;
388
create trigger trig before insert on t1
389
for each row set new.f1 ='trig3', @test_var3='trig3';
391
set @test_var1= '', @test_var2= '', @test_var3= '';
393
insert into t1 (f1,f2) values ('insert to db1 t1',1);
394
insert into trig_db1.t1 (f1,f2) values ('insert to db1 t1 from db1',2);
395
insert into trig_db2.t2 (f1,f2) values ('insert to db2 t2 from db1',3);
396
insert into trig_db3.t1 (f1,f2) values ('insert to db3 t1 from db1',4);
397
select @test_var1, @test_var2, @test_var3;
398
select * from t1 order by f2;
399
select * from trig_db2.t2;
400
select * from trig_db3.t1;
401
select * from t1 order by f2;
406
drop database trig_db1;
407
drop database trig_db2;
408
drop database trig_db3;
411
###########################################
412
################ Section 3.5.2 ############
413
# Check for the global nature of Triggers #
414
###########################################
417
# Test case: Ensure that if a trigger created without a qualifying database
418
# name belongs to the database in use at creation time.
420
# Test case: Ensure that if a trigger created with a qualifying database name
421
# belongs to the database specified.
423
# Test case: Ensure that if a trigger created with a qualifying database name
424
# does not belong to the database in use at creation time unless
425
# the qualifying database name identifies the database that is
426
# also in use at creation time.
427
let $message= Testcase 3.5.2.1/2/3:;
428
--source include/show_msg.inc
432
drop database if exists trig_db1;
433
drop database if exists trig_db2;
435
create database trig_db1;
436
create database trig_db2;
438
eval create table t1 (f1 char(50), f2 integer) engine = $engine_type;
439
eval create table trig_db2.t1 (f1 char(50), f2 integer) engine = $engine_type;
440
create trigger trig1_b before insert on t1
441
for each row set @test_var1='trig1_b';
442
create trigger trig_db1.trig1_a after insert on t1
443
for each row set @test_var2='trig1_a';
444
create trigger trig_db2.trig2 before insert on trig_db2.t1
445
for each row set @test_var3='trig2';
446
select trigger_schema, trigger_name, event_object_table
447
from information_schema.triggers order by trigger_name;
449
set @test_var1= '', @test_var2= '', @test_var3= '';
450
insert into t1 (f1,f2) values ('insert to db1 t1 from db1',352);
451
insert into trig_db2.t1 (f1,f2) values ('insert to db2 t1 from db1',352);
452
select @test_var1, @test_var2, @test_var3;
456
drop database trig_db1;
457
drop database trig_db2;