From 59b3884f670a27d796c140cd19f35686d25cb903 Mon Sep 17 00:00:00 2001 From: Deepakshi Mittal <78574784+deepakshi-mittal@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:09:00 -0700 Subject: [PATCH] Fixed After and Instead of trigger issues on table (#2425) 1. If an After trigger exists on table, it is skipped after instead of trigger is fired on same table in Babelfish. 2. Query execution and After trigger is skipped on table in babelfish when it has a disabled Instead of Trigger Task: BABEL-4672 and BABEL-4801 Signed-off-by: Deepakshi Mittal --- test/JDBC/expected/BABEL-4672-vu-cleanup.out | 8 + test/JDBC/expected/BABEL-4672-vu-prepare.out | 8 + test/JDBC/expected/BABEL-4672-vu-verify.out | 645 ++++++++++++++++++ .../input/triggers/BABEL-4672-vu-cleanup.sql | 8 + .../input/triggers/BABEL-4672-vu-prepare.sql | 8 + .../input/triggers/BABEL-4672-vu-verify.sql | 436 ++++++++++++ test/JDBC/upgrade/13_4/schedule | 1 + test/JDBC/upgrade/13_5/schedule | 1 + test/JDBC/upgrade/13_6/schedule | 1 + test/JDBC/upgrade/13_7/schedule | 1 + test/JDBC/upgrade/13_8/schedule | 1 + test/JDBC/upgrade/13_9/schedule | 1 + test/JDBC/upgrade/14_10/schedule | 1 + test/JDBC/upgrade/14_11/schedule | 1 + test/JDBC/upgrade/14_12/schedule | 1 + test/JDBC/upgrade/14_3/schedule | 1 + test/JDBC/upgrade/14_5/schedule | 1 + test/JDBC/upgrade/14_6/schedule | 1 + test/JDBC/upgrade/14_7/schedule | 1 + test/JDBC/upgrade/14_8/schedule | 1 + test/JDBC/upgrade/14_9/schedule | 1 + test/JDBC/upgrade/15_1/schedule | 1 + test/JDBC/upgrade/15_2/schedule | 1 + test/JDBC/upgrade/15_3/schedule | 1 + test/JDBC/upgrade/15_4/schedule | 1 + test/JDBC/upgrade/15_5/schedule | 1 + test/JDBC/upgrade/15_6/schedule | 1 + test/JDBC/upgrade/latest/schedule | 1 + 28 files changed, 1135 insertions(+) create mode 100644 test/JDBC/expected/BABEL-4672-vu-cleanup.out create mode 100644 test/JDBC/expected/BABEL-4672-vu-prepare.out create mode 100644 test/JDBC/expected/BABEL-4672-vu-verify.out create mode 100644 test/JDBC/input/triggers/BABEL-4672-vu-cleanup.sql create mode 100644 test/JDBC/input/triggers/BABEL-4672-vu-prepare.sql create mode 100644 test/JDBC/input/triggers/BABEL-4672-vu-verify.sql diff --git a/test/JDBC/expected/BABEL-4672-vu-cleanup.out b/test/JDBC/expected/BABEL-4672-vu-cleanup.out new file mode 100644 index 0000000000..b839f2d9cc --- /dev/null +++ b/test/JDBC/expected/BABEL-4672-vu-cleanup.out @@ -0,0 +1,8 @@ +DROP VIEW IF EXISTS vw_emp_salary; +GO + +DROP TABLE IF EXISTS tbl_emp_salary; +GO + +DROP TABLE IF EXISTS emp_salary; +GO diff --git a/test/JDBC/expected/BABEL-4672-vu-prepare.out b/test/JDBC/expected/BABEL-4672-vu-prepare.out new file mode 100644 index 0000000000..a0cf211b39 --- /dev/null +++ b/test/JDBC/expected/BABEL-4672-vu-prepare.out @@ -0,0 +1,8 @@ +CREATE TABLE emp_salary(emp_id int, salary int); +GO + +CREATE TABLE tbl_emp_salary(emp_id int, salary int); +GO + +CREATE VIEW vw_emp_salary as SELECT * FROM tbl_emp_salary; +GO diff --git a/test/JDBC/expected/BABEL-4672-vu-verify.out b/test/JDBC/expected/BABEL-4672-vu-verify.out new file mode 100644 index 0000000000..6edfe191d9 --- /dev/null +++ b/test/JDBC/expected/BABEL-4672-vu-verify.out @@ -0,0 +1,645 @@ +----------- Section 1 IOT INSERT Triggers +-- IOT INSERT TRIGGER -> AFTER INSERT TRIGGER +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +INSERT INTO emp_salary VALUES (1,1000); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +2#!#2000 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +-- IOT INSERT TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; +GO + +INSERT INTO emp_salary VALUES (4,4000); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +2#!#12998 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +-- IOT INSERT TRIGGER -> AFTER DELETE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id-1; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id-1; +GO + +INSERT INTO emp_salary VALUES (4,1000); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: missing FROM-clause entry for table "deleted")~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +2#!#12998 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +TRUNCATE TABLE emp_salary; +GO + +----------- Section 2 IOT UPDATE Triggers +-- IOT UPDATE TRIGGER -> AFTER INSERT TRIGGER +INSERT INTO emp_salary VALUES (1, 1000); +GO +~~ROW COUNT: 1~~ + + +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +UPDATE emp_salary SET salary = salary + 5 where emp_id = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +-- IOT UPDATE TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; +GO + +UPDATE emp_salary SET salary = salary + 5 where emp_id = 2; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#12998 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +-- IOT UPDATE TRIGGER -> AFTER DELETE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id + 1; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id + 1; +GO + +UPDATE emp_salary SET salary = salary + 5 where emp_id = 1; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: missing FROM-clause entry for table "deleted")~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#12998 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +TRUNCATE TABLE emp_salary; +GO + +----------- Section 3 IOT DELETE Triggers +-- IOT DELETE TRIGGER -> AFTER INSERT TRIGGER +INSERT INTO emp_salary VALUES(1, 1000); +GO +~~ROW COUNT: 1~~ + + +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +DELETE FROM emp_salary where emp_id = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO + +-- IOT DELETE TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; +GO + +DELETE FROM emp_salary where emp_id = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#12998 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO + +-- IOT DELETE TRIGGER -> AFTER DELETE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +DELETE FROM emp_salary where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = 3; +GO + +DELETE FROM emp_salary where emp_id = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO + +TRUNCATE TABLE emp_salary; +GO + +----------- Section 4 Cases with views for INSERT and UPDATE +-- IOT INSERT/UPDATE TRIGGER VIEW-> IOT INSERT/UPDATE TRIGGER TABLE -> AFTER INSERT/UPDATE TRIGGER TABLE +INSERT INTO tbl_emp_salary VALUES (1, 1000), (2, 2000), (3, 3000); +GO +~~ROW COUNT: 3~~ + + +CREATE TRIGGER tr_vw_emp_salary_instead +ON vw_emp_salary +INSTEAD OF INSERT, UPDATE +AS +INSERT INTO tbl_emp_salary SELECT emp_id + 1, salary + 999 FROM INSERTED +GO + +CREATE TRIGGER tr_emp_salary_instead +ON tbl_emp_salary +INSTEAD OF INSERT, UPDATE +AS +INSERT INTO tbl_emp_salary SELECT emp_id + 1, salary + 999 FROM INSERTED +GO + +INSERT INTO vw_emp_salary VALUES (7,7000); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +3#!#3000 +9#!#8998 +~~END~~ + + +UPDATE vw_emp_salary SET salary = salary + 500 where emp_id = 8; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +3#!#3000 +9#!#8998 +~~END~~ + + +CREATE TRIGGER tr_emp_salary_after +ON tbl_emp_salary +AFTER INSERT, UPDATE +AS +INSERT INTO tbl_emp_salary SELECT emp_id + 1, salary + 999 FROM INSERTED +GO + +INSERT INTO vw_emp_salary VALUES (20,10000); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +UPDATE vw_emp_salary SET salary = salary + 500 where emp_id = 21; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +3#!#3000 +9#!#8998 +22#!#11998 +23#!#12997 +~~END~~ + + +DROP TRIGGER IF EXISTS tr_emp_salary_after; +GO + +DROP TRIGGER IF EXISTS tr_emp_salary_instead; +GO + +DROP TRIGGER IF EXISTS tr_vw_emp_salary_instead; +GO + +TRUNCATE TABLE tbl_emp_salary; +GO + +----------- Section 5 Cases with views for DELETE +-- IOT DELETE TRIGGER VIEW-> IOT DELETE TRIGGER TABLE -> AFTER DELETE TRIGGER TABLE +INSERT INTO tbl_emp_salary VALUES (1, 1000), (2, 2000), (3, 3000), (4, 4000); +GO +~~ROW COUNT: 4~~ + + +CREATE TRIGGER tr_vw_emp_salary_instead_delete +ON vw_emp_salary +INSTEAD OF DELETE +AS +DELETE FROM tbl_emp_salary where emp_id = (SELECT emp_id FROM DELETED) + 1; +GO + +CREATE TRIGGER tr_emp_salary_instead_delete +ON tbl_emp_salary +INSTEAD OF DELETE +AS +DELETE FROM tbl_emp_salary where emp_id = (SELECT emp_id FROM DELETED) + 1; +GO + +CREATE TRIGGER tr_emp_salary_after +ON tbl_emp_salary +AFTER DELETE +AS +DELETE FROM tbl_emp_salary where emp_id = (SELECT emp_id FROM DELETED) + 1; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +3#!#3000 +4#!#4000 +~~END~~ + + +DELETE FROM vw_emp_salary where emp_id = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO +~~START~~ +int#!#int +1#!#1000 +2#!#2000 +~~END~~ + + +DROP TRIGGER IF EXISTS tr_emp_salary_after_delete; +GO + +DROP TRIGGER IF EXISTS tr_emp_salary_instead_delete; +GO + +DROP TRIGGER IF EXISTS tr_vw_emp_salary_instead_delete; +GO + +----Section 6 AFTER Triggers with Disabled IOT Trigger BABEL-4801 +-- DISABLED IOT INSERT TRIGGER -> AFTER INSERT TRIGGER +TRUNCATE TABLE tbl_emp_salary; +GO + +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +DISABLE trigger tr_emp_salary_instead_insert ON emp_salary; +GO + +INSERT INTO emp_salary VALUES (1,1000); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#1000 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +-- DISABLED IOT UPDATE TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 1; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 1; +GO + +DISABLE trigger tr_emp_salary_instead_update ON emp_salary; +GO + +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#20998 +3#!#3000 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +-- DISABLED IOT DELETE TRIGGER -> AFTER DELETE TRIGGER +INSERT INTO emp_salary VALUES(2, 2000); +GO +~~ROW COUNT: 1~~ + + +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +DELETE FROM emp_salary where emp_id = 1; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = 2; +GO + +DISABLE trigger tr_emp_salary_instead_delete ON emp_salary; +GO + +DELETE FROM emp_salary where emp_id = 3; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO +~~START~~ +int#!#int +1#!#20998 +~~END~~ + + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO diff --git a/test/JDBC/input/triggers/BABEL-4672-vu-cleanup.sql b/test/JDBC/input/triggers/BABEL-4672-vu-cleanup.sql new file mode 100644 index 0000000000..259a866453 --- /dev/null +++ b/test/JDBC/input/triggers/BABEL-4672-vu-cleanup.sql @@ -0,0 +1,8 @@ +DROP VIEW IF EXISTS vw_emp_salary; +GO + +DROP TABLE IF EXISTS tbl_emp_salary; +GO + +DROP TABLE IF EXISTS emp_salary; +GO \ No newline at end of file diff --git a/test/JDBC/input/triggers/BABEL-4672-vu-prepare.sql b/test/JDBC/input/triggers/BABEL-4672-vu-prepare.sql new file mode 100644 index 0000000000..f68dc73f4b --- /dev/null +++ b/test/JDBC/input/triggers/BABEL-4672-vu-prepare.sql @@ -0,0 +1,8 @@ +CREATE TABLE emp_salary(emp_id int, salary int); +GO + +CREATE TABLE tbl_emp_salary(emp_id int, salary int); +GO + +CREATE VIEW vw_emp_salary as SELECT * FROM tbl_emp_salary; +GO \ No newline at end of file diff --git a/test/JDBC/input/triggers/BABEL-4672-vu-verify.sql b/test/JDBC/input/triggers/BABEL-4672-vu-verify.sql new file mode 100644 index 0000000000..0830972be9 --- /dev/null +++ b/test/JDBC/input/triggers/BABEL-4672-vu-verify.sql @@ -0,0 +1,436 @@ +----------- Section 1 IOT INSERT Triggers +-- IOT INSERT TRIGGER -> AFTER INSERT TRIGGER +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +INSERT INTO emp_salary VALUES (1,1000); +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +-- IOT INSERT TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; +GO + +INSERT INTO emp_salary VALUES (4,4000); +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +-- IOT INSERT TRIGGER -> AFTER DELETE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id-1; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id-1; +GO + +INSERT INTO emp_salary VALUES (4,1000); +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +TRUNCATE TABLE emp_salary; +GO + +----------- Section 2 IOT UPDATE Triggers +-- IOT UPDATE TRIGGER -> AFTER INSERT TRIGGER +INSERT INTO emp_salary VALUES (1, 1000); +GO + +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +UPDATE emp_salary SET salary = salary + 5 where emp_id = 1; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +-- IOT UPDATE TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; +GO + +UPDATE emp_salary SET salary = salary + 5 where emp_id = 2; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +-- IOT UPDATE TRIGGER -> AFTER DELETE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id + 1; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = DELETED.emp_id + 1; +GO + +UPDATE emp_salary SET salary = salary + 5 where emp_id = 1; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +TRUNCATE TABLE emp_salary; +GO + +----------- Section 3 IOT DELETE Triggers +-- IOT DELETE TRIGGER -> AFTER INSERT TRIGGER +INSERT INTO emp_salary VALUES(1, 1000); +GO + +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +DELETE FROM emp_salary where emp_id = 1; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO + +-- IOT DELETE TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; +GO + +DELETE FROM emp_salary where emp_id = 1; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO + +-- IOT DELETE TRIGGER -> AFTER DELETE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +DELETE FROM emp_salary where emp_id = 2; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = 3; +GO + +DELETE FROM emp_salary where emp_id = 1; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO + +TRUNCATE TABLE emp_salary; +GO + +----------- Section 4 Cases with views for INSERT and UPDATE +-- IOT INSERT/UPDATE TRIGGER VIEW-> IOT INSERT/UPDATE TRIGGER TABLE -> AFTER INSERT/UPDATE TRIGGER TABLE +INSERT INTO tbl_emp_salary VALUES (1, 1000), (2, 2000), (3, 3000); +GO + +CREATE TRIGGER tr_vw_emp_salary_instead +ON vw_emp_salary +INSTEAD OF INSERT, UPDATE +AS +INSERT INTO tbl_emp_salary SELECT emp_id + 1, salary + 999 FROM INSERTED +GO + +CREATE TRIGGER tr_emp_salary_instead +ON tbl_emp_salary +INSTEAD OF INSERT, UPDATE +AS +INSERT INTO tbl_emp_salary SELECT emp_id + 1, salary + 999 FROM INSERTED +GO + +INSERT INTO vw_emp_salary VALUES (7,7000); +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO + +UPDATE vw_emp_salary SET salary = salary + 500 where emp_id = 8; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO + +CREATE TRIGGER tr_emp_salary_after +ON tbl_emp_salary +AFTER INSERT, UPDATE +AS +INSERT INTO tbl_emp_salary SELECT emp_id + 1, salary + 999 FROM INSERTED +GO + +INSERT INTO vw_emp_salary VALUES (20,10000); +GO + +UPDATE vw_emp_salary SET salary = salary + 500 where emp_id = 21; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO + +DROP TRIGGER IF EXISTS tr_emp_salary_after; +GO + +DROP TRIGGER IF EXISTS tr_emp_salary_instead; +GO + +DROP TRIGGER IF EXISTS tr_vw_emp_salary_instead; +GO + +TRUNCATE TABLE tbl_emp_salary; +GO + +----------- Section 5 Cases with views for DELETE +-- IOT DELETE TRIGGER VIEW-> IOT DELETE TRIGGER TABLE -> AFTER DELETE TRIGGER TABLE +INSERT INTO tbl_emp_salary VALUES (1, 1000), (2, 2000), (3, 3000), (4, 4000); +GO + +CREATE TRIGGER tr_vw_emp_salary_instead_delete +ON vw_emp_salary +INSTEAD OF DELETE +AS +DELETE FROM tbl_emp_salary where emp_id = (SELECT emp_id FROM DELETED) + 1; +GO + +CREATE TRIGGER tr_emp_salary_instead_delete +ON tbl_emp_salary +INSTEAD OF DELETE +AS +DELETE FROM tbl_emp_salary where emp_id = (SELECT emp_id FROM DELETED) + 1; +GO + +CREATE TRIGGER tr_emp_salary_after +ON tbl_emp_salary +AFTER DELETE +AS +DELETE FROM tbl_emp_salary where emp_id = (SELECT emp_id FROM DELETED) + 1; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO + +DELETE FROM vw_emp_salary where emp_id = 1; +GO + +SELECT emp_id, salary FROM vw_emp_salary ORDER BY emp_id, salary; +GO + +DROP TRIGGER IF EXISTS tr_emp_salary_after_delete; +GO + +DROP TRIGGER IF EXISTS tr_emp_salary_instead_delete; +GO + +DROP TRIGGER IF EXISTS tr_vw_emp_salary_instead_delete; +GO + +----Section 6 AFTER Triggers with Disabled IOT Trigger BABEL-4801 +-- DISABLED IOT INSERT TRIGGER -> AFTER INSERT TRIGGER +TRUNCATE TABLE tbl_emp_salary; +GO + +CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary +INSTEAD OF INSERT +AS +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary +AFTER INSERT +AS +INSERT INTO emp_salary VALUES(3, 3000); +GO + +DISABLE trigger tr_emp_salary_instead_insert ON emp_salary; +GO + +INSERT INTO emp_salary VALUES (1,1000); +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_insert; +GO + +DROP TRIGGER tr_emp_salary_instead_insert; +GO + +-- DISABLED IOT UPDATE TRIGGER -> AFTER UPDATE TRIGGER +CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary +INSTEAD OF UPDATE +AS +UPDATE emp_salary SET salary = salary + 999 where emp_id = 1; +GO + +CREATE TRIGGER tr_emp_salary_after_update ON emp_salary +AFTER UPDATE +AS +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 1; +GO + +DISABLE trigger tr_emp_salary_instead_update ON emp_salary; +GO + +UPDATE emp_salary SET salary = salary + 9999 where emp_id = 1; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_update; +GO + +DROP TRIGGER tr_emp_salary_instead_update; +GO + +-- DISABLED IOT DELETE TRIGGER -> AFTER DELETE TRIGGER +INSERT INTO emp_salary VALUES(2, 2000); +GO + +CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary +INSTEAD OF DELETE +AS +DELETE FROM emp_salary where emp_id = 1; +GO + +CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary +AFTER DELETE +AS +DELETE FROM emp_salary where emp_id = 2; +GO + +DISABLE trigger tr_emp_salary_instead_delete ON emp_salary; +GO + +DELETE FROM emp_salary where emp_id = 3; +GO + +SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; +GO + +DROP TRIGGER tr_emp_salary_after_delete; +GO + +DROP TRIGGER tr_emp_salary_instead_delete; +GO \ No newline at end of file diff --git a/test/JDBC/upgrade/13_4/schedule b/test/JDBC/upgrade/13_4/schedule index 2ea6fe96b2..4aa95f21c3 100644 --- a/test/JDBC/upgrade/13_4/schedule +++ b/test/JDBC/upgrade/13_4/schedule @@ -62,6 +62,7 @@ BABEL-404 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/13_5/schedule b/test/JDBC/upgrade/13_5/schedule index edce1f9493..ae53748be4 100644 --- a/test/JDBC/upgrade/13_5/schedule +++ b/test/JDBC/upgrade/13_5/schedule @@ -68,6 +68,7 @@ BABEL-404 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index ef895d5a46..dd94c8b53a 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -88,6 +88,7 @@ BABEL-405 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/13_7/schedule b/test/JDBC/upgrade/13_7/schedule index b05e04925d..33bc484c36 100644 --- a/test/JDBC/upgrade/13_7/schedule +++ b/test/JDBC/upgrade/13_7/schedule @@ -86,6 +86,7 @@ BABEL-405 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/13_8/schedule b/test/JDBC/upgrade/13_8/schedule index b05e04925d..33bc484c36 100644 --- a/test/JDBC/upgrade/13_8/schedule +++ b/test/JDBC/upgrade/13_8/schedule @@ -86,6 +86,7 @@ BABEL-405 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index ae6ebfd931..4515a383c7 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -86,6 +86,7 @@ BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 BABEL_539 +BABEL-4672 BABEL-621 BABEL-728 BABEL-741 diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index 74f45b792f..7d8c1da7f4 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -421,6 +421,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 sys-parsename-before-15_6-or-16_1 permission_restrictions_from_pg BABEL-4529-before-15_6-or-14_11 diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 5d02a83b4d..25e0862f08 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -421,6 +421,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 sys-parsename-before-15_6-or-16_1 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 diff --git a/test/JDBC/upgrade/14_12/schedule b/test/JDBC/upgrade/14_12/schedule index 5d02a83b4d..25e0862f08 100644 --- a/test/JDBC/upgrade/14_12/schedule +++ b/test/JDBC/upgrade/14_12/schedule @@ -421,6 +421,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 sys-parsename-before-15_6-or-16_1 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index 2fba8d9593..ed88f13f87 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -90,6 +90,7 @@ BABEL-405 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index f5e6de00ef..ad057a6e71 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -88,6 +88,7 @@ BABEL-405 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 6f78b4edfe..77521739a5 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -101,6 +101,7 @@ BABEL-405 BABEL-4078-before-14_8-or-15_3 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/14_7/schedule b/test/JDBC/upgrade/14_7/schedule index 6d65edb5d4..dcac092935 100644 --- a/test/JDBC/upgrade/14_7/schedule +++ b/test/JDBC/upgrade/14_7/schedule @@ -108,6 +108,7 @@ BABEL-4078-before-14_8-or-15_3 BABEL-4098 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index 6f1edc1ad2..d6cb67e3c4 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -108,6 +108,7 @@ BABEL-4078 BABEL-4098 babel_417 BABEL-493 +BABEL-4672 BABEL_539 BABEL-621 BABEL-728 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 53f5796a5d..a7edcb06c0 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -422,6 +422,7 @@ BABEL-2999 drop_index-before-15_6-or-16_2 babel-4475 BABEL-4606 +BABEL-4672 sys-parsename-before-15_6-or-16_1 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index 9b70a84dc9..d4729c267e 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -398,6 +398,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 babel-4517 diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index 2040d4cb3d..dcaa001c1f 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -428,6 +428,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 babel-4475 diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index 91efc60f04..dc754fb1eb 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -450,6 +450,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 babel-4517 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index 1a16bdf3ad..1558113341 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -462,6 +462,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 permission_restrictions_from_pg BABEL-730-before-15_6-or-16_1 babel-4517 diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index fdcf4af795..09afad8e3b 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -489,6 +489,7 @@ operator_binary_whitespace-before-15_6-or-16_2 BABEL-2999 drop_index-before-15_6-or-16_2 BABEL-4606 +BABEL-4672 permission_restrictions_from_pg BABEL-4529-before-15_6-or-14_11 BABEL-730-before-15_6-or-16_1 diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index 7b53124372..5626e3671a 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -502,6 +502,7 @@ TestDatatypeAggSort babel_index_nulls_order BABEL-2999 BABEL-4606 +BABEL-4672 BABEL-4529 sys_availability_groups sys_availability_replicas diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 7b53124372..5626e3671a 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -502,6 +502,7 @@ TestDatatypeAggSort babel_index_nulls_order BABEL-2999 BABEL-4606 +BABEL-4672 BABEL-4529 sys_availability_groups sys_availability_replicas