Skip to content

Commit

Permalink
Fix for Bug#107107 (Bug#34101635), Redundant "Reset stmt" when settin…
Browse files Browse the repository at this point in the history
…g useServerPrepStmts&cachePrepStmts to true.

Change-Id: I9523c90db6d97775db73ed62acb2694eaaffe576
  • Loading branch information
Axyoan Marcelo committed Dec 6, 2023
1 parent 644be22 commit 8d279d3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

Version 8.3.0

- Fix for Bug#107107 (Bug#34101635), Redundant "Reset stmt" when setting useServerPrepStmts&cachePrepStmts to true.
Thanks to Marcos Albe for his contribution.

- Fix for Bug#19845752, COMMENT PARSING IS NOT PROPER IN CONNECTOR JDBC.

- Fix for Bug#112884 (Bug#36043166), Setting a large timeout leads to errors when executing SQL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public void clearParameters(boolean clearServerParameters) {

if (this.queryBindings != null) {
hadLongData = this.queryBindings.clearBindValues();
this.queryBindings.setLongParameterSwitchDetected(clearServerParameters && hadLongData ? false : true);
this.queryBindings.setLongParameterSwitchDetected(clearServerParameters && hadLongData);
}

if (clearServerParameters && hadLongData) {
Expand All @@ -567,6 +567,8 @@ public void serverResetStatement() {
this.session.getProtocol().getServerSession().preserveOldTransactionState();
this.session.clearInputStream();
}
// Nothing to be detected after a reset...
this.queryBindings.setLongParameterSwitchDetected(false);
}
}

Expand Down
51 changes: 51 additions & 0 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13555,4 +13555,55 @@ void testBug112884() throws Exception {
});
}

/**
* Tests fix for Bug#107107 (Bug#34101635), Redundant "Reset stmt" when setting useServerPrepStmts&cachePrepStmts to true.
*
* @throws Exception
*/
@Test
void testBug107107() throws Exception {
String prevGeneralLog = this.getMysqlVariable("general_log");
String prevLogOutput = this.getMysqlVariable("log_output");

try {
Properties props = new Properties();
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "true");
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);

this.stmt.execute("SET GLOBAL general_log = 'OFF'");
this.stmt.execute("SET GLOBAL log_output = 'TABLE'");
this.stmt.execute("SET GLOBAL general_log = 'ON'");

createTable("testBug107107", "(id INT)");

PreparedStatement ps = null;
String sql = "INSERT INTO testBug107107 (id) VALUES (?)";
for (int i = 1; i <= 3; i++) {
ps = testConn.prepareStatement(sql);
ps.setInt(1, i);
ps.execute();
ps.close();
}

boolean foundTestTable = false;
this.rs = this.stmt.executeQuery("SELECT command_type, CONVERT(argument USING utf8mb4) FROM mysql.general_log ORDER BY event_time DESC LIMIT 10");
while (this.rs.next()) {
String commandType = this.rs.getString(1);
String argument = this.rs.getString(2);
if (!foundTestTable && argument.contains("testBug107107")) {
foundTestTable = true;
}
assertFalse(commandType.contains("Reset stmt"), "Unexpected Reset stmt command found.");
}
assertTrue(foundTestTable, "Expected general log events were not recorded in mysql.general_log.");

testConn.close();
} finally {
this.stmt.execute("SET GLOBAL general_log = 'OFF'");
this.stmt.execute("SET GLOBAL log_output = '" + prevLogOutput + "'");
this.stmt.execute("SET GLOBAL general_log = '" + prevGeneralLog + "'");
}
}

}

0 comments on commit 8d279d3

Please sign in to comment.