~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
stop slave;
2
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
3
reset master;
4
reset slave;
5
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
6
start slave;
7
DROP TRIGGER test.t1_bi;
8
DROP TRIGGER test.t2_ai;
9
DROP TRIGGER test.t1_bu;
10
DROP TRIGGER test.t2_au;
11
DROP TRIGGER test.t1_bd;
12
DROP TRIGGER test.t2_ad;
13
DROP TABLE IF EXISTS test.t1;
14
DROP TABLE IF EXISTS test.t2;
15
DROP TABLE IF EXISTS test.t3;
16
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));
17
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));
18
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));
19
CREATE TRIGGER test.t1_bi BEFORE INSERT ON test.t1 FOR EACH ROW UPDATE test.t3 SET b1=1 and y=YEAR(NOW())|
20
CREATE TRIGGER test.t2_ai AFTER INSERT ON test.t2 FOR EACH ROW BEGIN
21
INSERT INTO test.t3 VALUES(NULL,0,'MySQL Replication team rocks!', 'Dark beer in prague is #1',12345.34,12.51,0,1965,NOW());
22
UPDATE test.t3 SET f = ROUND(f);
23
END|
24
CREATE TRIGGER test.t1_bu BEFORE UPDATE on test.t1 FOR EACH ROW BEGIN
25
UPDATE test.t3 SET y = '2000';
26
INSERT INTO test.t3 VALUES(NULL,1,'Testing MySQL databases before update ', 'Insert should work',621.43, 0105.21,0,1974,NOW());
27
END|
28
CREATE TRIGGER test.t2_au AFTER UPDATE on test.t2 FOR EACH ROW BEGIN
29
DECLARE done INT DEFAULT 0;
30
DECLARE a DECIMAL(10,4);
31
DECLARE b FLOAT;
32
DECLARE num MEDIUMINT;
33
DECLARE cur1 CURSOR FOR SELECT t2.id, t2.d, t2.f FROM test.t2;
34
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
35
OPEN cur1;
36
REPEAT
37
FETCH cur1 INTO num, a, b;
38
IF NOT done THEN
39
UPDATE test.t3 SET total =(a*b) WHERE ID = num; 
40
END IF;
41
UNTIL done END REPEAT;
42
CLOSE cur1;
43
END|
44
CREATE TRIGGER test.t1_bd BEFORE DELETE on test.t1 FOR EACH ROW BEGIN
45
DECLARE done INT DEFAULT 0;
46
DECLARE a BIT(8);
47
DECLARE b VARCHAR(255);
48
DECLARE c CHAR(255);
49
DECLARE d DECIMAL(10,4);
50
DECLARE e FLOAT;
51
DECLARE f BIGINT UNSIGNED;
52
DECLARE g YEAR;
53
DECLARE h TIMESTAMP;
54
DECLARE cur1 CURSOR FOR SELECT  t1.b1, t1.vc, t1.bc, t1.d, t1.f, t1.total, t1.y, t1.t FROM test.t1;
55
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
56
OPEN cur1;
57
REPEAT
58
FETCH cur1 INTO a, b, c, d, e, f, g, h;
59
IF NOT done THEN
60
INSERT INTO test.t3 VALUES(NULL, a, b, c, d, e, f, g, h);
61
END IF;
62
UNTIL done END REPEAT;
63
CLOSE cur1;
64
END|
65
CREATE TRIGGER test.t2_ad AFTER DELETE ON test.t2 FOR EACH ROW
66
DELETE FROM test.t1|
67
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());
68
INSERT INTO test.t2 VALUES(NULL,0,'Testing MySQL databases is a cool ', 'MySQL Customers ROCK!',654321.4321,1.24521,0,YEAR(NOW()),NOW());
69
UPDATE test.t1 SET b1 = 0 WHERE b1 = 1;
70
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());
71
UPDATE test.t2 SET b1 = 0 WHERE b1 = 1;
72
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());
73
DELETE FROM test.t1 WHERE id = 1;
74
DELETE FROM test.t2 WHERE id = 1;
75
DROP TRIGGER test.t1_bi;
76
DROP TRIGGER test.t2_ai;
77
DROP TRIGGER test.t1_bu;
78
DROP TRIGGER test.t2_au;
79
DROP TRIGGER test.t1_bd;
80
DROP TRIGGER test.t2_ad;
81
DROP TABLE IF EXISTS test.t1;
82
DROP TABLE IF EXISTS test.t2;
83
DROP TABLE IF EXISTS test.t3;