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 2013/10/24 12:39:44 UTC

svn commit: r1535335 - in /db/derby/code/branches/10.10: ./ java/client/org/apache/derby/client/am/SqlWarning.java java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java

Author: kahatlen
Date: Thu Oct 24 10:39:44 2013
New Revision: 1535335

URL: http://svn.apache.org/r1535335
Log:
DERBY-6373: NPE in Statement.getWarnings()

Merged revision 1534523 from trunk.

Modified:
    db/derby/code/branches/10.10/   (props changed)
    db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/SqlWarning.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1534523

Modified: db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/SqlWarning.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/SqlWarning.java?rev=1535335&r1=1535334&r2=1535335&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/SqlWarning.java (original)
+++ db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/SqlWarning.java Thu Oct 24 10:39:44 2013
@@ -104,17 +104,9 @@ public class SqlWarning extends SqlExcep
         // Set up the nextException chain
         if ( nextWarning_ != null )
         {
-            // The exception chain gets constructed automatically through 
+            // The warning chain gets constructed automatically through
             // the beautiful power of recursion
-            //
-            // We have to use the right method to convert the next exception
-            // depending upon its type.  Luckily with all the other subclasses
-            // of SQLException we don't have to make our own matching 
-            // subclasses because 
-            sqlw.setNextException(
-                nextException_ instanceof SqlWarning ?
-                    ((SqlWarning)nextException_).getSQLWarning() :
-                    nextException_.getSQLException());
+            sqlw.setNextWarning(nextWarning_.getSQLWarning());
         }
         
         return sqlw;

Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java?rev=1535335&r1=1535334&r2=1535335&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java Thu Oct 24 10:39:44 2013
@@ -32,6 +32,7 @@ import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.SQLWarning;
 import java.sql.Statement;
 import java.sql.Time;
 import java.sql.Timestamp;
@@ -359,6 +360,38 @@ public class BatchUpdateTest extends Bas
         commit();
     }
 
+    /**
+     * Regression test case for DERBY-6373.
+     */
+    public void testMultipleStatementsBatchWithWarnings() throws SQLException {
+        Statement s = createStatement();
+        s.execute("insert into t1 values 1");
+
+        // Execute a batch of three deletes. All of them should get a warning
+        // because no rows matched the WHERE clause.
+        s.addBatch("delete from t1 where c1 in (select 0 from t1)");
+        s.addBatch("delete from t1 where c1 in (select 0 from t1)");
+        s.addBatch("delete from t1 where c1 in (select 0 from t1)");
+        s.executeBatch();
+
+        // Used to fail with NullPointerException on the client.
+        SQLWarning w = s.getWarnings();
+
+        // Expect one warning per delete on the client. Embedded gives only
+        // a single warning.
+        assertSQLState("02000", w);
+        w = w.getNextWarning();
+        if (usingEmbedded()) {
+            assertNull(w);
+        } else {
+            assertSQLState("02000", w);
+            w = w.getNextWarning();
+            assertSQLState("02000", w);
+            w = w.getNextWarning();
+            assertNull(w);
+        }
+    }
+
     // try executing a batch with 1000 statements in it.
     public void test1000StatementsBatch() throws SQLException {
         int updateCount[];