Skip to content

Commit

Permalink
Fix for Bug#116318 (Bug#37152533), useServerPrepStmts useLocalTransac…
Browse files Browse the repository at this point in the history
…tionState cause first execute rollback failure.

Change-Id: Ifb5c03f5efda1a450a43d14a7a2bb4693dbad1b5
  • Loading branch information
Axyoan Marcelo authored and fjssilva committed Dec 16, 2024
1 parent c9e78a2 commit a3909bf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 9.2.0

- Fix for Bug#116318 (Bug#37152533), useServerPrepStmts useLocalTransactionState cause first execute rollback failure.

- Fix for Bug#116955 (Bug#37383012), Tests fail after server changed cipher for xdevapi.

- Fix for Bug#63992 (Bug#14598872), getTables did not return a result for table names with a dot in it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ public NativePacketPayload checkErrorMessage() {
*/
private NativePacketPayload checkErrorMessage(int command) {
NativePacketPayload resultPacket = null;
this.serverSession.setStatusFlags(0);
this.serverSession.setStatusFlags(0, command == NativeConstants.COM_STMT_PREPARE);

try {
// 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
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/testsuite/regression/ConnectionRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12271,4 +12271,59 @@ void testBug114705() throws Exception {
}
}

/**
* Tests fix for Bug#116318 (Bug#37152533), useServerPrepStmts useLocalTransactionState cause first execute rollback failure.
*
* @throws Exception
*/
@Test
void testBug116318() throws Exception {
createTable("testBug116318", "(id INT PRIMARY KEY)");

boolean useSPS = false;
boolean useLTS = false;
boolean useLSS = false;

do {
final String testCase = String.format("Case: [useSPS: %s, useLTS: %s, useLSS: %s ]", useSPS ? "Y" : "N", useLTS ? "Y" : "N", useLSS ? "Y" : "N");

Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), PropertyDefinitions.SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
props.setProperty(PropertyKey.useLocalTransactionState.getKeyName(), Boolean.toString(useLTS));
props.setProperty(PropertyKey.useLocalSessionState.getKeyName(), Boolean.toString(useLSS));

// Insert duplicate record one by one.
try (Connection testConn = getConnectionWithProps(props)) {
testConn.setAutoCommit(false);
PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
testPstmt.executeUpdate();
PreparedStatement testPstmt2 = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
assertThrows(testCase, SQLException.class, testPstmt2::executeUpdate);
testConn.rollback();
testConn.setAutoCommit(true); // Bad data must have been rolled back, otherwise this commits it.
}
this.rs = this.stmt.executeQuery("SELECT * FROM testBug116318");
assertFalse(this.rs.next(), testCase);

// Insert duplicate record in batch.
try (Connection testConn = getConnectionWithProps(props)) {
testConn.createStatement().execute("TRUNCATE TABLE testBug116318");
testConn.setAutoCommit(false);
PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
testPstmt.addBatch();
testPstmt.executeBatch();
PreparedStatement testPstmt2 = testConn.prepareStatement("INSERT INTO testBug116318 VALUES (1)");
testPstmt2.addBatch();
assertThrows(testCase, SQLException.class, testPstmt2::executeBatch);
testConn.rollback();

testConn.setAutoCommit(true); // Bad data must have been rolled back, otherwise this commits it.
}
this.rs = this.stmt.executeQuery("SELECT * FROM testBug116318");
assertFalse(this.rs.next(), testCase);
} while ((useSPS = !useSPS) || (useLTS = !useLTS) || (useLSS = !useLSS));
}

}

0 comments on commit a3909bf

Please sign in to comment.