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/04/22 10:02:26 UTC
svn commit: r1589036 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Author: kahatlen
Date: Tue Apr 22 08:02:26 2014
New Revision: 1589036
URL: http://svn.apache.org/r1589036
Log:
DERBY-6543: Syntax error when reference to transition variable has whitespace around it
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.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/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1589036&r1=1589035&r2=1589036&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Tue Apr 22 08:02:26 2014
@@ -4976,14 +4976,12 @@ public final class DataDictionaryImpl
}
int tokBeginOffset = tableName.getBeginOffset();
- int tokEndOffset = tableName.getEndOffset();
if (tokBeginOffset == -1)
{
continue;
}
String colName = ref.getColumnName();
- int columnLength = ref.getEndOffset() - ref.getBeginOffset() + 1;
newText.append(triggerDefinition.substring(start, tokBeginOffset-actionOffset));
int colPositionInRuntimeResultSet = -1;
@@ -5039,7 +5037,8 @@ public final class DataDictionaryImpl
tableName.getTableName(),
tableName.getTableName().equals(oldReferencingName),
colPositionInRuntimeResultSet));
- start = tokEndOffset- actionOffset + columnLength + 2;
+
+ start = ref.getEndOffset() + 1 - actionOffset;
}
//By this point, we are finished transforming the trigger action if
//it has any references to old/new transition variables.
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=1589036&r1=1589035&r2=1589036&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 Tue Apr 22 08:02:26 2014
@@ -2412,4 +2412,28 @@ public class TriggerTest extends BaseJDB
"create trigger d6540_tr2 after insert on d6540_t1 "
+ "referencing new as app.n for each row values 1");
}
+
+ /**
+ * DERBY-6543: If a reference to a transition variable had blanks around
+ * the period sign that separated the transition variable and the column
+ * name, such as {@code NEW . X} instead of {@code NEW.X}, it would fail
+ * with a syntax error.
+ */
+ public void testDerby6543() throws SQLException {
+ setAutoCommit(false);
+ Statement s = createStatement();
+ s.execute("create table d6543_1(x int)");
+ s.execute("create table d6543_2(x int)");
+
+ // Used to fail with syntax error.
+ s.execute("create trigger d6543_tr after insert on d6543_1 "
+ + "referencing new as new for each row insert into d6543_2 "
+ + "select x from d6543_1 where new . x = x");
+
+ // Verify trigger works.
+ assertUpdateCount(s, 4, "insert into d6543_1 values 1, 2, 2, 3");
+ JDBC.assertFullResultSet(
+ s.executeQuery("select * from d6543_2 order by x"),
+ new String[][] { {"1"}, {"2"}, {"2"}, {"2"}, {"2"}, {"3"} });
+ }
}