Skip to content

fix: pass dataLength to getMssqlType in valueCorrection#1855

Merged
dhensby merged 1 commit intotediousjs:masterfrom
dhensby:fix/value-correction-length
May 4, 2026
Merged

fix: pass dataLength to getMssqlType in valueCorrection#1855
dhensby merged 1 commit intotediousjs:masterfrom
dhensby:fix/value-correction-length

Conversation

@dhensby
Copy link
Copy Markdown
Collaborator

@dhensby dhensby commented May 4, 2026

Problem

valueCorrection() calls getMssqlType(metadata.type) without passing the length argument. The getMssqlType function uses length to disambiguate nullable N-types (IntN, FloatN, MoneyN, DateTimeN) — without it, they always resolve to the smallest variant:

N-Type Expected (with length) Actual (without length)
IntN (len=8) BigInt TinyInt
IntN (len=4) Int TinyInt
IntN (len=2) SmallInt TinyInt
FloatN (len=8) Float Real
MoneyN (len=8) Money SmallMoney
DateTimeN (len=8) DateTime SmallDateTime

This means valueHandler entries registered for BigInt, Int, SmallInt, Float, Money, or DateTime are never invoked — only the smallest variant handler fires.

Note: column metadata types (via createColumns) are not affected — that call site already passes column.dataLength correctly.

Closes #1853

Fix

One-liner: pass metadata.dataLength as the second argument to getMssqlType() in valueCorrection().

Tests

Added an integration test that registers separate value handlers for BigInt, Int, and TinyInt, then queries all three types. Without the fix, only the TinyInt handler fires; with the fix, each handler fires exactly once.

valueCorrection() was calling getMssqlType() without the length argument,
causing IntN, FloatN, MoneyN and DateTimeN types to always resolve to
their smallest variant (TinyInt, Real, SmallMoney, SmallDateTime). This
meant value handlers registered for BigInt, Int, SmallInt, Float, Money,
or DateTime were never invoked.

Closes tediousjs#1853

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a driver-specific bug in the tedious implementation where valueCorrection() failed to pass dataLength into getMssqlType(), causing IntN/FloatN/MoneyN/DateTimeN values to be misclassified as their smallest variants and therefore dispatch to the wrong (or no) valueHandler.

Changes:

  • Passes metadata.dataLength to getMssqlType() in lib/tedious/request.js so N-types resolve to the correct sql.TYPES.*.
  • Adds an integration test to ensure valueHandler dispatch works correctly for BigInt, Int, and TinyInt.
  • Wires the new test into both the tedious and msnodesqlv8 integration test runners.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lib/tedious/request.js Fixes N-type disambiguation for valueHandler dispatch by providing metadata.dataLength to getMssqlType().
test/common/tests.js Adds an integration test asserting correct valueHandler routing for IntN-family integer types.
test/tedious/tedious.js Registers the new shared integration test in the tedious test suite.
test/msnodesqlv8/msnodesqlv8.js Registers the new shared integration test in the msnodesqlv8 test suite.

@dhensby dhensby merged commit 3a7e45f into tediousjs:master May 4, 2026
51 checks passed
@dhensby dhensby deleted the fix/value-correction-length branch May 4, 2026 21:30
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

🎉 This PR is included in version 12.5.1 🎉

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.

valueCorrection drops length arg, misrouting IntN/FloatN/MoneyN/DateTimeN.

2 participants