dyedgreen / deno-sqlite

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

Strange results with bigints #122

Closed djboardman closed 3 years ago

djboardman commented 3 years ago

Hi

I've been getting some strange results with bigints when I insert them as part of a row into a sqlite table. I've tried sqllite types BigInt, Integer and Int but always the same result.

For example BigInt(-1) become -29 in sqlite And BigInt(1000000000000000000000) becomes 186471204942302412

Some bigints work fine e.g. BigInt(50000000000000000) goes in as 50000000000000000

I can't anything obvious that is different about the ones that work and the ones that don't

Thanks

dyedgreen commented 3 years ago

Thanks for spotting this @djboardman the negative case is a pretty embarrassing bug on my part 🤐

For the very big number, you’re overflowing an int64, which is what sqlite uses to represent integers; so in that case I think we should raise an error to prevent unexpected behavior like this.

djboardman commented 3 years ago

Ah, OK I was going to say that I hadn't checked the big number for overflow, I was caught in the headlights of the -1

dyedgreen commented 3 years ago

Thanks again for reporting this @djboardman 😅