db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1526429 - in /db/derby/code/branches/10.10: ./ java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Date Thu, 26 Sep 2013 09:31:44 GMT
Author: kahatlen
Date: Thu Sep 26 09:31:44 2013
New Revision: 1526429

URL: http://svn.apache.org/r1526429
Log:
DERBY-6351: Syntax error on equal transition table name and correlation name in statement
trigger

Merged revision 1526406 from trunk.

Modified:
    db/derby/code/branches/10.10/   (props changed)
    db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1526406

Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java?rev=1526429&r1=1526428&r2=1526429&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
(original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
Thu Sep 26 09:31:44 2013
@@ -606,7 +606,6 @@ public class CreateTriggerNode extends D
 			for (int i = 0; i < tabs.size(); i++)
 			{
 				FromBaseTable fromTable = (FromBaseTable) tabs.get(i);
-				String refTableName = fromTable.getTableName().getTableName();
 				String baseTableName = fromTable.getBaseTableName();
 				if ((baseTableName == null) ||
 					((oldTableName == null || !oldTableName.equals(baseTableName)) &&
@@ -632,7 +631,7 @@ public class CreateTriggerNode extends D
 				** pick it up automatically; otherwise, supply
 				** the default.
 				*/
-				if (refTableName.equals(baseTableName))
+                if (fromTable.getCorrelationName() == null)
 				{
 					newText.append(baseTableName).append(" ");
 				}

Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java?rev=1526429&r1=1526428&r2=1526429&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
(original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Thu Sep 26 09:31:44 2013
@@ -1737,4 +1737,64 @@ public class TriggerTest extends BaseJDB
     public static void derby4610proc(String str) {
         // do nothing
     }
+
+    /**
+     * Regression test case for DERBY-6351, where CREATE TRIGGER would fail
+     * with a syntax error if the triggered SQL statement referenced a
+     * transition table using a correlation name, and that correlation name
+     * was equal to the transition table name.
+     */
+    public void testDerby6351TransitionTableCorrelation() throws SQLException {
+        Statement s = createStatement();
+        s.execute("create table t1(x int)");
+        s.execute("create table t2(x varchar(10), y int)");
+
+        // The correlation name is equal to the name of the transition table.
+        // This used to fail with a syntax error.
+        s.execute("create trigger tr1 after insert on t1 "
+                + "referencing new table as n "
+                + "insert into t2 select 'tr1', x from n n");
+        s.execute("create trigger tr2 after update on t1 "
+                + "referencing old table as o "
+                + "insert into t2 select 'tr2', x from o o");
+
+        // For completeness, also verify that no correlation name and a
+        // distinct correlation name work as expected.
+        s.execute("create trigger tr3 after insert on t1 "
+                + "referencing new table as n "
+                + "insert into t2 select 'tr3', x from n");
+        s.execute("create trigger tr4 after update on t1 "
+                + "referencing old table as o "
+                + "insert into t2 select 'tr4', x from o");
+        s.execute("create trigger tr5 after insert on t1 "
+                + "referencing new table as n "
+                + "insert into t2 select 'tr5', n1.x from n n1");
+        s.execute("create trigger tr6 after update on t1 "
+                + "referencing old table as o "
+                + "insert into t2 select 'tr6', o1.x from o o1");
+
+        // Fire the insert triggers and verify that they worked.
+        s.execute("insert into t1 values 1,2");
+        JDBC.assertFullResultSet(
+                s.executeQuery("select * from t2 order by x, y"),
+                new String[][] {
+                    { "tr1", "1" },
+                    { "tr1", "2" },
+                    { "tr3", "1" },
+                    { "tr3", "2" },
+                    { "tr5", "1" },
+                    { "tr5", "2" },
+                });
+
+        // Fire the update triggers and verify that they worked.
+        s.execute("delete from t2"); // clean up first
+        s.execute("update t1 set x = x + 1 where x = 1");
+        JDBC.assertFullResultSet(
+                s.executeQuery("select * from t2 order by x, y"),
+                new String[][] {
+                    { "tr2", "1" },
+                    { "tr4", "1" },
+                    { "tr6", "1" },
+                });
+    }
 }



Mime
View raw message