mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
sqlite: handle ?NNN parameters as positional
PR-URL: https://github.com/nodejs/node/pull/59350 Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
This commit is contained in:
parent
b85e77bf27
commit
3c1521cfa0
|
|
@ -1941,7 +1941,9 @@ bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) {
|
|||
}
|
||||
|
||||
for (int i = anon_start; i < args.Length(); ++i) {
|
||||
while (sqlite3_bind_parameter_name(statement_, anon_idx) != nullptr) {
|
||||
while (1) {
|
||||
const char* param = sqlite3_bind_parameter_name(statement_, anon_idx);
|
||||
if (param == nullptr || param[0] == '?') break;
|
||||
anon_idx++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,6 +240,36 @@ suite('StatementSync.prototype.run()', () => {
|
|||
stmt.run({ k: 3, v: 30 }), { changes: 1, lastInsertRowid: 3 }
|
||||
);
|
||||
});
|
||||
|
||||
test('SQLite defaults unbound ?NNN parameters', (t) => {
|
||||
const db = new DatabaseSync(nextDb());
|
||||
t.after(() => { db.close(); });
|
||||
const setup = db.exec(
|
||||
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER NOT NULL) STRICT;'
|
||||
);
|
||||
t.assert.strictEqual(setup, undefined);
|
||||
const stmt = db.prepare('INSERT INTO data (key, val) VALUES (?1, ?3)');
|
||||
|
||||
t.assert.throws(() => {
|
||||
stmt.run(1);
|
||||
}, {
|
||||
code: 'ERR_SQLITE_ERROR',
|
||||
message: 'NOT NULL constraint failed: data.val',
|
||||
errcode: 1299,
|
||||
errstr: 'constraint failed',
|
||||
});
|
||||
});
|
||||
|
||||
test('binds ?NNN params by position', (t) => {
|
||||
const db = new DatabaseSync(nextDb());
|
||||
t.after(() => { db.close(); });
|
||||
const setup = db.exec(
|
||||
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER NOT NULL) STRICT;'
|
||||
);
|
||||
t.assert.strictEqual(setup, undefined);
|
||||
const stmt = db.prepare('INSERT INTO data (key, val) VALUES (?1, ?2)');
|
||||
t.assert.deepStrictEqual(stmt.run(1, 2), { changes: 1, lastInsertRowid: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
suite('StatementSync.prototype.sourceSQL', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user