1
#################################################################
2
# This file inclde tests that address the foreign key cases of
3
# the following requirements since they are specific to innodb.
4
# Other test cases for these requirements are included in the
5
# triggers_master.test file.
6
#################################################################
8
--disable_abort_on_error
11
# Test case: Verifing that a trigger that activates a primary key results in
12
# the primary key acting correctly on the foreign key
13
let $message= Testcase x.x.x.1:;
14
--source include/show_msg.inc
18
DROP TABLE IF EXISTS t0, t1, t2;
21
eval CREATE TABLE t0 (col1 char(50)) ENGINE=$engine_type;
22
eval CREATE TABLE t1 (id INT NOT NULL, col1 char(50),
23
PRIMARY KEY (id)) ENGINE=$engine_type;
24
eval CREATE TABLE t2 (id INT PRIMARY KEY, f_id INT,
25
INDEX par_ind (f_id), col1 char(50),
26
FOREIGN KEY (f_id) REFERENCES t1(id)
27
ON DELETE SET NULL) ENGINE=$engine_type;
29
insert into t1 values (1,'Department A');
30
insert into t1 values (2,'Department B');
31
insert into t1 values (3,'Department C');
32
insert into t2 values (1,2,'Emp 1');
33
insert into t2 values (2,2,'Emp 2');
34
insert into t2 values (3,2,'Emp 3');
36
create trigger trig after insert on t0 for each row
37
delete from t1 where col1=new.col1;
40
lock tables t0 write, t1 write;
41
insert into t0 values ('Department B');
51
# Test case: Checking that triggers can be used as a way to address missing foreign
53
let $message= Testcase x.x.x.2:;
54
--source include/show_msg.inc
57
DROP TABLE IF EXISTS t1, t2;
60
eval CREATE TABLE t1 (id INT NOT NULL, col1 char(50),
61
PRIMARY KEY (id)) ENGINE=$engine_type;
62
eval CREATE TABLE t2 (id INT PRIMARY KEY, f_id INT,
63
INDEX par_ind (f_id), col1 char(50),
64
FOREIGN KEY (f_id) REFERENCES t1(id)
65
ON UPDATE CASCADE) ENGINE=$engine_type;
67
insert into t1 values (1,'Department A');
68
insert into t1 values (2,'Department B');
69
insert into t1 values (3,'Department C');
70
insert into t2 values (1,2,'Emp 1');
71
insert into t2 values (2,3,'Emp 2');
75
insert into t2 values (3,4,'Emp 3');
77
create trigger tr_t2 before insert on t2 for each row
78
insert into t1 values(new.f_id, concat('New Department ', new.f_id));
80
lock tables t1 write, t2 write;
81
insert into t2 values (3,4,'Emp 3');
89
drop table t2, t1, t0;
92
let $message= Foreign Key tests disabled (bug 11472 - stored in trig_frkey2.test);
93
--source include/show_msg.inc