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 56.56%. Comparing base (c26c8c4) to head (6bc7a9b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2866      +/-   ##
============================================
+ Coverage     56.41%   56.56%   +0.15%     
- Complexity     4555     4582      +27     
============================================
  Files           151      151              
  Lines         34560    34560              
  Branches       5768     5768              
============================================
+ Hits          19497    19549      +52     
+ Misses        12425    12408      -17     
+ Partials       2638     2603      -35     

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

Updated tvpTypeName to use RandomUtil for identifier generation and ensured proper escaping in SQL statements.
@muskan124947
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

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.

2 participants