Closed
Description
Version
all
Platform
all
Subsystem
sqlite
What steps will reproduce the bug?
IMO, there is an issue with SQLite's behavior, as highlighted by the current test (https://github.com/nodejs/node/blob/main/test/parallel/test-sqlite-named-parameters.js#L17-L32):
test('throws on unknown named parameters', (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'/,
});
});
How often does it reproduce? Is there a required condition?
NA
What is the expected behavior? Why is that the expected behavior?
IMO, as mentioned earlier here, it should be permissible to set more parameters (such as the $unknown
parameter of this test) than those actually used in the SQL string.
This approach is utilized by better-sqlite3 and is particularly useful when conditionally constructing your WHERE clause with parameters that may or may not be used in the final query.
The code and the associated error test should be modified to throw an error regarding the $v
named parameter instead, similar to the behavior of better-sqlite3.
What do you see instead?
NA
Additional information
No response