Repository navigation
feat: read and write decimal, numeric and money values exactly as strings - #1839
colinhacks wants to merge 3 commits into
Conversation
| done(); | ||
| } | ||
| }); | ||
|
|
There was a problem hiding this comment.
Could we make this table-driven, with each SQL expression beside its expected value and a named test for each case? Something like it.each, using Mocha’s existing loop-based pattern here. That would be easier to follow than matching 15 selected columns to a separate expected array.
There was a problem hiding this comment.
Good call, done in 08b0877. The cases go through the file's testDataType loop now, one named test each.
|
Hi @colinhacks Thanks for working on this! We’re developing SQL Server support for Prisma 8 and need lossless Decimal/Numeric parameters and results. We’d prefer to coordinate here rather than submit an overlapping implementation. Our intended usage is to validate decimal strings against the declared precision/scale before passing them to Tedious, and enable decimalAsString for results. That would let us reject values requiring rounding without changing Tedious’s existing compatibility behavior. Does this fit the intended public contract? Two areas would be particularly helpful to confirm:
One small testing suggestion: assert the expected row/output-event count at completion, so a missing event cannot leave the value assertions unexecuted. Happy to help validate the relevant cases against SQL Server 2022/2025. Please let us know what would be useful. |
|
Yes, that's the intended contract. A decimal string is written exactly, Strings go through the same writer for The overflow check is the one already on master, by storage width, so Also took the test suggestion, the helpers now assert the row and output-value counts at completion. |
Hi @colinhacks Thanks for clarifying and adding the integration tests and completion-count assertions, that addresses my questions. The contract works for our intended Prisma integration. We’ll pass exact decimal strings, enable We’ll track this PR and validate the released implementation against our SQL Server cases before enabling support. Thanks for moving this forward! |
|
Should we just make this a breaking change? Options like |
I agree that exact values by default would be cleaner and safer. Users shouldn’t need to discover an option to avoid losing digits. The main benefit of I’d support making this a breaking change with clear migration guidance. It would also help to clarify the write behavior separately, whether number inputs remain accepted and whether values with too many fractional digits are rounded or rejected. Happy to help test the agreed behavior against SQL Server. Thanks for considering this! |
|
Agreed it should be the default. I'd still ship it as an option first though, so it can go out in a minor instead of waiting on the next major, then make it the default and drop the option in that major. Happy to do that PR as well. |
Adds a
decimalAsStringconnection option for reading, and writes decimal strings exactly.decimalAsString: true,decimal,numeric,moneyandsmallmoneyvalues,sql_variantones included, come back as strings that hold the exact value, with as many fractional digits as the type's scale:'1.50'for adecimal(10, 2),'1.5000'for amoney. The default stays a number.Decimal,Numeric,MoneyorSmallMoneyparameter given a decimal string such as'-12.50'is encoded from its digits instead of throughparseFloat, rounding half away from zero to the scale as SQL Server does. Today'12345678901234567.123456789'bound asDecimal(38, 9)is stored as12345678901234568.244756480.Numbers keep the current path, and so do strings in exponent form:
mssql's batch mode writes a string parameter into the batch asN'…', and SQL Server doesn't convertN'1e5'todecimal.One visible change:
validateon these four types returns a decimal string as a string (trimmed) instead of a number, which the tests invalidations-test.tsnow expect.Tested on SQL Server 2019, 2022 and 2025 on Linux with the integration suite, and through
mssql12.7.14, which passesconfig.optionsto tedious as they are.Closes #163
Refs #760, #1675, #678