Skip to content

Commit 317b53d

Browse files
fix: add check to prevent updateCounts being set to an invalid number (#451)
1 parent 122bff7 commit 317b53d

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

CHANGELOG.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/#semantic-versioning-200).
55

6+
## [?]
7+
### Fixed
8+
* Incorrect BatchUpdateException.getUpdateCounts() on failed batch statement execution ([Issue #450](https://github.com/awslabs/aws-mysql-jdbc/issues/450)).
9+
610
## [1.1.9] - 2023-07-31
711
### Added
8-
- Documentation:
9-
- An example of how to enable logging ([PR #431](https://github.com/awslabs/aws-mysql-jdbc/pull/431)).
10-
- Release policy ([PR #434](https://github.com/awslabs/aws-mysql-jdbc/pull/434)).
11-
- The `keepSessionStateOnFailover` failover property to allow retaining the connection session state after failover without manually reconfiguring a connection ([Issue #425](https://github.com/awslabs/aws-mysql-jdbc/issues/425)).
12+
* Documentation:
13+
* An example of how to enable logging ([PR #431](https://github.com/awslabs/aws-mysql-jdbc/pull/431)).
14+
* Release policy ([PR #434](https://github.com/awslabs/aws-mysql-jdbc/pull/434)).
15+
* The `keepSessionStateOnFailover` failover property to allow retaining the connection session state after failover without manually reconfiguring a connection ([Issue #425](https://github.com/awslabs/aws-mysql-jdbc/issues/425)).
1216

1317
### Fixed
14-
- Avoid updating topology during global transactions which caused JTA transactions to fail ([Issue #292](https://github.com/awslabs/aws-mysql-jdbc/issues/292)).
15-
- Keep `currentHostIndex` and hosts list in sync and pick a new connection when host role changes ([Issue #303](https://github.com/awslabs/aws-mysql-jdbc/issues/303)).
16-
- Redundant reset statement called due to incorrect condition ([Issue #422](https://github.com/awslabs/aws-mysql-jdbc/pull/435)).
18+
* Avoid updating topology during global transactions which caused JTA transactions to fail ([Issue #292](https://github.com/awslabs/aws-mysql-jdbc/issues/292)).
19+
* Keep `currentHostIndex` and hosts list in sync and pick a new connection when host role changes ([Issue #303](https://github.com/awslabs/aws-mysql-jdbc/issues/303)).
20+
* Redundant reset statement called due to incorrect condition ([Issue #422](https://github.com/awslabs/aws-mysql-jdbc/pull/435)).
1721

1822
## [1.1.8] - 2023-06-28
1923
### Fixed
20-
- The topology service cache no longer stores connection specific properties so connections to the same cluster will not connect with the wrong properties ([Issue #407](https://github.com/awslabs/aws-mysql-jdbc/issues/407)).
21-
- Fixed value `convertToNull` being rejected for property `zeroDateTimeBehavior` because of capitalization ([Issue #411](https://github.com/awslabs/aws-mysql-jdbc/pull/413)).
22-
- Handle case in the `FailoverConnectionPlugin` where the `currentHostIndex` is equal to `NO_CONNECTION_INDEX` ([Issue #417](https://github.com/awslabs/aws-mysql-jdbc/issues/417)).
24+
* The topology service cache no longer stores connection specific properties so connections to the same cluster will not connect with the wrong properties ([Issue #407](https://github.com/awslabs/aws-mysql-jdbc/issues/407)).
25+
* Fixed value `convertToNull` being rejected for property `zeroDateTimeBehavior` because of capitalization ([Issue #411](https://github.com/awslabs/aws-mysql-jdbc/pull/413)).
26+
* Handle case in the `FailoverConnectionPlugin` where the `currentHostIndex` is equal to `NO_CONNECTION_INDEX` ([Issue #417](https://github.com/awslabs/aws-mysql-jdbc/issues/417)).
2327

2428
## [1.1.7] - 2023-05-11
2529
### Changed

src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* You should have received a copy of the GNU General Public License along with
2626
* this program; if not, write to the Free Software Foundation, Inc.,
2727
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
*
29+
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2830
*/
2931

3032
package com.mysql.cj.jdbc;
@@ -1053,7 +1055,9 @@ private long[] executeBatchUsingMultiQueries(boolean multiQueriesEnabled, int nb
10531055

10541056
protected int processMultiCountsAndKeys(StatementImpl batchedStatement, int updateCountCounter, long[] updateCounts) throws SQLException {
10551057
synchronized (checkClosed().getConnectionMutex()) {
1056-
updateCounts[updateCountCounter++] = batchedStatement.getLargeUpdateCount();
1058+
if (batchedStatement.getLargeUpdateCount() != -1) {
1059+
updateCounts[updateCountCounter++] = batchedStatement.getLargeUpdateCount();
1060+
}
10571061

10581062
boolean doGenKeys = this.batchedGeneratedKeys != null;
10591063

src/test/java/testsuite/regression/StatementRegressionTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* You should have received a copy of the GNU General Public License along with
2626
* this program; if not, write to the Free Software Foundation, Inc.,
2727
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
*
29+
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2830
*/
2931

3032
package testsuite.regression;
@@ -12671,4 +12673,38 @@ public void testBug107222() throws Exception {
1267112673
assertEquals(-1, sql.indexOf("NULL", startPos), testCase);
1267212674
} while ((useSPS = !useSPS) && (setMax = !setMax));
1267312675
}
12676+
12677+
/**
12678+
* Test fix for Issue #450. BatchUpdateException.getUpdateCounts() should return EXECUTE_FAILED status when an error
12679+
* occurs while executing a batch statement.
12680+
*
12681+
* @throws Exception
12682+
*/
12683+
@Test
12684+
public void testBugIssue450() throws Exception {
12685+
Properties props = new Properties();
12686+
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
12687+
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
12688+
props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), "true");
12689+
this.conn = getConnectionWithProps(props);
12690+
Statement stmt = this.conn.createStatement();
12691+
12692+
String tableName = "testBugIssue450";
12693+
12694+
createTable(tableName, "(c0 INT PRIMARY KEY NOT NULL)");
12695+
12696+
stmt.execute("INSERT INTO " + tableName + " VALUES (1)");
12697+
12698+
Statement bstmt = conn.createStatement();
12699+
bstmt.addBatch("INSERT INTO " + tableName + " VALUES (1)");
12700+
bstmt.addBatch("INSERT INTO " + tableName + " VALUES (2)");
12701+
try {
12702+
bstmt.executeBatch();
12703+
} catch (BatchUpdateException e) {
12704+
int[] res = e.getUpdateCounts();
12705+
for (int r : res) {
12706+
assertEquals(Statement.EXECUTE_FAILED, r);
12707+
}
12708+
}
12709+
}
1267412710
}

0 commit comments

Comments
 (0)