Skip to content

Commit

Permalink
Fix for Bug#96623 (Bug#30221117), batch update with rewriteBatchedSta…
Browse files Browse the repository at this point in the history
…tements&useServerPrepStmts send fail request.

Change-Id: I938dde221f3a246906f10c367c28be1bb02301b8
  • Loading branch information
Axyoan Marcelo committed Sep 17, 2024
1 parent 5530fb9 commit 03dedd7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
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.1.0

- Fix for Bug#96623 (Bug#30221117), batch update with rewriteBatchedStatements&useServerPrepStmts send fail request.

- Fix for Bug#114705 (Bug#36539680), Contribution: make trustStorePassword be null if this.trustStoreSettings.keyStorePassword is null.
Thanks to Jesper Blomquist for his contribution.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ private boolean canHandleAsServerPreparedStatement(String sql) throws SQLExcepti
return false;
}

boolean allowMultiQueries = this.propertySet.getBooleanProperty(PropertyKey.allowMultiQueries).getValue();
boolean allowMultiQueries = this.propertySet.getBooleanProperty(PropertyKey.allowMultiQueries).getValue()
|| this.propertySet.getBooleanProperty(PropertyKey.rewriteBatchedStatements).getValue();

if (this.cachePrepStmts.getValue()) {
this.serverSideStatementCheckCacheLock.lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ protected void serverPrepare(String sql) throws SQLException {
t = SQLError.createCommunicationsException(this.connection, this.session.getProtocol().getPacketSentTimeHolder(),
this.session.getProtocol().getPacketReceivedTimeHolder(), ioEx, this.exceptionInterceptor);
} catch (CJException sqlEx) {
SQLException ex = SQLExceptionsMapping.translateException(sqlEx);
SQLException ex = SQLExceptionsMapping.translateException(sqlEx, this.exceptionInterceptor);

if (this.dumpQueriesOnException.getValue()) {
StringBuilder messageBuf = new StringBuilder(((PreparedQuery) this.query).getOriginalSql().length() + 32);
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
import com.mysql.cj.conf.PropertySet;
import com.mysql.cj.exceptions.CJCommunicationsException;
import com.mysql.cj.exceptions.ExceptionFactory;
import com.mysql.cj.exceptions.ExceptionInterceptor;
import com.mysql.cj.exceptions.MysqlErrorNumbers;
import com.mysql.cj.exceptions.WrongArgumentException;
import com.mysql.cj.interceptors.QueryInterceptor;
Expand Down Expand Up @@ -13929,4 +13930,61 @@ public <T extends Resultset> T preProcess(Supplier<String> sql, Query intercepte

}

/**
* Tests fix for Bug#96623 (Bug#30221117), batch update with rewriteBatchedStatements&useServerPrepStmts send fail request.
*
* @throws Exception
*/
@Test
public void testBug96623() throws Exception {
boolean allowMQ = false;
boolean rwBS = false;
boolean useSPS = false;
boolean cachePS = false;

createTable("testBug96623", "(c0 int)");
do {
Properties props = new Properties();
props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), Boolean.toString(allowMQ));
props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), Boolean.toString(rwBS));
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
props.setProperty(PropertyKey.emulateUnsupportedPstmts.getKeyName(), "true");
props.setProperty(PropertyKey.exceptionInterceptors.getKeyName(), TestBug96623ExceptionInterceptor.class.getName());

TestBug96623ExceptionInterceptor.testCase = String.format("Case [allowMQ: %s, rwBS: %s, useSPS: %s, cachePS: %s]", allowMQ ? "Y" : "N",
rwBS ? "Y" : "N", useSPS ? "Y" : "N", cachePS ? "Y" : "N");

try (Connection testConn = getConnectionWithProps(props); PreparedStatement ps = testConn.prepareStatement("UPDATE testBug96623 SET c0=?")) {
for (int i = 0; i < 4; i++) {
ps.setInt(1, i);
ps.addBatch();
}

ps.executeBatch();
}
} while ((allowMQ = !allowMQ) || (rwBS = !rwBS) || (useSPS = !useSPS) || (cachePS = !cachePS));
}

public static class TestBug96623ExceptionInterceptor implements ExceptionInterceptor {

static String testCase = null;

@Override
public ExceptionInterceptor init(Properties props, Log log) {
return this;
}

@Override
public void destroy() {
}

@Override
public SQLException interceptException(Exception sqlEx) {
assertFalse(sqlEx instanceof SQLSyntaxErrorException, testCase);
return null;
}

}

}

0 comments on commit 03dedd7

Please sign in to comment.