Skip to content

Commit

Permalink
Fix for Bug#109418 (Bug#36043556), batch insert threw an unexpected e…
Browse files Browse the repository at this point in the history
…xception.

Change-Id: I6db6db07286b78636acaed74bfe37095872ffe17
  • Loading branch information
Axyoan Marcelo committed Jul 19, 2024
1 parent 33b8fc7 commit c35535d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 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#109418 (Bug#36043556), batch insert threw an unexpected exception.

- Fix for Bug#114410 (Bug#36434816), Code performance issue.

- Fix for Bug#110586 (Bug#35254470), got unexpected result when the data type was set to ZEROFILL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public void close() throws SQLException {

this.connection.recachePreparedStatement(this);
this.isCached = true;
this.results = null;
this.generatedKeysResults = null;
return;
}

Expand Down
47 changes: 47 additions & 0 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13677,4 +13677,51 @@ public void testBug22931632() throws Exception {
assertDoesNotThrow(((JdbcPreparedStatement) this.pstmt)::getParameterBindings);
}

/**
* Test fix for Bug#109418 (Bug#36043556), batch insert threw an unexpected exception.
*
* @throws Exception
*/
@Test
public void testBug109418() throws Exception {
boolean useRBS = false;
boolean cachePS = false;
boolean useSPS = false;
boolean useRGK = false;
do {
Properties props = new Properties();
props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), Boolean.toString(useRBS));
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
try (Connection testConn = getConnectionWithProps(props)) {
createTable("testBug109418", "(id INT PRIMARY KEY)");

this.pstmt = testConn.prepareStatement("INSERT INTO testBug109418(id) VALUES(?)",
useRGK ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);

this.pstmt.setInt(1, 1);
this.pstmt.addBatch();
this.pstmt.setInt(1, 2);
this.pstmt.addBatch();
this.pstmt.executeBatch();
this.pstmt.close();

this.pstmt = testConn.prepareStatement("INSERT INTO testBug109418(id) VALUES(?)",
useRGK ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
this.pstmt.setInt(1, 3);
this.pstmt.addBatch();
this.pstmt.setInt(1, 1);
this.pstmt.addBatch();

final String testCase = String.format("Case: [useRBS=%s, cachePS=%s, useSPS=%s, useRGK=%s]", useRBS ? "Y" : "N", cachePS ? "Y" : "N",
useSPS ? "Y" : "N", useRGK ? "Y" : "N");
assertThrows(testCase, BatchUpdateException.class, this.pstmt::executeBatch);
} finally {
dropTable("testBug109418");
this.pstmt.close();
}

} while ((useRBS = !useRBS) || (cachePS = !cachePS) || (useSPS = !useSPS) || (useRGK = !useRGK));
}

}

0 comments on commit c35535d

Please sign in to comment.