~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/triggers/trig_frkey.inc

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#################################################################
2
 
# This file inclde tests that address the foreign key cases of
 
2
# This file include tests that address the foreign key cases of
3
3
# the following requirements since they are specific to innodb.
4
4
# Other test cases for these requirements are included in the
5
 
# triggers_master.test file.
 
5
# triggers_*.inc files.
6
6
#################################################################
7
7
 
8
8
--disable_abort_on_error
9
9
 
10
 
#Section x.x.x.1
 
10
# Section x.x.x.1
11
11
# Test case: Verifing that a trigger that activates a primary key results in
12
12
#            the primary key acting correctly on the foreign key
13
13
let $message= Testcase x.x.x.1:;
14
14
--source include/show_msg.inc
15
15
 
16
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;
 
17
--disable_warnings
 
18
DROP TABLE IF EXISTS t0, t1, t2;
 
19
--enable_warnings
 
20
 
 
21
--replace_result $engine_type <engine_to_be_tested>
 
22
eval
 
23
CREATE TABLE t0 (col1 CHAR(50))
 
24
ENGINE = $engine_type;
 
25
--replace_result $engine_type <engine_to_be_tested>
 
26
eval
 
27
CREATE TABLE t1 (id INT NOT NULL, col1 CHAR(50), PRIMARY KEY (id))
 
28
ENGINE = $engine_type;
 
29
--replace_result $engine_type <engine_to_be_tested>
 
30
eval
 
31
CREATE TABLE t2 (id INT PRIMARY KEY, f_id INT,
 
32
   INDEX par_ind (f_id), col1 CHAR(50),
 
33
   FOREIGN KEY (f_id) REFERENCES t1(id) ON DELETE SET NULL)
 
34
ENGINE = $engine_type;
 
35
 
 
36
INSERT INTO t1 VALUES (1,'Department A');
 
37
INSERT INTO t1 VALUES (2,'Department B');
 
38
INSERT INTO t1 VALUES (3,'Department C');
 
39
INSERT INTO t2 VALUES (1,2,'Emp 1');
 
40
INSERT INTO t2 VALUES (2,2,'Emp 2');
 
41
INSERT INTO t2 VALUES (3,2,'Emp 3');
 
42
 
 
43
CREATE TRIGGER trig AFTER INSERT ON t0 FOR EACH ROW
 
44
DELETE FROM t1 WHERE col1 = new.col1;
 
45
 
 
46
--sorted_result
 
47
SELECT * FROM t2;
 
48
LOCK TABLES t0 WRITE, t1 WRITE;
 
49
INSERT INTO t0 VALUES ('Department B');
 
50
UNLOCK TABLES;
 
51
--sorted_result
 
52
SELECT * FROM t2;
44
53
 
45
54
# Cleanup
46
 
        drop trigger trig;
47
 
        drop table t2, t1;
 
55
DROP TRIGGER trig;
 
56
DROP TABLE t2, t1;
48
57
 
49
58
 
50
59
#Section x.x.x.2
53
62
let $message= Testcase x.x.x.2:;
54
63
--source include/show_msg.inc
55
64
 
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;
 
65
--disable_warnings
 
66
DROP TABLE IF EXISTS t1, t2;
 
67
--enable_warnings
 
68
 
 
69
--replace_result $engine_type <engine_to_be_tested>
 
70
eval
 
71
CREATE TABLE t1 (id INT NOT NULL, col1 CHAR(50), PRIMARY KEY (id))
 
72
ENGINE = $engine_type;
 
73
--replace_result $engine_type <engine_to_be_tested>
 
74
eval
 
75
CREATE TABLE t2 (id INT PRIMARY KEY, f_id INT,
 
76
   INDEX par_ind (f_id), col1 CHAR(50),
 
77
   FOREIGN KEY (f_id) REFERENCES t1(id) ON UPDATE CASCADE)
 
78
ENGINE = $engine_type;
 
79
 
 
80
INSERT INTO t1 VALUES (1,'Department A');
 
81
INSERT INTO t1 VALUES (2,'Department B');
 
82
INSERT INTO t1 VALUES (3,'Department C');
 
83
INSERT INTO t2 VALUES (1,2,'Emp 1');
 
84
INSERT INTO t2 VALUES (2,3,'Emp 2');
 
85
 
 
86
--error ER_NO_REFERENCED_ROW_2
 
87
insert into t2 VALUES (3,4,'Emp 3');
 
88
 
 
89
CREATE TRIGGER tr_t2 BEFORE INSERT ON t2 FOR EACH ROW
 
90
INSERT INTO t1 VALUES(new.f_id, CONCAT('New Department ', new.f_id));
 
91
 
 
92
LOCK TABLES t1 WRITE, t2 WRITE;
 
93
INSERT INTO t2 VALUES (3,4,'Emp 3');
 
94
UNLOCK TABLES;
 
95
 
 
96
--sorted_result
 
97
SELECT * FROM t1;
 
98
--sorted_result
 
99
SELECT * FROM t2;
86
100
 
87
101
# 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
 
 
 
102
DROP TRIGGER tr_t2;
 
103
DROP TABLE t2, t1, t0;
 
104
 
 
105
 
 
106
--echo
 
107
--echo Foreign Key tests disabled (bug 11472 - stored in trig_frkey2.test)
 
108
--echo -------------------------------------------------------------------