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/22 09:14:25 UTC
svn commit: r1534523 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/SqlWarning.java
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Author: kahatlen
Date: Tue Oct 22 07:14:24 2013
New Revision: 1534523
URL: http://svn.apache.org/r1534523
Log:
DERBY-6373: NPE in Statement.getWarnings()
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java?rev=1534523&r1=1534522&r2=1534523&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java Tue Oct 22 07:14:24 2013
@@ -71,17 +71,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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java?rev=1534523&r1=1534522&r2=1534523&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java Tue Oct 22 07:14:24 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[];