Debian Codegraph @

mysql-test/suite/rpl/t/rpl_row_trig003.test

raw
1 #############################################################################
2 # Original Author: JBM #
3 # Original Date: Aug/16/2005 #
4 # Updated: 8/29/2005 Remove sleep calls add dump and diff #
5 #############################################################################
6 # TEST: This test includes all trigger types. BEFORE/AFTER INSERT, UPDATE & #
7 # DELETE. In addition, includes cursor, bit, varchar, flow control, #
8 # looping, ROUND(), NOW(), YEAR(), TIMESTAMP #
9 #############################################################################
10
11 # Includes
12 -- source include/have_binlog_format_row.inc
13 -- source include/set_privilege_checks_user_as_system_user.inc
14 -- source include/master-slave.inc
15
16 #-- disable_query_log
17 #-- disable_result_log
18
19 # Begin clean up test section
20 connection master;
21 --disable_warnings
22 --error 0,1360
23 DROP TRIGGER test.t1_bi;
24 --error 0,1360
25 DROP TRIGGER test.t2_ai;
26 --error 0,1360
27 DROP TRIGGER test.t1_bu;
28 --error 0,1360
29 DROP TRIGGER test.t2_au;
30 --error 0,1360
31 DROP TRIGGER test.t1_bd;
32 --error 0,1360
33 DROP TRIGGER test.t2_ad;
34 DROP TABLE IF EXISTS test.t1;
35 DROP TABLE IF EXISTS test.t2;
36 DROP TABLE IF EXISTS test.t3;
37 --enable_warnings
38
39 # test section 1
40
41 CREATE TABLE test.t1 (id MEDIUMINT NOT NULL AUTO_INCREMENT, b1 BIT(8), vc VARCHAR(255), bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, f FLOAT DEFAULT 0, total BIGINT UNSIGNED, y YEAR, t TIMESTAMP,PRIMARY KEY(id));
42 CREATE TABLE test.t2 (id MEDIUMINT NOT NULL AUTO_INCREMENT, b1 BIT(8), vc VARCHAR(255), bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, f FLOAT DEFAULT 0, total BIGINT UNSIGNED, y YEAR, t TIMESTAMP,PRIMARY KEY(id));
43 CREATE TABLE test.t3 (id MEDIUMINT NOT NULL AUTO_INCREMENT, b1 BIT(8), vc VARCHAR(255), bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, f FLOAT DEFAULT 0, total BIGINT UNSIGNED, y YEAR, t TIMESTAMP,PRIMARY KEY(id));
44
45 # Note Most of these cause the slave to core or do not produce desired results. Currently commenting out the ones not working until they are fixed.
46
47 delimiter |;
48 CREATE TRIGGER test.t1_bi BEFORE INSERT ON test.t1 FOR EACH ROW UPDATE test.t3 SET b1=1 and y=YEAR(NOW())|
49 CREATE TRIGGER test.t2_ai AFTER INSERT ON test.t2 FOR EACH ROW BEGIN
50 INSERT INTO test.t3 VALUES(NULL,0,'MySQL Replication team rocks!', 'Dark beer in prague is #1',12345.34,12.51,0,1965,NOW());
51 UPDATE test.t3 SET f = ROUND(f);
52 END|
53 CREATE TRIGGER test.t1_bu BEFORE UPDATE on test.t1 FOR EACH ROW BEGIN
54 UPDATE test.t3 SET y = '2000';
55 INSERT INTO test.t3 VALUES(NULL,1,'Testing MySQL databases before update ', 'Insert should work',621.43, 0105.21,0,1974,NOW());
56 END|
57 CREATE TRIGGER test.t2_au AFTER UPDATE on test.t2 FOR EACH ROW BEGIN
58 DECLARE done INT DEFAULT 0;
59 DECLARE a DECIMAL(10,4);
60 DECLARE b FLOAT;
61 DECLARE num MEDIUMINT;
62 DECLARE cur1 CURSOR FOR SELECT t2.id, t2.d, t2.f FROM test.t2;
63 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
64
65 OPEN cur1;
66
67 REPEAT
68 FETCH cur1 INTO num, a, b;
69 IF NOT done THEN
70 UPDATE test.t3 SET total =(a*b) WHERE ID = num;
71 END IF;
72 UNTIL done END REPEAT;
73 CLOSE cur1;
74 END|
75 CREATE TRIGGER test.t1_bd BEFORE DELETE on test.t1 FOR EACH ROW BEGIN
76 DECLARE done INT DEFAULT 0;
77 DECLARE a BIT(8);
78 DECLARE b VARCHAR(255);
79 DECLARE c CHAR(255);
80 DECLARE d DECIMAL(10,4);
81 DECLARE e FLOAT;
82 DECLARE f BIGINT UNSIGNED;
83 DECLARE g YEAR;
84 DECLARE h TIMESTAMP;
85 DECLARE cur1 CURSOR FOR SELECT t1.b1, t1.vc, t1.bc, t1.d, t1.f, t1.total, t1.y, t1.t FROM test.t1;
86 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
87
88 OPEN cur1;
89
90 REPEAT
91 FETCH cur1 INTO a, b, c, d, e, f, g, h;
92 IF NOT done THEN
93 INSERT INTO test.t3 VALUES(NULL, a, b, c, d, e, f, g, h);
94 END IF;
95 UNTIL done END REPEAT;
96 CLOSE cur1;
97 END|
98 CREATE TRIGGER test.t2_ad AFTER DELETE ON test.t2 FOR EACH ROW
99 DELETE FROM test.t1|
100 delimiter ;|
101
102 INSERT INTO test.t1 VALUES(NULL,1,'Testing MySQL databases is a cool ', 'Must make it bug free for the customer',654321.4321,15.21,0,1965,NOW());
103 INSERT INTO test.t2 VALUES(NULL,0,'Testing MySQL databases is a cool ', 'MySQL Customers ROCK!',654321.4321,1.24521,0,YEAR(NOW()),NOW());
104
105 UPDATE test.t1 SET b1 = 0 WHERE b1 = 1;
106
107 INSERT INTO test.t2 VALUES(NULL,1,'This is an after update test.', 'If this works, total will not be zero on the master or slave',1.4321,5.221,0,YEAR(NOW()),NOW());
108 UPDATE test.t2 SET b1 = 0 WHERE b1 = 1;
109
110 INSERT INTO test.t1 VALUES(NULL,1,'add some more test data test.', 'and hope for the best', 3.321,5.221,0,YEAR(NOW()),NOW());
111
112 # To make sure BUG#14698 is gone, we sleep before calling trigger
113 # (with the bug in, that caused differences in TIMESTAMP columns).
114 # We just need to let the machine's clock advance, it's not
115 # to do synchronization.
116
117 let $wait_condition= SELECT SUM(f)= ROUND(SUM(f)) FROM t3;
118 --source include/wait_condition_or_abort.inc
119
120 DELETE FROM test.t1 WHERE id = 1;
121
122 DELETE FROM test.t2 WHERE id = 1;
123
124 --source include/sync_slave_sql_with_master.inc
125 connection master;
126
127 # time to dump the databases and so we can see if they match
128
129 --exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/trg003_master.sql
130 --exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/trg003_slave.sql
131
132 # cleanup
133 --disable_warnings
134 --error 0,1360
135 DROP TRIGGER test.t1_bi;
136 --error 0,1360
137 DROP TRIGGER test.t2_ai;
138 --error 0,1360
139 DROP TRIGGER test.t1_bu;
140 --error 0,1360
141 DROP TRIGGER test.t2_au;
142 --error 0,1360
143 DROP TRIGGER test.t1_bd;
144 --error 0,1360
145 DROP TRIGGER test.t2_ad;
146 DROP TABLE IF EXISTS test.t1;
147 DROP TABLE IF EXISTS test.t2;
148 DROP TABLE IF EXISTS test.t3;
149 --enable_warnings
150
151 diff_files $MYSQLTEST_VARDIR/tmp/trg003_master.sql $MYSQLTEST_VARDIR/tmp/trg003_slave.sql;
152
153 # Cleanup
154 --remove_file $MYSQLTEST_VARDIR/tmp/trg003_master.sql
155 --remove_file $MYSQLTEST_VARDIR/tmp/trg003_slave.sql
156
157 # End of 5.0 test case
158 --source include/rpl_end.inc