@@ -11788,4 +11788,64 @@ void testBug108643() throws Exception {
11788
11788
this.stmt.execute("TRUNCATE TABLE testBug108643");
11789
11789
} while ((useSPS = !useSPS) || (allowMQ = !allowMQ) || (rwBatchStmts = !rwBatchStmts) || (useLTS = !useLTS) || (useLSS = !useLSS));
11790
11790
}
11791
+
11792
+ /**
11793
+ * Tests fix for Bug#109013 (Bug#34772608), useServerPrepStmts and useLocalTransactionState could cause rollback failure.
11794
+ *
11795
+ * @throws Exception
11796
+ */
11797
+ @Test
11798
+ void testBug109013() throws Exception {
11799
+ createTable("testBug109013", "(id INT PRIMARY KEY)");
11800
+
11801
+ boolean useSPS = false;
11802
+ boolean useLTS = false;
11803
+ boolean useLSS = false;
11804
+
11805
+ do {
11806
+ final String testCase = String.format("Case: [useSPS: %s, useLTS: %s, useLSS: %s ]", useSPS ? "Y" : "N", useLTS ? "Y" : "N", useLSS ? "Y" : "N");
11807
+
11808
+ Properties props = new Properties();
11809
+ props.setProperty(PropertyKey.sslMode.getKeyName(), PropertyDefinitions.SslMode.DISABLED.name());
11810
+ props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11811
+ props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
11812
+ props.setProperty(PropertyKey.useLocalTransactionState.getKeyName(), Boolean.toString(useLTS));
11813
+ props.setProperty(PropertyKey.useLocalSessionState.getKeyName(), Boolean.toString(useLSS));
11814
+
11815
+ // Insert duplicate record in batch.
11816
+ try (Connection testConn = getConnectionWithProps(props)) {
11817
+ testConn.setAutoCommit(false);
11818
+ try (PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug109013 VALUES (?)")) {
11819
+ testPstmt.setInt(1, 1);
11820
+ testPstmt.addBatch();
11821
+ testPstmt.setInt(1, 1); // Duplicate record.
11822
+ testPstmt.addBatch();
11823
+ assertThrows(testCase, SQLException.class, testPstmt::executeBatch);
11824
+ testConn.rollback();
11825
+ }
11826
+ testConn.setAutoCommit(true); // Bad data must have been rolled back, otherwise this commits it.
11827
+ }
11828
+ this.rs = this.stmt.executeQuery("SELECT * FROM testBug109013");
11829
+ assertFalse(this.rs.next(), testCase);
11830
+
11831
+ // Insert duplicate record one by one.
11832
+ try (Connection testConn = getConnectionWithProps(props)) {
11833
+ testConn.createStatement().execute("TRUNCATE TABLE testBug109013");
11834
+ testConn.setAutoCommit(false);
11835
+ try (PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug109013 VALUES (?)")) {
11836
+ testPstmt.clearParameters();
11837
+ testPstmt.setInt(1, 1);
11838
+ assertEquals(1, testPstmt.executeUpdate());
11839
+ testPstmt.clearParameters();
11840
+ testPstmt.setInt(1, 1); // Duplicate record.
11841
+ assertThrows(testCase, SQLException.class, testPstmt::executeUpdate);
11842
+ testConn.rollback();
11843
+ }
11844
+ testConn.setAutoCommit(true); // Bad data must have been rolled back, otherwise this commits it.
11845
+ }
11846
+ this.rs = this.stmt.executeQuery("SELECT * FROM testBug109013");
11847
+ assertFalse(this.rs.next(), testCase);
11848
+
11849
+ } while ((useSPS = !useSPS) || (useLTS = !useLTS) || (useLSS = !useLSS));
11850
+ }
11791
11851
}
0 commit comments