You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2013/10/09 09:55:48 UTC
svn commit: r1530517 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Author: kahatlen
Date: Wed Oct 9 07:55:48 2013
New Revision: 1530517
URL: http://svn.apache.org/r1530517
Log:
DERBY-6371: DROP COLUMN looks in wrong schema when checking trigger dependencies
Use the same schema during dependency checking as during compilation
of the trigger action.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1530517&r1=1530516&r2=1530517&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Wed Oct 9 07:55:48 2013
@@ -22,7 +22,6 @@
package org.apache.derby.impl.sql.execute;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -1800,8 +1799,9 @@ class AlterTableConstantAction extends D
// Here we get the trigger action sql and use the parser to build
// the parse tree for it.
- SchemaDescriptor compSchema;
- compSchema = dd.getSchemaDescriptor(trd.getSchemaDescriptor().getUUID(), null);
+ SchemaDescriptor compSchema = dd.getSchemaDescriptor(
+ dd.getSPSDescriptor(trd.getActionId()).getCompSchemaId(),
+ null);
CompilerContext newCC = lcc.pushCompilerContext(compSchema);
Parser pa = newCC.getParser();
StatementNode stmtnode = (StatementNode)pa.parseStatement(trd.getTriggerDefinition());
@@ -1859,7 +1859,6 @@ class AlterTableConstantAction extends D
// alter table atdc_12 drop column b
// Following rebinding of the trigger action sql will catch the use
// of column b in trigger atdc_12_trigger_1
- compSchema = dd.getSchemaDescriptor(trd.getSchemaDescriptor().getUUID(), null);
newCC = lcc.pushCompilerContext(compSchema);
newCC.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);
pa = newCC.getParser();
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java?rev=1530517&r1=1530516&r2=1530517&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java Wed Oct 9 07:55:48 2013
@@ -1842,4 +1842,78 @@ public class TriggerTest extends BaseJDB
+ "(select count(*) from sysibm.sysdummy1)");
}
+
+ /**
+ * Verify the fix for DERBY-6371. The dependency checking done when
+ * dropping a column used the wrong compilation schema and sometimes
+ * incorrectly reported that a trigger depended on the column.
+ */
+ public void testDerby6371DropColumn() throws SQLException {
+ Statement s = createStatement();
+ s.execute("create schema d6371_s1");
+ s.execute("create schema d6371_s2");
+ s.execute("create table d6371_s1.t1(x int, y int)");
+ s.execute("create table d6371_s1.t2(x int, y int)");
+ s.execute("set schema 'D6371_S1'");
+
+ commit();
+
+ s.execute("create trigger d6371_s2.tr1 after update of x on t1 "
+ + "for each row insert into t2(x) select x from t1");
+
+ // Should not be allowed to drop column X, which is referenced by
+ // the trigger.
+ assertStatementError("X0Y25", s,
+ "alter table t1 drop column x restrict");
+ assertStatementError("X0Y25", s,
+ "alter table t2 drop column x restrict");
+
+ // Now drop a column that is not referenced from the trigger. Used
+ // to fail with a message saying the trigger TR1 depended on it.
+ s.execute("alter table t1 drop column y restrict");
+ s.execute("alter table t2 drop column y restrict");
+
+ // Verify that the trigger still works.
+ s.execute("insert into t1 values 1");
+ s.execute("update t1 set x = x + 1");
+ JDBC.assertSingleValueResultSet(
+ s.executeQuery("select * from t2"), "2");
+
+ // Go back to a clean set of tables.
+ rollback();
+
+ /* ---- End of the regression test case for the actual bug. ---- */
+
+ // Extra check for a new code path that could be taken after the
+ // fix. If the trigger is created by a user that has no schema, and
+ // no explicit schema has been set in the connection, the trigger's
+ // compilation schema will be NULL. Make sure that such a trigger
+ // doesn't get into trouble during dependency validation. In
+ // particular, we would like to avoid problems such as those in
+ // DERBY-6361.
+ Connection c2 =
+ openDefaultConnection("D6371_USER_WITHOUT_SCHEMA", "secret");
+ Statement s2 = c2.createStatement();
+ s2.execute("create trigger d6371_s1.tr2 "
+ + "after update of x on d6371_s1.t1 for each row "
+ + "insert into d6371_s1.t2(x) select x from d6371_s1.t1");
+ s2.close();
+ c2.commit();
+ c2.close();
+
+ // Now exercise the dependency checking, both with columns that are
+ // referenced by the trigger and columns that are not referenced.
+ assertStatementError("X0Y25", s,
+ "alter table t1 drop column x restrict");
+ assertStatementError("X0Y25", s,
+ "alter table t2 drop column x restrict");
+ s.execute("alter table t1 drop column y restrict");
+ s.execute("alter table t2 drop column y restrict");
+
+ // And verify that the trigger works.
+ s.execute("insert into t1 values 1");
+ s.execute("update t1 set x = x + 1");
+ JDBC.assertSingleValueResultSet(
+ s.executeQuery("select * from t2"), "2");
+ }
}