Skip to content

Conversation

@muskan124947
Copy link
Contributor

@muskan124947 muskan124947 commented Dec 22, 2025

Description

When executing a mixed batch of SQL statements using Statement.execute() (e.g. INSERT → INSERT error → INSERT → SELECT), if a statement in the middle of the batch fails (such as a primary key violation) and the application catches the resulting SQLException and calls getMoreResults() to continue, the driver incorrectly skips the update count of the next valid DML statement.

As a result, the update count for a successful statement following an error is never returned, and result processing jumps directly from the error to the subsequent ResultSet. This violates expected JDBC result traversal semantics and causes applications to lose valid update counts.

This issue is tracked in : Statement.execute() skips valid update count after catching SQLException in mixed batch execution #2850

Fix

The issue was caused by incorrect handling of DONE tokens for failed statements during result traversal.
Specifically, the driver skipped DONE tokens with updateCount = -1 without checking whether the token represented an error.

The fix updates the parsing logic to not skip error DONE tokens, ensuring the parser stops at the correct error position in the TDS stream. This allows getMoreResults() to correctly advance to the next statement and expose the update count of subsequent successful DML operations.

if (-1 == doneToken.getUpdateCount() && EXECUTE_BATCH != executeMethod && !doneToken.isError())
    return true;

This change prevents valid update counts from being swallowed after an error in mixed batch execution.

Testing

Added a new test that executes a mixed SQL batch containing:

- A successful INSERT
- A failing INSERT (primary key violation)
- A subsequent successful INSERT
- A final SELECT
  • The test catches the expected exception, continues result processing using getMoreResults(), and verifies:
  • The update count of the valid INSERT following the error is returned
  • The final SELECT result set is processed correctly

The test fails with the previous behavior and passes with this fix applied.

@muskan124947 muskan124947 self-assigned this Dec 22, 2025
@muskan124947 muskan124947 added this to the 13.3.1 milestone Dec 22, 2025
@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.01%. Comparing base (ce88330) to head (309af8e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2866      +/-   ##
============================================
- Coverage     59.04%   59.01%   -0.03%     
+ Complexity     4756     4749       -7     
============================================
  Files           151      151              
  Lines         34564    34564              
  Branches       5769     5769              
============================================
- Hits          20407    20399       -8     
  Misses        11406    11406              
- Partials       2751     2759       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@muskan124947
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@muskan124947 muskan124947 force-pushed the users/muskgupta/githubIssue#2850 branch from 306e864 to f1c4d37 Compare December 30, 2025 05:24
@muskan124947 muskan124947 merged commit 0eb40a0 into main Jan 2, 2026
18 of 19 checks passed
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.

4 participants