db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r795549 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Date Sun, 19 Jul 2009 14:43:42 GMT
Author: kahatlen
Date: Sun Jul 19 14:43:41 2009
New Revision: 795549

URL: http://svn.apache.org/viewvc?rev=795549&view=rev
Log:
DERBY-4316: Embedded and client don't agree on whether to continue after error in batch

Added a test case that shows the difference.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java

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=795549&r1=795548&r2=795549&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
Sun Jul 19 14:43:41 2009
@@ -1521,4 +1521,49 @@
             fail("Could not see 'duplicate key' in printStackTrace()", bue);
         }
     }
+
+    /**
+     * Test the behaviour when one of the statements in a batch fails. The
+     * embedded driver stops executing the batch when that happens, whereas
+     * the client driver continues. The difference between embedded and
+     * client is logged as DERBY-4316.
+     */
+    public void testContinueAfterError() throws SQLException {
+        // Turn off auto-commit so that the tables added by the test can be
+        // rolled back in tearDown().
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+        s.execute("create table a(x int)");
+        s.execute("create table b(x int primary key)");
+        s.execute("create table c(x int references b(x))");
+
+        // Drop the three tables in a batch. Since B is referenced by C, it
+        // cannot be dropped before C is dropped. Hence DROP TABLE B will fail.
+        s.addBatch("drop table a");
+        s.addBatch("drop table b");
+        s.addBatch("drop table c");
+
+        // Embedded stops processing the batch on the first failure, and only
+        // the update count from the successful statement is returned. The
+        // client driver continues after the failure, so it'll also drop C.
+        int[] expectedCounts = usingEmbedded() ?
+            new int[]{0} : new int[]{0, Statement.EXECUTE_FAILED, 0};
+
+        assertBatchExecuteError("X0Y25", s, expectedCounts);
+
+        // Table A should not exist after the batch was executed.
+        assertStatementError("42X05", s, "select * from a");
+        // Table B should still exist, since DROP TABLE B failed.
+        assertTableRowCount("B", 0);
+
+        // Embedded driver stops after failure, so expect table C to exist,
+        // whereas the client driver continues after failure, so expect that
+        // it does not exist.
+        if (usingEmbedded()) {
+            assertTableRowCount("C", 0);
+        } else {
+            assertStatementError("42X05", s, "select * from c");
+        }
+    }
 }



Mime
View raw message