CraZySacX / node-jdbc

JDBC Wrapper for node.js
140 stars 106 forks source link

bigints are mapped from the database back to Js as strings #164

Closed juvation closed 6 years ago

juvation commented 6 years ago

i was getting some odd behaviour for bigint columns so i took a look in resultset.js and found this curious mapping --

typeNames[java.getStaticFieldValue("java.sql.Types", "BIGINT")] = "String";

i changed it to "Double" in my local copy and all was well. probably should be mapped to something numeric.

CraZySacX commented 6 years ago

This was done on purpose.

Long is the correct type for mapping to Java but JavaScript integer max is 2^53-1, so with the latest change it is now truncating the result. See the java node module README.md section on java.lang.Long.

For BIGINT I recommend using String as the default type in rs objects as that is what will work in JavaScript without truncation.

Double will work, but for values greater than 2^53 - 1, you will lose precision. String was chosen because this can easily be passed into the various javascript biginteger libraries if you actually have to do math with the value after it is retrieved.