fix: crash after closing the database
This commit is contained in:
parent
d2364faa35
commit
b4d9e35023
11
src/addon.cc
11
src/addon.cc
@ -398,6 +398,9 @@ Napi::Value Statement::Close(const Napi::CallbackInfo& info) {
|
||||
auto env = info.Env();
|
||||
|
||||
auto stmt = FromExternal(info[0]);
|
||||
if (stmt == nullptr) {
|
||||
return Napi::Value();
|
||||
}
|
||||
|
||||
int r = sqlite3_finalize(stmt->handle_);
|
||||
if (r != SQLITE_OK) {
|
||||
@ -413,6 +416,10 @@ Napi::Value Statement::Run(const Napi::CallbackInfo& info) {
|
||||
auto env = info.Env();
|
||||
|
||||
auto stmt = FromExternal(info[0]);
|
||||
if (stmt == nullptr) {
|
||||
return Napi::Value();
|
||||
}
|
||||
|
||||
auto params = info[1];
|
||||
auto result = info[2].As<Napi::Array>();
|
||||
|
||||
@ -451,6 +458,10 @@ Napi::Value Statement::Step(const Napi::CallbackInfo& info) {
|
||||
auto env = info.Env();
|
||||
|
||||
auto stmt = FromExternal(info[0]);
|
||||
if (stmt == nullptr) {
|
||||
return Napi::Value();
|
||||
}
|
||||
|
||||
auto params = info[1];
|
||||
auto cache = info[2];
|
||||
auto is_get = info[3].As<Napi::Boolean>();
|
||||
|
||||
@ -49,6 +49,16 @@ test('db.close', () => {
|
||||
db = new Database();
|
||||
});
|
||||
|
||||
test('db.close with existing statement', () => {
|
||||
const stmt = db.prepare('SELECT 1');
|
||||
db.close();
|
||||
|
||||
expect(() => stmt.run()).toThrowError('Statement closed');
|
||||
|
||||
// Just to fix afterEach
|
||||
db = new Database();
|
||||
});
|
||||
|
||||
test('statement.close', () => {
|
||||
const stmt = db.prepare('SELECT 1');
|
||||
stmt.close();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user