Skip to content

Commit

Permalink
Fixed After and Instead of trigger issues on table
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
deepakshi-mittal committed Apr 24, 2024
1 parent 0efbb15 commit 4e04208
Show file tree
Hide file tree
Showing 21 changed files with 632 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/JDBC/expected/BABEL-4672-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE IF EXISTS tbl_emp_salary;
GO

DROP TABLE IF EXISTS emp_salary;
GO
5 changes: 5 additions & 0 deletions test/JDBC/expected/BABEL-4672-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE emp_salary(emp_id int, salary int);
GO

CREATE TABLE tbl_emp_salary(emp_id int, salary int);
GO
354 changes: 354 additions & 0 deletions test/JDBC/expected/BABEL-4672-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
----------- 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 = (SELECT emp_id from INSERTED);
GO

CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary
AFTER DELETE
AS
DELETE FROM emp_salary where emp_id = (SELECT emp_id -1 from DELETED);
GO

INSERT INTO emp_salary VALUES (3,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
~~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 = (SELECT emp_id from INSERTED)
GO

CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary
AFTER DELETE
AS
DELETE FROM emp_salary where emp_id = (SELECT emp_id +1 from DELETED)
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
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
5 changes: 5 additions & 0 deletions test/JDBC/input/triggers/BABEL-4672-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE IF EXISTS tbl_emp_salary;
GO

DROP TABLE IF EXISTS emp_salary;
GO
5 changes: 5 additions & 0 deletions test/JDBC/input/triggers/BABEL-4672-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE emp_salary(emp_id int, salary int);
GO

CREATE TABLE tbl_emp_salary(emp_id int, salary int);
GO
Loading

0 comments on commit 4e04208

Please sign in to comment.