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 2014/08/18 08:17:19 UTC
svn commit: r1618544 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/compile/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: kahatlen
Date: Mon Aug 18 06:17:18 2014
New Revision: 1618544
URL: http://svn.apache.org/r1618544
Log:
DERBY-6705: Triggers should not allow MERGE statements that reference temporary tables
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
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/compile/MatchingClauseNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java?rev=1618544&r1=1618543&r2=1618544&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java Mon Aug 18 06:17:18 2014
@@ -1610,5 +1610,17 @@ public class MatchingClauseNode extends
return false;
}
-
+
+ @Override
+ public boolean referencesSessionSchema() throws StandardException {
+ return referencesSessionSchema(_matchingRefinement)
+ || referencesSessionSchema(_updateColumns)
+ || referencesSessionSchema(_insertColumns)
+ || referencesSessionSchema(_insertValues);
+ }
+
+ private static boolean referencesSessionSchema(QueryTreeNode node)
+ throws StandardException {
+ return node != null && node.referencesSessionSchema();
+ }
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java?rev=1618544&r1=1618543&r2=1618544&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java Mon Aug 18 06:17:18 2014
@@ -183,7 +183,7 @@ public final class MergeNode extends DML
private FromBaseTable _targetTable;
private FromTable _sourceTable;
private ValueNode _searchCondition;
- private ArrayList<MatchingClauseNode> _matchingClauses;
+ private QueryTreeNodeVector<MatchingClauseNode> _matchingClauses;
//
// Filled in at bind() time.
@@ -214,7 +214,7 @@ public final class MergeNode extends DML
FromTable targetTable,
FromTable sourceTable,
ValueNode searchCondition,
- ArrayList<MatchingClauseNode> matchingClauses,
+ QueryTreeNodeVector<MatchingClauseNode> matchingClauses,
ContextManager cm
)
throws StandardException
@@ -424,6 +424,14 @@ public final class MergeNode extends DML
return ft.getTableName().getTableName();
}
+ @Override
+ public boolean referencesSessionSchema() throws StandardException {
+ return _sourceTable.referencesSessionSchema()
+ || _targetTable.referencesSessionSchema()
+ || _searchCondition.referencesSessionSchema()
+ || _matchingClauses.referencesSessionSchema();
+ }
+
/**
*<p>
* Because of name resolution complexities, we do not allow derived column lists
@@ -1031,7 +1039,7 @@ public final class MergeNode extends DML
ConstantAction[] clauseActions = new ConstantAction[ clauseCount ];
for ( int i = 0; i < clauseCount; i++ )
{
- MatchingClauseNode mcn = _matchingClauses.get( i );
+ MatchingClauseNode mcn = _matchingClauses.elementAt(i);
mcn.generate( acb, _selectList, generatedScan, _hojn, i );
clauseActions[ i ] = mcn.makeConstantAction( acb );
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=1618544&r1=1618543&r2=1618544&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Mon Aug 18 06:17:18 2014
@@ -3660,7 +3660,7 @@ mergeStatement() throws StandardExceptio
FromTable targetTable;
FromTable sourceTable;
ValueNode searchCondition;
- ArrayList<MatchingClauseNode> matchingClauses;
+ QueryTreeNodeVector<MatchingClauseNode> matchingClauses;
}
{
<MERGE> <INTO> targetTable = tableFactor()
@@ -3686,10 +3686,12 @@ mergeStatement() throws StandardExceptio
/*
* <A NAME="matchingClauseList">matchingClauseList</A>
*/
-ArrayList<MatchingClauseNode>
+QueryTreeNodeVector<MatchingClauseNode>
matchingClauseList() throws StandardException :
{
- ArrayList<MatchingClauseNode> matchingClauses = new ArrayList<MatchingClauseNode>();
+ QueryTreeNodeVector<MatchingClauseNode> matchingClauses =
+ new QueryTreeNodeVector<MatchingClauseNode>(
+ MatchingClauseNode.class, getContextManager());
}
{
matchingClause( matchingClauses ) ( matchingClause( matchingClauses ) ) *
@@ -3702,7 +3704,8 @@ matchingClauseList() throws StandardExce
* <A NAME="matchingClause">matchingClause</A>
*/
void
-matchingClause( ArrayList<MatchingClauseNode> matchingClauses ) throws StandardException :
+matchingClause(QueryTreeNodeVector<MatchingClauseNode> matchingClauses)
+ throws StandardException :
{
ValueNode matchingRefinement = null;
ResultColumnList updateColumns = null;
@@ -3731,7 +3734,7 @@ matchingClause( ArrayList<MatchingClause
( matchingRefinement, getContextManager() );
}
- matchingClauses.add( matchingClause );
+ matchingClauses.addElement(matchingClause);
}
|
LOOKAHEAD ( { getToken(1).kind == WHEN && getToken(2).kind == NOT } )
@@ -3743,7 +3746,7 @@ matchingClause( ArrayList<MatchingClause
matchingClause = MatchingClauseNode.makeInsertClause
( matchingRefinement, insertColumns, insertValues, getContextManager() );
- matchingClauses.add( matchingClause );
+ matchingClauses.addElement(matchingClause);
}
}
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=1618544&r1=1618543&r2=1618544&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 Mon Aug 18 06:17:18 2014
@@ -2022,6 +2022,24 @@ public class TriggerTest extends BaseJDB
+ "(select count(*) from session.temptable) = "
+ "(select count(*) from sysibm.sysdummy1)");
+ // DERBY-6705
+ assertCompileError("XCL51",
+ "create trigger tr7 after insert on t1 "
+ + "merge into t2 using session.temptable on i=x "
+ + "when matched then delete");
+
+ // DERBY-6705
+ assertCompileError("XCL51",
+ "create trigger tr8 after insert on t1 "
+ + "merge into session.temptable using t2 on i=x "
+ + "when matched then delete");
+
+ // DERBY-6705
+ assertCompileError("XCL51",
+ "create trigger tr9 after insert on t1 "
+ + "merge into t2 using t1 "
+ + "on exists(select * from session.temptable where t1.x=t2.i) "
+ + "when matched then delete");
}
/**