Skip to content

fix: one rowcount per result, each its own, in the server's order - #503

Merged
TimelordUK merged 2 commits into
masterfrom
fix/rowcount-per-result
Oct 25, 2026
Merged

TimelordUK merged 2 commits into
masterfrom
fix/rowcount-per-result

Conversation

@TimelordUK

Copy link
Copy Markdown
Owner

Events now follow the server's order, and every result the server reports raises one rowcount with its own count. A result with no count gives 0.

What the server reports. I checked with raw ODBC, reading SQLRowCount after each SQLMoreResults:

  • A PRINT (or a raiserror below severity 11) is a result of its own, with no count.
  • DDL, declare and set inside a batch aren't results at all, so they leave no trace.

Fixed in lib/reader.js:

  • A PRINT repeated the previous result's count. insert; print gave rowcount 1, rowcount 1. It now gives rowcount 1, info p1, rowcount 0.
  • The next result's info, and a mid-batch error, were emitted before the previous result's rowcount and callback. They now come after.
  • When an error ended the batch after a result (select 1; throw ...), that result's callback was never called. It's now called first with more=true, then the error with more=false.
  • A cancel still ends the query at once: cancel-cb, HY008, done, free.
batch before after
insert; print info, rowcount 1, rowcount 1 rowcount 1, info, rowcount 0
insert 2; create; drop; update 2; print; delete 2 2, info, 2, 2, 2 2, 2, info, 0, 2
callback: select 1; raiserror(16); select 2 error, ok 1, ok 0, ok 1 ok 1, error, ok 0, ok 1
callback: select 1; throw error ok 1 (more), error

Behaviour change for the release notes: when a callback query's batch fails after a result, the callback is now called for that result first. node-mssql adds every rowcount to rowsAffected, so insert; print now gives [1, 0] there, where it gave [1, 1].

Tests

  • 37 corpus transcripts updated. Six are agreed ones that change only as the new contract says: errors/dup-key-b/c/d, print-then-raiserror, raiserror-after-result, throw-ends-batch, queue/error-after-result-* and scripts/issue-481.
  • The Linux pins needed no change: none of them has a result before its error.
  • New unit tests: compoundqueries.test.js, "rowcount per result" (9 tests; 4 fail on master).
  • The ODBC errors not bubbling up when PRINT + THROW are used. #396 tests in multiple-errors.test.js now read to the last callback.
  • Locally (Windows, ODBC 18):

🤖 Generated with Claude Code

TimelordUK and others added 2 commits October 25, 2026 10:59
A PRINT is a result of its own with no count, but it repeated the previous
result's count (insert; print gave rowcount 1 twice). Info and mid-batch errors
were emitted before the previous result's rowcount and callback, and when an
error ended the batch after a result, that result's callback was never called.

What comes with a result is now held on it until the result before is complete.
A result with no count (PRINT, a lone DDL statement) reports 0. In callback mode
the next result waits a tick for the previous result's callback. A cancel still
ends the query at once.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… (Linux keeps them)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@TimelordUK
TimelordUK merged commit 3d653a0 into master Oct 25, 2026
11 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.

1 participant