Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database.open: callback not called if mode is undefined #1697

Open
tguichaoua opened this issue Apr 10, 2023 · 1 comment
Open

Database.open: callback not called if mode is undefined #1697

tguichaoua opened this issue Apr 10, 2023 · 1 comment
Labels

Comments

@tguichaoua
Copy link

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 tguichaoua added the bug label Apr 10, 2023
@tguichaoua tguichaoua changed the title open not called if mode is undefined Database.open: callback not called if mode is undefined Apr 10, 2023
@tguichaoua
Copy link
Author

unsigned int pos = 1;
int mode;
if (info.Length() >= pos && info[pos].IsNumber() && OtherIsInt(info[pos].As<Napi::Number>())) {
mode = info[pos++].As<Napi::Number>().Int32Value();
}
else {
mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
}
Napi::Function callback;
if (info.Length() >= pos && info[pos].IsFunction()) {
callback = info[pos++].As<Napi::Function>();
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant