Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-385] stored procedure call getUpdateCount() regression
  • Loading branch information
rusher committed Nov 6, 2016
1 parent a4eeb01 commit 6190081
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/mariadb/jdbc/MariaDbStatement.java
Expand Up @@ -832,13 +832,13 @@ public ResultSet getResultSet() throws SQLException {
* @throws SQLException if a database access error occurs or this method is called on a closed Statement
*/
public int getUpdateCount() throws SQLException {
if (executionResult == null) {
if (executionResult == null || executionResult.getResultSet() != null) {
return -1; /* Result comes from SELECT , or there are no more results */
}
if (executionResult.isSingleExecutionResult()) {
return (int) ((SingleExecutionResult) executionResult).getAffectedRows();
} else {
return ((MultiExecutionResult) executionResult).getFirstAffectedRows();
return executionResult.getFirstAffectedRows();
}
}

Expand Down
29 changes: 28 additions & 1 deletion src/test/java/org/mariadb/jdbc/DriverTest.java
Expand Up @@ -751,12 +751,39 @@ public void testAutocommit() throws SQLException {
}

@Test
public void testUpdateCount() throws SQLException {
public void testUpdateCountSingle() throws SQLException {
Statement stmt = sharedConnection.createStatement();
stmt.execute("select 1");
assertTrue(-1 == stmt.getUpdateCount());
}

@Test
public void testUpdateCountMulti() throws SQLException {
try (Connection connection = setConnection("&allowMultiQueries=true")) {
Statement stmt = connection.createStatement();
stmt.execute("select 1;select 1");
assertTrue(-1 == stmt.getUpdateCount());
stmt.getMoreResults();
assertTrue(-1 == stmt.getUpdateCount());
}
}

/**
* CONJ-385 - stored procedure update count regression.
*
* @throws SQLException if connection error occur.
*/
@Test
public void testUpdateCountProcedure() throws SQLException {
createProcedure("multiUpdateCount", "() BEGIN SELECT 1; SELECT 2; END");
CallableStatement callableStatement = sharedConnection.prepareCall("{call multiUpdateCount()}");
callableStatement.execute();
assertTrue(-1 == callableStatement.getUpdateCount());
callableStatement.getMoreResults();
assertTrue(-1 == callableStatement.getUpdateCount());
}


@Test
public void testConnectWithDb() throws SQLException {
requireMinimumVersion(5, 0);
Expand Down

0 comments on commit 6190081

Please sign in to comment.