Enable returning `SQL_DOUBLE` type as a JS Number
abmusse opened this issue · comments
Describe the solution you'd like
Enable returning SQL_DOUBLE
type as a JS Number
instead of a JS String
if dbstmt.asNumber(true)
is set.
Contiuation of #64
Currently only SQL_INTEGER
, SQL_SMALLINT
, SQL_DECIMAL
, and SQL_NUMERIC
types will be returned as JS Number when dbstmt.asNumber(true)
is set.
Additional context
According to the docs:
Floating-point
A single-precision floating-point number is a 32-bit approximate representation
of a real number. The range of magnitude is approximately
1.17549436 × 10-38 to 3.40282356 × 1038.
A double-precision floating-point number is a IEEE 64-bit approximate representation
of a real number. The range of magnitude is approximately
2.2250738585072014 × 10^-308 to 1.7976931348623158 × 10^308.
Single-precision floating-point is generally accurate to 7 digits of precision.
Double-precision floating-point is generally accurate to 15 digits of precision.
JavaScript Number has the following min and max values:
Number.MAX_VALUE = 1.7976931348623157e+308
Number.MIN_VALUE = 5e-324
Seems like the JS Number Class will be able to hold the SQL_DOUBLE
type.
We can probably just add a case for SQL_DOUBLE
here
@dmabupt @kadler @markdirish @ThePrez Do you think this would work?
idb-connector v1.2.5 is released to fix this issue.
Nice!
I think we should also add test cases selecting and fetching Min and Max values for DOUBLE, FLOAT, REAL
types to confirm the behavior. Similar to how we have done here.
Note that precision and scale returned for REAL
and DOUBLE
columns is not the same as for DECIMAL
/NUMERIC
columns. It does not contain the number of digits, but instead precision will be either 4 (REAL
) or 8 (DOUBLE
), which is the size in bytes that it takes up.
Code like this is not correct
nodejs-idb-connector/src/db2ia/dbstmt.cc
Lines 2099 to 2103 in 1b4d8d1
nodejs-idb-connector/src/db2ia/dbstmt.cc
Lines 2269 to 2272 in 1b4d8d1