Skip to content

Commit

Permalink
fix: add check to prevent updateCounts being set to an invalid number (
Browse files Browse the repository at this point in the history
  • Loading branch information
crystall-bitquill authored Sep 7, 2023
1 parent 122bff7 commit 317b53d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
24 changes: 14 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ All notable changes to this project will be documented in this file.

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).

## [?]
### Fixed
* Incorrect BatchUpdateException.getUpdateCounts() on failed batch statement execution ([Issue #450](https://github.com/awslabs/aws-mysql-jdbc/issues/450)).

## [1.1.9] - 2023-07-31
### Added
- Documentation:
- An example of how to enable logging ([PR #431](https://github.com/awslabs/aws-mysql-jdbc/pull/431)).
- Release policy ([PR #434](https://github.com/awslabs/aws-mysql-jdbc/pull/434)).
- 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)).
* Documentation:
* An example of how to enable logging ([PR #431](https://github.com/awslabs/aws-mysql-jdbc/pull/431)).
* Release policy ([PR #434](https://github.com/awslabs/aws-mysql-jdbc/pull/434)).
* 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)).

### Fixed
- Avoid updating topology during global transactions which caused JTA transactions to fail ([Issue #292](https://github.com/awslabs/aws-mysql-jdbc/issues/292)).
- 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)).
- Redundant reset statement called due to incorrect condition ([Issue #422](https://github.com/awslabs/aws-mysql-jdbc/pull/435)).
* Avoid updating topology during global transactions which caused JTA transactions to fail ([Issue #292](https://github.com/awslabs/aws-mysql-jdbc/issues/292)).
* 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)).
* Redundant reset statement called due to incorrect condition ([Issue #422](https://github.com/awslabs/aws-mysql-jdbc/pull/435)).

## [1.1.8] - 2023-06-28
### Fixed
- 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)).
- Fixed value `convertToNull` being rejected for property `zeroDateTimeBehavior` because of capitalization ([Issue #411](https://github.com/awslabs/aws-mysql-jdbc/pull/413)).
- 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)).
* 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)).
* Fixed value `convertToNull` being rejected for property `zeroDateTimeBehavior` because of capitalization ([Issue #411](https://github.com/awslabs/aws-mysql-jdbc/pull/413)).
* 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)).

## [1.1.7] - 2023-05-11
### Changed
Expand Down
6 changes: 5 additions & 1 deletion src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

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

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

boolean doGenKeys = this.batchedGeneratedKeys != null;

Expand Down
36 changes: 36 additions & 0 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

package testsuite.regression;
Expand Down Expand Up @@ -12671,4 +12673,38 @@ public void testBug107222() throws Exception {
assertEquals(-1, sql.indexOf("NULL", startPos), testCase);
} while ((useSPS = !useSPS) && (setMax = !setMax));
}

/**
* Test fix for Issue #450. BatchUpdateException.getUpdateCounts() should return EXECUTE_FAILED status when an error
* occurs while executing a batch statement.
*
* @throws Exception
*/
@Test
public void testBugIssue450() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), "true");
this.conn = getConnectionWithProps(props);
Statement stmt = this.conn.createStatement();

String tableName = "testBugIssue450";

createTable(tableName, "(c0 INT PRIMARY KEY NOT NULL)");

stmt.execute("INSERT INTO " + tableName + " VALUES (1)");

Statement bstmt = conn.createStatement();
bstmt.addBatch("INSERT INTO " + tableName + " VALUES (1)");
bstmt.addBatch("INSERT INTO " + tableName + " VALUES (2)");
try {
bstmt.executeBatch();
} catch (BatchUpdateException e) {
int[] res = e.getUpdateCounts();
for (int r : res) {
assertEquals(Statement.EXECUTE_FAILED, r);
}
}
}
}

0 comments on commit 317b53d

Please sign in to comment.