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 my...@apache.org on 2014/02/28 01:08:52 UTC
svn commit: r1572788 - in /db/derby/code/branches/10.10: ./
java/engine/org/apache/derby/iapi/sql/dictionary/
java/engine/org/apache/derby/impl/sql/execute/
java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: myrnavl
Date: Fri Feb 28 00:08:52 2014
New Revision: 1572788
URL: http://svn.apache.org/r1572788
Log:
DERBY-6371; DROP COLUMN looks in wrong schema when checking trigger dependencies
backport of revisions 1530517 and 1530913 from trunk
Modified:
db/derby/code/branches/10.10/ (props changed)
db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java
db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.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:r1530517,1530913
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java?rev=1572788&r1=1572787&r2=1572788&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java Fri Feb 28 00:08:52 2014
@@ -366,14 +366,13 @@ public class TriggerDescriptor extends T
isRow &&
usesReferencingClause)
{
- SchemaDescriptor compSchema;
- compSchema = getDataDictionary().getSchemaDescriptor(triggerSchemaId, null);
- CompilerContext newCC = lcc.pushCompilerContext(compSchema);
+ CompilerContext newCC = lcc.pushCompilerContext(
+ dd.getSchemaDescriptor(actionSPS.getCompSchemaId(), null));
Parser pa = newCC.getParser();
Visitable stmtnode = pa.parseStatement(triggerDefinition);
lcc.popCompilerContext(newCC);
- actionSPS.setText(getDataDictionary().getTriggerActionString(stmtnode,
+ actionSPS.setText(dd.getTriggerActionString(stmtnode,
oldReferencingName,
newReferencingName,
triggerDefinition,
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1572788&r1=1572787&r2=1572788&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Fri Feb 28 00:08:52 2014
@@ -1820,8 +1820,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());
@@ -1879,7 +1880,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/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=1572788&r1=1572787&r2=1572788&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 Fri Feb 28 00:08:52 2014
@@ -2047,4 +2047,78 @@ public class TriggerTest extends BaseJDB
// DERBY-6348.
s.execute("insert into d6348 values 1");
}
+
+ /**
+ * 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");
+ }
}