sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Returning zero from user-defined function treated as returning null

Open AnyhowStep opened this issue 6 years ago • 4 comments

db = new Database();
db.create_function(
    "returnZero",
    () => 0
);
db.exec("SELECT returnZero(), 0");

Expected:

returnZero() 0
0 0

Actual:

returnZero() 0
null 0

AnyhowStep avatar Sep 20 '19 17:09 AnyhowStep

Tracked the bug down to this line of code. image

AnyhowStep avatar Sep 20 '19 20:09 AnyhowStep

!0 is true.

So, it thinks 0 is null

AnyhowStep avatar Sep 20 '19 20:09 AnyhowStep

https://github.com/kripken/sql.js/blob/master/dist/sql-wasm-debug.js#L764-L767

AnyhowStep avatar Sep 20 '19 20:09 AnyhowStep

https://github.com/kripken/sql.js/blob/master/src/api.coffee#L484-L495

Seems like it was fixed recently, but no npm package was published, and the dist was not updated.

AnyhowStep avatar Sep 20 '19 20:09 AnyhowStep