Skip to content

Fix Statement.getUpdateCount: return -1 when current result is a ResultSet#54

Open
IceboxDev wants to merge 1 commit intodbeaver:develfrom
IceboxDev:fix/getupdatecount-no-update
Open

Fix Statement.getUpdateCount: return -1 when current result is a ResultSet#54
IceboxDev wants to merge 1 commit intodbeaver:develfrom
IceboxDev:fix/getupdatecount-no-update

Conversation

@IceboxDev
Copy link
Copy Markdown

LibSqlStatement.getUpdateCount() currently returns rows_written unconditionally, including for SELECT queries where rows_written == 0.

Per the JDBC spec:

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned.

Returning 0 instead of -1 for a SELECT means "an update result with 0 rows affected" ? a different, legitimate state. Clients that walk all results via the standard pattern loop forever:

do {
    val isRs = stmt.getMoreResults()
    val n = stmt.getUpdateCount()
    if (!isRs && n == -1) break
    // ...
} while (true)

This manifests in JetBrains DataGrip / PyCharm as the query showing rows in the editor but the "loading" spinner never stopping. Eventually the RMI proxy backing the Statement is GC'd on the driver side and the IDE log fills with java.rmi.NoSuchObjectException: no such object in table from UniversalResultsProducer$StatementSource.hasMoreResultSets / getUpdateCount.

Fix:

  • getUpdateCount / getLargeUpdateCount return -1 when the current result is a ResultSet (signalled by executionResult.getColumns() being non-empty) or when there is no current result.
  • getMoreResults() (both overloads) clears executionResult and resultSet so subsequent getUpdateCount correctly returns -1 for "no more results".
  • Removed LibSqlException("No update count before statement execute") ? per spec, getUpdateCount returns -1 in that state, it does not throw.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 2 duplication

Metric Results
Complexity 4
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant