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 da...@apache.org on 2010/03/03 00:03:00 UTC

svn commit: r918241 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj java/testing/org/apache/derbyTesting/functionTests/tests/lang/OffsetFetchNextTest.java

Author: dag
Date: Tue Mar  2 23:03:00 2010
New Revision: 918241

URL: http://svn.apache.org/viewvc?rev=918241&view=rev
Log:
DERBY-4562 Compilation of prepared statement results in Syntax Error

Backported from trunk with a separate patch; derby-4562c-10_5.diff


Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OffsetFetchNextTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar  2 23:03:00 2010
@@ -1 +1 @@
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,911315,915733
+/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,911315,915733,916075

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=918241&r1=918240&r2=918241&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Tue Mar  2 23:03:00 2010
@@ -1177,6 +1177,48 @@
 	}
 
 
+
+    /**
+     * Determine if we are seeing an offsetClause or the identifier OFFSET
+     * (Derby does not make it a reserved word).  "n" must be an integer
+     * literal or a dynamic parameter specification.
+     *
+     * @return true if it is an offsetClause.
+     */
+    private boolean seeingOffsetClause()
+    {
+        int nesting = 0;
+
+        // Token number, i == 1: OFFSET
+        int i = 2;
+
+        int tokKind = getToken(i).kind;
+
+        // check for integer literal or ? followed by ROW(S)
+        if (tokKind == PLUS_SIGN ||
+            tokKind == MINUS_SIGN) {
+
+            tokKind = getToken(++i).kind;
+
+            if (tokKind == EXACT_NUMERIC) {
+
+                tokKind = getToken(++i).kind;
+
+                return (tokKind == ROW ||
+                        tokKind == ROWS);
+            }
+        } else if (tokKind == EXACT_NUMERIC) {
+
+            tokKind = getToken(++i).kind;
+
+            return (tokKind == ROW ||
+                    tokKind == ROWS);
+        }
+
+        return false;
+    }
+
+
 	/**
 	 * Determine whether the next sequence of tokens can be the beginning
 	 * of a rowValueConstructorList. A rowValueConstructorList is a comma-
@@ -13892,9 +13934,7 @@
 	|	tok = <OFF>
 	|	LOOKAHEAD({
 			getToken(1).kind == OFFSET &&
-			!(getToken(2).kind == PLUS_SIGN ||
-			  getToken(2).kind == MINUS_SIGN ||
-			  getToken(2).kind == EXACT_NUMERIC)
+			!seeingOffsetClause()
 		})
 		tok = <OFFSET>
 	|	tok = <OLD>

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OffsetFetchNextTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OffsetFetchNextTest.java?rev=918241&r1=918240&r2=918241&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OffsetFetchNextTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OffsetFetchNextTest.java Tue Mar  2 23:03:00 2010
@@ -130,15 +130,33 @@
     public void testNewKeywordNonReserved()
             throws Exception
     {
-        getConnection().prepareStatement(
-            "select a,b as OFFSET from t1 OFFSET 0 rows");
+        setAutoCommit(false);
+        prepareStatement("select a,b as offset from t1 offset 0 rows");
 
         // Column and table correlation name usage
-        getConnection().prepareStatement(
-            "select a,b from t1 AS OFFSET");
+        prepareStatement("select a,b from t1 as offset");
 
-        getConnection().prepareStatement(
-            "select a,b OFFSET from t1 OFFSET");
+        prepareStatement("select a,b offset from t1 offset");
+        prepareStatement("select a,b offset from t1 offset +2 rows");
+
+        // DERBY-4562
+        Statement s = createStatement();
+        s.executeUpdate("create table t4562(i int, offset int)");
+        ResultSet rs = s.executeQuery(
+            "select * from t4562 where i > 0 and offset + i < 0 offset 2 rows");
+        rs.next();
+
+        rs = s.executeQuery(
+            "select * from t4562 where i > 0 and offset - i < 0 offset 2 rows");
+        rs.next();
+
+        rs = s.executeQuery(
+            "select * from t4562 where i > 0 and offset * i < 0 offset 2 rows");
+        rs.next();
+
+        rs.close();
+
+        rollback();
     }