db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1527993 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerWhenClauseTest.java
Date Tue, 01 Oct 2013 09:31:26 GMT
Author: kahatlen
Date: Tue Oct  1 09:31:26 2013
New Revision: 1527993

URL: http://svn.apache.org/r1527993
Log:
DERBY-534: Support use of the WHEN clause in CREATE TRIGGER statements

Disallow references to tables in the SESSION schema in the WHEN clause.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerWhenClauseTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java?rev=1527993&r1=1527992&r2=1527993&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
Tue Oct  1 09:31:26 2013
@@ -437,10 +437,11 @@ class CreateTriggerNode extends DDLState
 			}
 		}
 
-		//If attempting to reference a SESSION schema table (temporary or permanent) in the trigger
action, throw an exception
-		if (actionNode.referencesSessionSchema())
+        // Throw an exception if the WHEN clause or the triggered SQL
+        // statement references a table in the SESSION schema.
+        if (referencesSessionSchema()) {
 			throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
-
+        }
 	}
 
 	/**
@@ -456,7 +457,9 @@ class CreateTriggerNode extends DDLState
 	{
 		//If create trigger is part of create statement and the trigger is defined on or it references
SESSION schema tables,
 		//it will get caught in the bind phase of trigger and exception will be thrown by the trigger
bind. 
-		return (isSessionSchema(triggerTableDescriptor.getSchemaName()) || actionNode.referencesSessionSchema());
+        return isSessionSchema(triggerTableDescriptor.getSchemaName())
+                || actionNode.referencesSessionSchema()
+                || (whenClause != null && whenClause.referencesSessionSchema());
 	}
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerWhenClauseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerWhenClauseTest.java?rev=1527993&r1=1527992&r2=1527993&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerWhenClauseTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerWhenClauseTest.java
Tue Oct  1 09:31:26 2013
@@ -44,6 +44,8 @@ public class TriggerWhenClauseTest exten
      */
     private static List<Integer> procedureCalls;
 
+    private static final String REFERENCES_SESSION_SCHEMA = "XCL51";
+
     public TriggerWhenClauseTest(String name) {
         super(name);
     }
@@ -257,4 +259,21 @@ public class TriggerWhenClauseTest exten
                 s.executeQuery("select * from t2 order by x"),
                 new String[][]{{"1"}, {"1"}, {"2"}, {"3"}, {"3"}});
     }
+
+    /**
+     * Test that CREATE TRIGGER fails if the WHEN clause references a table
+     * in the SESSION schema.
+     */
+    public void testSessionSchema() throws SQLException {
+        Statement s = createStatement();
+        s.execute("declare global temporary table temptable (x int) "
+                + "not logged");
+        s.execute("create table t1(x int)");
+        s.execute("create table t2(x int)");
+
+        assertCompileError(REFERENCES_SESSION_SCHEMA,
+                "create trigger tr1 after insert on t1 "
+                + "when (exists (select * from session.temptable)) "
+                + "insert into t2 values 1");
+    }
 }



Mime
View raw message