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

src: allow unknown sqlite parameters #55931

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 1 addition & 3 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,7 @@ bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) {
}

if (r == 0) {
THROW_ERR_INVALID_STATE(
env(), "Unknown named parameter '%s'", *utf8_key);
return false;
continue;
}
}

Expand Down
13 changes: 6 additions & 7 deletions test/parallel/test-sqlite-named-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ function nextDb() {
}

suite('named parameters', () => {
test('throws on unknown named parameters', (t) => {
test('unknown named parameters are supported', (t) => {
const db = new DatabaseSync(nextDb());
t.after(() => { db.close(); });
const setup = db.exec(
'CREATE TABLE types(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'
);
t.assert.strictEqual(setup, undefined);

t.assert.throws(() => {
const stmt = db.prepare('INSERT INTO types (key, val) VALUES ($k, $v)');
stmt.run({ $k: 1, $unknown: 1 });
}, {
code: 'ERR_INVALID_STATE',
message: /Unknown named parameter '\$unknown'/,
const stmt = db.prepare('INSERT INTO types (key, val) VALUES ($k, $v)');
t.assert.deepStrictEqual(stmt.run({ $k: 1, $unknown: 1, $v: 1 }, true),
{
changes: 1,
lastInsertRowid: 1,
});
});

Expand Down
Loading