Skip to content

Commit bbe2c6b

Browse files
committed
Fix for Bug#109013 (Bug#34772608), useServerPrepStmts and useLocalTransactionState could cause rollback failure.
Change-Id: I88f259cb0d7615fe583247042e6c79512081ba4d
1 parent de0d864 commit bbe2c6b

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.33
55

6+
- Fix for Bug#109013 (Bug#34772608), useServerPrepStmts and useLocalTransactionState could cause rollback failure.
7+
68
- Fix for bug Bug#108643 (Bug#34652568), Commit statement not effect when two params turns on.
79

810
- Fix for Bug#34918989, Pluggable classes are initialized even when they cannot be used by Connector/J.

src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java

+2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ public void serverResetStatement() {
572572
this.session.getProtocol().sendCommand(this.commandBuilder.buildComStmtReset(this.session.getSharedSendPacket(), this.serverStatementId), false,
573573
0);
574574
} finally {
575+
// OK_PACKET returned in previous sendCommand() was not processed so keep original transaction state.
576+
this.session.getProtocol().getServerSession().preserveOldTransactionState();
575577
this.session.clearInputStream();
576578
}
577579
}

src/test/java/testsuite/regression/ConnectionRegressionTest.java

+60
Original file line numberDiff line numberDiff line change
@@ -11788,4 +11788,64 @@ void testBug108643() throws Exception {
1178811788
this.stmt.execute("TRUNCATE TABLE testBug108643");
1178911789
} while ((useSPS = !useSPS) || (allowMQ = !allowMQ) || (rwBatchStmts = !rwBatchStmts) || (useLTS = !useLTS) || (useLSS = !useLSS));
1179011790
}
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+
}
1179111851
}

0 commit comments

Comments
 (0)