-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value out of bounds for Numeric types #474
Comments
Because that's what the TDS protocol mandates for Numeric values. For Line 519 in 3cb8586
...
buffer.writeUInt64LE(value); // 8 bytes
buffer.writeUInt32LE(0x00000000); // 4 bytes
buffer.writeUInt32LE(0x00000000); // 4 bytes The first line is the one with the problem. https://github.com/tediousjs/tedious/blob/master/src/tracking-buffer/writable-tracking-buffer.js#L125 writeUInt64LE(value) {
this.writeInt32LE(value & -1);
return this.writeUInt32LE(Math.floor(value * SHIFT_RIGHT_32));
} The 32 bit right shift is where the problem seems to manifest itself. Now I see that the problem is that 66666550000000000000 is 0x39d2f2a02aed16000, which requires more than 64 bits. But this raises the issue that not all integers with more than 53 bits can be correctly represented in JavaScripts' Number type. To handle this correctly may require some head scratching, and some new unit tests. |
As a workaround, using a smaller scale would probably work. |
@pekim Thanks for answering my question and providing the information! I decided to write it in Python instead of Node.js to move forward. I'll still be using this library for other work, but it won't involve numeric types. Hopefully a solution can be found so no one else runs into this issue. |
In my case, I had to use a different workaround since the const value_stored = value.toFixed(desired_precision); This is so that you don't lose precision but also don't choke up anything in between my code and the DB that makes assumptions about scale and magnitude that I'm not aware of or control. Of course, this is less bandwidth efficient than using the correct type but in my case <30 byte per record penalty is insignificant. |
That solved the issue for me as well. Is there a way to apply this globally so everytime sequelize tries to insert/update a decimal value it calls .toFixed(2)? |
I'm running into an issue where a valid numerical value is blocking my insert statement with tedious. A manual SQL insert into the database with the same numerical value works.
Manual SQL Insert:
Here's my code:
The tedious code seems to convert 66666.55 to an integer with a value of 66666550000000000000. It then tries to take the remainder and quotient of that value and write it to a buffer using writeUInt32LE.
Why is the tedious code converting floating point numbers to integers and writing them to buffers instead of keeping the floating point number and using the built-in function writeDoubleLE for buffers?
This issue is blocking me from moving forward.
The text was updated successfully, but these errors were encountered: