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 kr...@apache.org on 2010/08/10 17:13:04 UTC

svn commit: r984074 - in /db/derby/code/branches/10.6: ./ java/client/org/apache/derby/client/am/Statement.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java

Author: kristwaa
Date: Tue Aug 10 15:13:04 2010
New Revision: 984074

URL: http://svn.apache.org/viewvc?rev=984074&view=rev
Log:
DERBY-4748: StringIndexOutOfBoundsException on syntax error (invalid COMMIT)

Merged fix cleanly from trunk (revision 980684).

Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 10 15:13:04 2010
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,958163,958522,958555,958618,958939,959550,962716,963206,963705,964115,965647,967304
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,958163,958522,958555,958618,958939,959550,962716,963206,963705,964115,965647,967304,980684
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/Statement.java?rev=984074&r1=984073&r2=984074&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/Statement.java Tue Aug 10 15:13:04 2010
@@ -2357,27 +2357,16 @@ public class Statement implements java.s
      * @return identifier or unmodified string
      */
     private String isolateAnyInitialIdentifier (String sql) {
-        int idx = 0;
-        int length = sql.length();
-
-        if (length == 0) {
-            return sql;
-        }
-
-        char next = sql.charAt(idx);
-
-        if (!Character.isLetter(next)) {
-            return sql;
-        }
-
-        while (idx < length) {
-            if (!Character.isLetter(next)) {
+        int idx;
+        for (idx = 0; idx < sql.length(); idx++) {
+            char ch = sql.charAt(idx);
+            if (!Character.isLetter(ch)) {
+                // first non-token char found
                 break;
             }
-            next = sql.charAt(++idx);
         }
-
-        return sql.substring(0, idx);
+        // return initial token if one is found, or the entire string otherwise
+        return (idx > 0) ? sql.substring(0, idx) : sql;
     }
 
     /**

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java?rev=984074&r1=984073&r2=984074&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java (original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java Tue Aug 10 15:13:04 2010
@@ -22,8 +22,6 @@
 package org.apache.derbyTesting.functionTests.tests.lang;
 
 import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
@@ -31,15 +29,13 @@ import java.sql.Types;
 
 import junit.framework.Assert;
 import junit.framework.Test;
-import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
- * Test for comments.
+ * Test for comments, and a few tests related to parsing non-comment SQL.
  */
 public final class CommentTest extends BaseJDBCTestCase {
 
@@ -216,6 +212,10 @@ public final class CommentTest extends B
             s.executeQuery("select'a' from sys.systables"));
         JDBC.assertDrainResults(
             s.executeQuery("select\"TABLEID\" from sys.systables"));
+
+        // Added for DERBY-4748.
+        assertCompileError("42X01", "commit");
+        assertCompileError("42X01", "commit;");
     }
 
     /**