From 8d279d3b53356fdd0f56da421152077813a1c51b Mon Sep 17 00:00:00 2001 From: Axyoan Marcelo Date: Tue, 21 Nov 2023 13:05:23 -0600 Subject: [PATCH] Fix for Bug#107107 (Bug#34101635), Redundant "Reset stmt" when setting useServerPrepStmts&cachePrepStmts to true. Change-Id: I9523c90db6d97775db73ed62acb2694eaaffe576 --- CHANGES | 3 ++ .../com/mysql/cj/ServerPreparedQuery.java | 4 +- .../regression/StatementRegressionTest.java | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index c6c645c34..84f2afbf6 100644 --- a/CHANGES +++ b/CHANGES @@ -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. diff --git a/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java b/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java index 2c9532f81..f91ebb98a 100644 --- a/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java +++ b/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java @@ -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) { @@ -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); } } diff --git a/src/test/java/testsuite/regression/StatementRegressionTest.java b/src/test/java/testsuite/regression/StatementRegressionTest.java index 326a5dc8f..a9467a970 100644 --- a/src/test/java/testsuite/regression/StatementRegressionTest.java +++ b/src/test/java/testsuite/regression/StatementRegressionTest.java @@ -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 + "'"); + } + } + }