db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1537874 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Fri, 01 Nov 2013 09:50:15 GMT
Author: dyre
Date: Fri Nov  1 09:50:15 2013
New Revision: 1537874

URL: http://svn.apache.org/r1537874
Log:
DERBY-5806: Fix parsing of empty string in DRDAConnThread. Set ClientStatement.sqlMode_ correctly
for empty statements.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/NullSQLTextTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java?rev=1537874&r1=1537873&r2=1537874&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java Fri Nov
 1 09:50:15 2013
@@ -2259,6 +2259,7 @@ public class ClientStatement implements 
 
         clearWarningsX(); // Per jdbc spec 0.7, and getWarnings() javadoc
         sql = escape(sql);
+        sqlMode_ = executeType==executeQueryMethod__?isQuery__:isUpdate__;
         parseSqlAndSetSqlModes(sql);
         checkAutoGeneratedKeysParameters();
         if (sqlMode_ == isUpdate__) {
@@ -2629,9 +2630,8 @@ public class ClientStatement implements 
         String firstToken = getStatementToken(sql);
 
         if (firstToken == null) {
-            // entire statement was just one or more comments; pass it as a
-            // query to the server and let the server deal with it.
-            sqlMode_ = isQuery__;
+            // entire statement was just one or more comments; pass it to the 
+            // server and let it deal with it.
             return;
         }
 

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1537874&r1=1537873&r2=1537874&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Fri Nov 
1 09:50:15 2013
@@ -5920,7 +5920,9 @@ class DRDAConnThread extends Thread {
         String ccsidMBCEncoding = currentStatement.ccsidMBCEncoding;
 
         if (length == 0) {
-            return null;
+            // Can't return null here as that will indicate that the cp is 
+            // missing, when it in fact was present, but contained an empty string
+            return ""; 
         }
         byte [] byteStr = reader.readBytes(length);
         if (ccsidMBCEncoding != null)

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java?rev=1537874&r1=1537873&r2=1537874&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java Fri Nov  1
09:50:15 2013
@@ -1413,6 +1413,9 @@ class DRDAStatement
     {
         java.util.StringTokenizer tokenizer = new java.util.StringTokenizer
             (sql, "\t\n\r\f=? (");
+        if (!tokenizer.hasMoreTokens()) {
+            return false;
+        }
          String firstToken = tokenizer.nextToken();
          if (StringUtil.SQLEqualsIgnoreCase(firstToken, 
                                             "call")) // captures CALL...and ?=CALL...

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/NullSQLTextTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/NullSQLTextTest.java?rev=1537874&r1=1537873&r2=1537874&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/NullSQLTextTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/NullSQLTextTest.java
Fri Nov  1 09:50:15 2013
@@ -319,4 +319,40 @@ public class NullSQLTextTest extends Bas
      */
     public static void zeroArg () {
     }
+    
+    private static String SQLSTATE_SYNTAX_ERROR = "42X01";
+    public void testExecuteEmptyString() throws SQLException {
+        try {
+            createStatement().execute("");
+            fail("Statement expected to fail");
+        } catch (SQLException sqle) {
+            assertSQLState(SQLSTATE_SYNTAX_ERROR, sqle);
+        }
+    }
+    
+    public void testExecuteUpdateEmptyString() {
+        try {
+            createStatement().executeUpdate("");
+            fail("Statement expected to fail");
+        } catch (SQLException sqle) {
+            assertSQLState(SQLSTATE_SYNTAX_ERROR, sqle);
+        }       
+    }
+    
+    public void testExecuteQueryEmptyString() {
+        try {
+            createStatement().executeQuery("");
+            fail("Statement expected to fail");
+        } catch (SQLException sqle) {
+            assertSQLState(SQLSTATE_SYNTAX_ERROR, sqle);
+        }        
+    }
+    public void testPrepareEmptyString() {
+        try {
+            prepareStatement("");
+            fail("Statement expected to fail");
+        } catch (SQLException sqle) {
+            assertSQLState(SQLSTATE_SYNTAX_ERROR, sqle);
+        }        
+    }
 }



Mime
View raw message