-
Notifications
You must be signed in to change notification settings - Fork 459
Fix Statement.execute() skipping update count after batch statement error #2866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+334
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
6bc7a9b to
85cb379
Compare
306e864 to
f1c4d37
Compare
machavan
approved these changes
Dec 31, 2025
Ananya2
approved these changes
Jan 2, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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:
The test fails with the previous behavior and passes with this fix applied.