Skip to content

Commit a3909bf

Browse files
Axyoan Marcelofjssilva
Axyoan Marcelo
authored andcommitted
Fix for Bug#116318 (Bug#37152533), useServerPrepStmts useLocalTransactionState cause first execute rollback failure.
Change-Id: Ifb5c03f5efda1a450a43d14a7a2bb4693dbad1b5
1 parent c9e78a2 commit a3909bf

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

CHANGES

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

44
Version 9.2.0
55

6+
- Fix for Bug#116318 (Bug#37152533), useServerPrepStmts useLocalTransactionState cause first execute rollback failure.
7+
68
- Fix for Bug#116955 (Bug#37383012), Tests fail after server changed cipher for xdevapi.
79

810
- Fix for Bug#63992 (Bug#14598872), getTables did not return a result for table names with a dot in it.

src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ public NativePacketPayload checkErrorMessage() {
761761
*/
762762
private NativePacketPayload checkErrorMessage(int command) {
763763
NativePacketPayload resultPacket = null;
764-
this.serverSession.setStatusFlags(0);
764+
this.serverSession.setStatusFlags(0, command == NativeConstants.COM_STMT_PREPARE);
765765

766766
try {
767767
// Check return value, if we get a java.io.EOFException, the server has gone away. We'll pass it on up the exception chain and let someone higher up

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

+55
Original file line numberDiff line numberDiff line change
@@ -12271,4 +12271,59 @@ void testBug114705() throws Exception {
1227112271
}
1227212272
}
1227312273

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+
1227412329
}

0 commit comments

Comments
 (0)