Skip to content

fix: send a null binary value to msnodesqlv8 as a varbinary null - #1995

Merged
dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:claude/unruffled-bardeen-79a579
Dec 2, 2026
Merged

dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:claude/unruffled-bardeen-79a579

Conversation

@dhensby

@dhensby dhensby commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

What this does:

Since msnodesqlv8 6.3.0 was published on 2026-11-28, the "Run msnodesqlv8 v6 tests" step fails the binary data test on every PR. A null sql.Binary input comes back as <Buffer 00 00 00 00>, not null.

The cause is in the msnodesqlv8 request. It sent a null Binary, VarBinary or Image value as an empty Buffer. That worked only because msnodesqlv8 before 6.3.0 sent an empty Buffer as NULL: the Buffer had no data pointer, and ODBC reads a null pointer as NULL. msnodesqlv8 6.3.0 fixed that (TimelordUK/node-sqlserver-v8#533), so it now sends an empty Buffer as an empty value. The server pads an empty value with zeros in a binary(n), and keeps it empty in a varbinary or an image.

The request cannot send a bare null instead. msnodesqlv8 binds a bare null as a char, and the server rejects that for a binary type with error 257 ("Implicit conversion from data type char to binary is not allowed").

The request now binds a null binary value as msnodesql.VarBinary(null). Every msnodesqlv8 version from 2.4.8 to 6.3.0 exports VarBinary, and binds it as a typed varbinary NULL (varbinary(max) before 6.3.0, varbinary(1) from 6.3.0). The server converts a varbinary NULL to binary, varbinary and image.

input tedious msnodesqlv8 < 6.3.0, master msnodesqlv8 6.3.0, master this branch, every version
sql.Binary(4), null null null <Buffer 00 00 00 00> null
sql.VarBinary, null null null <Buffer > null
sql.Image, null null null <Buffer > null

An empty Buffer that the caller gives still goes to msnodesqlv8 as an empty Buffer. msnodesqlv8 6.3.0 sends it as an empty value, as tedious does. Earlier versions send it as NULL. This change does not affect that.

Evidence:

  • I stubbed msnodesqlv8 and captured the SQL and values that the request gives queryRaw for the binary data test. Then I replayed them through tedious on SQL Server, with each value bound as msnodesqlv8 6.2.2 or 6.3.0 binds it (from the driver source).
    • On master, the 6.3.0 replay gives in2 = 00000000, in4 = empty and in6 = empty. The 6.2.2 replay gives null for all three.
    • With this branch, both replays give null for all three.
  • On master, in4 and in6 also fail on 6.3.0. The test stops at in2, so CI shows only that one.

Tests:

  • Unit (msnodesqlv8 query events harness): a null Binary, VarBinary and Image input is bound as VarBinary(null), and an empty Buffer is bound as an empty Buffer. The first test fails on master.
  • The existing binary data integration test covers the server side. It fails on master with msnodesqlv8 6.3.0. CI runs it here on msnodesqlv8 2 to 6.
  • Locally, npm run lint and npm run test-unit (576 passing) pass.

Related issues:

This failure shows on #1992 and on the Dependabot PRs opened since 2026-11-28. It needs no pin of msnodesqlv8: master keeps ^6.

Pre/Post merge checklist:

  • Update change log

🤖 Generated with Claude Code

The msnodesqlv8 request sent a null Binary, VarBinary or Image value
as an empty Buffer. msnodesqlv8 binds a bare null as a char, and the
server does not convert a char to a binary type. msnodesqlv8 before
6.3.0 sent an empty Buffer as NULL, so the empty Buffer worked as a
NULL.

msnodesqlv8 6.3.0 sends an empty Buffer as an empty value. A null
input then arrived as zeros in a binary(n), and as an empty value in
a varbinary or an image.

The request now binds a null binary value as msnodesqlv8's
VarBinary(null). Every supported version of msnodesqlv8 sends that as
a varbinary NULL, which the server converts to binary, varbinary and
image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhensby
dhensby marked this pull request as ready for review December 2, 2026 10:26
@dhensby
dhensby merged commit 2056090 into tediousjs:master Dec 2, 2026
93 of 94 checks passed
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 12.8.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant