node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

`Database.open`: callback not called if `mode` is undefined

Open tguichaoua opened this issue 2 years ago • 1 comments

Issue Summary

In the code bellow if mode is set to undefined the callback is never called. I expected that both code are equivalent.

  const db = new sqlite3.Database(":memory:", undefined, () => {
    console.log("1"); // not called
  });
  const db2 = new sqlite3.Database(":memory:", () => {
    console.log("2"); // called
  });

Steps to Reproduce

See summary

Version

5.1.6

Node.js Version

18.15.0

How did you install the library?

npm

tguichaoua avatar Apr 10 '23 19:04 tguichaoua

https://github.com/TryGhost/node-sqlite3/blob/8598a9dc11322881fc0da58bba463ad0d3cd0613/src/database.cc#L130-L143

In the code, if the second argument is pressent but not a number (e.g. undefined) pos is not incremented. So it try to read the second argument as the callback function, but because it is undefined, callback is not set.

tguichaoua avatar Apr 11 '23 08:04 tguichaoua