1
by brian
clean slate |
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 |
#################################################################
|
|
7 |
||
8 |
--disable_abort_on_error |
|
9 |
||
10 |
#Section x.x.x.1 |
|
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 |
|
15 |
||
16 |
||
17 |
--disable_warnings |
|
18 |
DROP TABLE IF EXISTS t0, t1, t2; |
|
19 |
--enable_warnings |
|
20 |
||
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; |
|
28 |
||
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'); |
|
35 |
||
36 |
create trigger trig after insert on t0 for each row |
|
37 |
delete from t1 where col1=new.col1; |
|
38 |
||
39 |
select * from t2; |
|
40 |
lock tables t0 write, t1 write; |
|
41 |
insert into t0 values ('Department B'); |
|
42 |
unlock tables; |
|
43 |
select * from t2; |
|
44 |
||
45 |
# Cleanup |
|
46 |
drop trigger trig; |
|
47 |
drop table t2, t1; |
|
48 |
||
49 |
||
50 |
#Section x.x.x.2 |
|
51 |
# Test case: Checking that triggers can be used as a way to address missing foreign |
|
52 |
# key definition |
|
53 |
let $message= Testcase x.x.x.2:; |
|
54 |
--source include/show_msg.inc |
|
55 |
||
56 |
--disable_warnings |
|
57 |
DROP TABLE IF EXISTS t1, t2; |
|
58 |
--enable_warnings |
|
59 |
||
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; |
|
66 |
||
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'); |
|
72 |
||
73 |
#FIXME: 32056 |
|
74 |
# --error 1452 |
|
75 |
insert into t2 values (3,4,'Emp 3'); |
|
76 |
||
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)); |
|
79 |
||
80 |
lock tables t1 write, t2 write; |
|
81 |
insert into t2 values (3,4,'Emp 3'); |
|
82 |
unlock tables; |
|
83 |
||
84 |
select * from t1; |
|
85 |
select * from t2; |
|
86 |
||
87 |
# Cleanup |
|
88 |
drop trigger tr_t2; |
|
89 |
drop table t2, t1, t0; |
|
90 |
||
91 |
||
92 |
let $message= Foreign Key tests disabled (bug 11472 - stored in trig_frkey2.test); |
|
93 |
--source include/show_msg.inc |
|
94 |