Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,7 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {

Local<Function> conflictFunc;
Local<Function> filterFunc;
bool filterCallbackFailed = false;
if (args.Length() > 1 && !args[1]->IsUndefined()) {
if (!args[1]->IsObject()) {
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
Expand Down Expand Up @@ -2338,25 +2339,25 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {

filterFunc = filterValue.As<Function>();

context.filterCallback =
[env, db, &filterFunc](std::string_view item) -> bool {
context.filterCallback = [env, &filterFunc, &filterCallbackFailed](
std::string_view item) -> bool {
// If there was an error in the previous call to the filter's
// callback, we skip calling it again.
if (db->ignore_next_sqlite_error_) {
if (filterCallbackFailed) {
return false;
}

Local<Value> argv[1];
if (!ToV8Value(env->context(), item, env->isolate())
.ToLocal(&argv[0])) {
db->SetIgnoreNextSQLiteError(true);
filterCallbackFailed = true;
return false;
}

Local<Value> result;
if (!filterFunc->Call(env->context(), Null(env->isolate()), 1, argv)
.ToLocal(&result)) {
db->SetIgnoreNextSQLiteError(true);
filterCallbackFailed = true;
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-sqlite-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ test('filter handler throws', (t) => {
name: 'Error',
message: 'Error filtering table data1'
});

t.assert.throws(() => {
database2.exec('CREATE TABLEEEE');
}, {
code: 'ERR_SQLITE_ERROR',
message: /syntax error/,
});
});

test('database.createSession() - filter changes', (t) => {
Expand Down
Loading