dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

±Infinity are replaced with -9223372036854775808 #89

Closed jeremyBanks closed 3 years ago

jeremyBanks commented 3 years ago

👋 Hello! Thank you for the very useful library. I have a bug report.

SQLite's REAL values are IEEE floating point numbers, and although they do not support NaNs, they do support infinities. An easy way to produce them is with overflowing float literals:

#!/usr/bin/env -S deno run
import { DB } from "https://deno.land/x/sqlite@v2.3.0/mod.ts";
const db = new DB();

for (const sqlValue of ['1e34567', '-1e34567']) {
  const [[result]] = db.query(`SELECT ${sqlValue}`);
  console.log(sqlValue, '->', result);
}
1e34567 -> Infinity
-1e34567 -> -Infinity

This library returns ±Infinity values from SQLite correctly. However, when passing them to SQLite, they are converted to the value -9223372036854775808.

for (const jsValue of [1e34567, -1e34567]) {
  const [[result]] = db.query("SELECT ?", [jsValue]);
  console.log(jsValue, '->', result);
}
Infinity -> -9223372036854775808n
-Infinity -> -9223372036854775808n
dyedgreen commented 3 years ago

Hi @jeremyBanks thank you for reporting this, this definitely looks like something which should be addressed.

I’ll have a look at this later 😀

jeremyBanks commented 3 years ago

I hope to have a potential fix PR for your consideration today. 🤞