db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andre...@apache.org
Subject svn commit: r419186 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 05 Jul 2006 08:07:26 GMT
Author: andreask
Date: Wed Jul  5 01:07:25 2006
New Revision: 419186

URL: http://svn.apache.org/viewvc?rev=419186&view=rev
Log:
DERBY-1064 Delete cascade causes NULL values inserted into table when after delete Trigger
fires. Contributed by Fernanda Pizzorno.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java?rev=419186&r1=419185&r2=419186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
Wed Jul  5 01:07:25 2006
@@ -475,6 +475,7 @@
 			triggerActivator.notifyEvent(TriggerEvents.BEFORE_DELETE, 
 										 rowHolder.getResultSet(), 
 										 (CursorResultSet)null);
+			triggerActivator.cleanup();
 
 		}
 
@@ -487,9 +488,11 @@
 		// fire AFTER trigger
 		if (triggerActivator != null)
 		{
+			triggerActivator.reopen();
 			triggerActivator.notifyEvent(TriggerEvents.AFTER_DELETE, 
 										 rowHolder.getResultSet(),
 										 (CursorResultSet)null);
+			triggerActivator.cleanup();
 		}
 		
 	}
@@ -608,12 +611,6 @@
 	public void	cleanUp() throws StandardException
 	{ 
 		numOpens = 0;
-
-		if (triggerActivator != null)
-		{
-			triggerActivator.cleanup();
-			// trigger activator is reused
-		}
 
 		/* Close down the source ResultSet tree */
 		if (source != null)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out?rev=419186&r1=419185&r2=419186&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
Wed Jul  5 01:07:25 2006
@@ -1074,4 +1074,63 @@
 0 rows inserted/updated/deleted
 ij> drop table tsn_t;
 0 rows inserted/updated/deleted
+ij> -- Testcase showing DERBY-1064
+CREATE TABLE T10641 ( X INT PRIMARY KEY );
+0 rows inserted/updated/deleted
+ij> CREATE TABLE T10641_DELETIONS ( X INT );
+0 rows inserted/updated/deleted
+ij> CREATE TABLE T10642 (
+    Y INT,
+    CONSTRAINT Y_AND_X FOREIGN KEY(Y) REFERENCES T10641(X) ON DELETE CASCADE);
+0 rows inserted/updated/deleted
+ij> CREATE TABLE T10642_DELETIONS ( Y INT );
+0 rows inserted/updated/deleted
+ij> CREATE TRIGGER TRIGGER_T10641
+    AFTER DELETE ON T10641
+    REFERENCING OLD AS OLD_ROW
+    FOR EACH ROW MODE DB2SQL
+    INSERT INTO T10641_DELETIONS VALUES (OLD_ROW.X);
+0 rows inserted/updated/deleted
+ij> CREATE TRIGGER TRIGGER_T10642
+    AFTER DELETE ON T10642
+    REFERENCING OLD AS OLD_ROW
+    FOR EACH ROW MODE DB2SQL
+    INSERT INTO T10642_DELETIONS VALUES (OLD_ROW.Y);
+0 rows inserted/updated/deleted
+ij> INSERT INTO T10641 VALUES (0);
+1 row inserted/updated/deleted
+ij> INSERT INTO T10642 VALUES (0);
+1 row inserted/updated/deleted
+ij> INSERT INTO T10641 VALUES (1);
+1 row inserted/updated/deleted
+ij> INSERT INTO T10642 VALUES (1);
+1 row inserted/updated/deleted
+ij> SELECT * FROM T10641;
+X          
+-----------
+0          
+1          
+ij> SELECT * FROM T10642;
+Y          
+-----------
+0          
+1          
+ij> DELETE FROM T10641;
+2 rows inserted/updated/deleted
+ij> SELECT * FROM T10641;
+X          
+-----------
+ij> SELECT * FROM T10642;
+Y          
+-----------
+ij> SELECT * FROM T10641_DELETIONS;
+X          
+-----------
+0          
+1          
+ij> SELECT * FROM T10642_DELETIONS;
+Y          
+-----------
+0          
+1          
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql?rev=419186&r1=419185&r2=419186&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
Wed Jul  5 01:07:25 2006
@@ -596,3 +596,32 @@
 select * from tsn_t;
 drop table tsn;
 drop table tsn_t;
+
+-- Testcase showing DERBY-1064
+CREATE TABLE T10641 ( X INT PRIMARY KEY );
+CREATE TABLE T10641_DELETIONS ( X INT );
+CREATE TABLE T10642 (
+    Y INT,
+    CONSTRAINT Y_AND_X FOREIGN KEY(Y) REFERENCES T10641(X) ON DELETE CASCADE);
+CREATE TABLE T10642_DELETIONS ( Y INT );
+CREATE TRIGGER TRIGGER_T10641
+    AFTER DELETE ON T10641
+    REFERENCING OLD AS OLD_ROW
+    FOR EACH ROW MODE DB2SQL
+    INSERT INTO T10641_DELETIONS VALUES (OLD_ROW.X);
+CREATE TRIGGER TRIGGER_T10642
+    AFTER DELETE ON T10642
+    REFERENCING OLD AS OLD_ROW
+    FOR EACH ROW MODE DB2SQL
+    INSERT INTO T10642_DELETIONS VALUES (OLD_ROW.Y);
+INSERT INTO T10641 VALUES (0);
+INSERT INTO T10642 VALUES (0);
+INSERT INTO T10641 VALUES (1);
+INSERT INTO T10642 VALUES (1);
+SELECT * FROM T10641;
+SELECT * FROM T10642;
+DELETE FROM T10641;
+SELECT * FROM T10641;
+SELECT * FROM T10642;
+SELECT * FROM T10641_DELETIONS;
+SELECT * FROM T10642_DELETIONS;



Mime
View raw message