mariadb/mysql-test/suite/rpl/t/rpl_create_drop_trigger.test
Alexander Barkov 87b0cc9912 MDEV-7286 TRIGGER: CREATE OR REPLACE, CREATE IF NOT EXISTS
Based on the patch by Sriram Patil, made under terms of GSoC 2014.
2015-03-04 09:52:01 +04:00

48 lines
1.7 KiB
Text

--source include/master-slave.inc
--echo # Part 1 - initial creation
connection master;
CREATE DATABASE db1;
USE db1;
CREATE TABLE t1 (val INT);
CREATE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val + 1;
SET @sum=0;
INSERT INTO t1 VALUES (10), (20), (30);
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Master FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
sync_slave_with_master;
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Slave FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
--echo # Part 2 - CREATE IF NOT EXISTS (on a existing trigger)
connection master;
CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val + 2;
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Master FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
sync_slave_with_master;
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Slave FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
--echo # Part 3 - CREATE OR REPLACE (on a existing trigger)
connection master;
CREATE OR REPLACE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val + 3;
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Master FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
sync_slave_with_master;
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Slave FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
--echo # Clearing up
connection master;
DROP TRIGGER val_sum;
DROP TABLE t1;
DROP TRIGGER IF EXISTS val_sum;
--error ER_TRG_DOES_NOT_EXIST
DROP TRIGGER random_trigger;
DROP DATABASE db1;
--error ER_NO_DB_ERROR
DROP TRIGGER IF EXISTS val_sum;
--echo # Syncing slave with master
sync_slave_with_master;
--error ER_TRG_DOES_NOT_EXIST
DROP TRIGGER val_sum;
--source include/rpl_end.inc