db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r980684 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/Statement.java testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
Date Fri, 30 Jul 2010 08:54:09 GMT
Author: kristwaa
Date: Fri Jul 30 08:54:09 2010
New Revision: 980684

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

Rewrote logic in isolateAnyInitialIdentifier and added test case.

Patch contributed by Knut Anders Hatlen (knut dot hatlen at oracle dot com) and
Kristian Waagan (kristwaa at apache dot org).
Patch file: derby-4748-1b-sioobe.diff


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=980684&r1=980683&r2=980684&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Fri Jul 30 08:54:09
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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java?rev=980684&r1=980683&r2=980684&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
Fri Jul 30 08:54:09 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;");
     }
 
     /**



Mime
View raw message