@@ -12271,4 +12271,59 @@ void testBug114705() throws Exception {
12271
12271
}
12272
12272
}
12273
12273
12274
+ /**
12275
+ * Tests fix for Bug#116318 (Bug#37152533), useServerPrepStmts useLocalTransactionState cause first execute rollback failure.
12276
+ *
12277
+ * @throws Exception
12278
+ */
12279
+ @Test
12280
+ void testBug116318() throws Exception {
12281
+ createTable("testBug116318", "(id INT PRIMARY KEY)");
12282
+
12283
+ boolean useSPS = false;
12284
+ boolean useLTS = false;
12285
+ boolean useLSS = false;
12286
+
12287
+ do {
12288
+ final String testCase = String.format("Case: [useSPS: %s, useLTS: %s, useLSS: %s ]", useSPS ? "Y" : "N", useLTS ? "Y" : "N", useLSS ? "Y" : "N");
12289
+
12290
+ Properties props = new Properties();
12291
+ props.setProperty(PropertyKey.sslMode.getKeyName(), PropertyDefinitions.SslMode.DISABLED.name());
12292
+ props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
12293
+ props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
12294
+ props.setProperty(PropertyKey.useLocalTransactionState.getKeyName(), Boolean.toString(useLTS));
12295
+ props.setProperty(PropertyKey.useLocalSessionState.getKeyName(), Boolean.toString(useLSS));
12296
+
12297
+ // Insert duplicate record one by one.
12298
+ try (Connection testConn = getConnectionWithProps(props)) {
12299
+ testConn.setAutoCommit(false);
12300
+ PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
12301
+ testPstmt.executeUpdate();
12302
+ PreparedStatement testPstmt2 = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
12303
+ assertThrows(testCase, SQLException.class, testPstmt2::executeUpdate);
12304
+ testConn.rollback();
12305
+ testConn.setAutoCommit(true); // Bad data must have been rolled back, otherwise this commits it.
12306
+ }
12307
+ this.rs = this.stmt.executeQuery("SELECT * FROM testBug116318");
12308
+ assertFalse(this.rs.next(), testCase);
12309
+
12310
+ // Insert duplicate record in batch.
12311
+ try (Connection testConn = getConnectionWithProps(props)) {
12312
+ testConn.createStatement().execute("TRUNCATE TABLE testBug116318");
12313
+ testConn.setAutoCommit(false);
12314
+ PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
12315
+ testPstmt.addBatch();
12316
+ testPstmt.executeBatch();
12317
+ PreparedStatement testPstmt2 = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
12318
+ testPstmt2.addBatch();
12319
+ assertThrows(testCase, SQLException.class, testPstmt2::executeBatch);
12320
+ testConn.rollback();
12321
+
12322
+ testConn.setAutoCommit(true); // Bad data must have been rolled back, otherwise this commits it.
12323
+ }
12324
+ this.rs = this.stmt.executeQuery("SELECT * FROM testBug116318");
12325
+ assertFalse(this.rs.next(), testCase);
12326
+ } while ((useSPS = !useSPS) || (useLTS = !useLTS) || (useLSS = !useLSS));
12327
+ }
12328
+
12274
12329
}
0 commit comments