Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3478130

Browse filesBrowse files
geeksilva97richardlau
authored andcommitted
sqlite: handle ?NNN parameters as positional
PR-URL: #59350 Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
1 parent 1b4885a commit 3478130
Copy full SHA for 3478130

File tree

Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed
Open diff view settings
Collapse file

‎src/node_sqlite.cc‎

Copy file name to clipboardExpand all lines: src/node_sqlite.cc
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,9 @@ bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) {
19321932
}
19331933

19341934
for (int i = anon_start; i < args.Length(); ++i) {
1935-
while (sqlite3_bind_parameter_name(statement_, anon_idx) != nullptr) {
1935+
while (1) {
1936+
const char* param = sqlite3_bind_parameter_name(statement_, anon_idx);
1937+
if (param == nullptr || param[0] == '?') break;
19361938
anon_idx++;
19371939
}
19381940

Collapse file

‎test/parallel/test-sqlite-statement-sync.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-sqlite-statement-sync.js
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,36 @@ suite('StatementSync.prototype.run()', () => {
240240
stmt.run({ k: 3, v: 30 }), { changes: 1, lastInsertRowid: 3 }
241241
);
242242
});
243+
244+
test('SQLite defaults unbound ?NNN parameters', (t) => {
245+
const db = new DatabaseSync(nextDb());
246+
t.after(() => { db.close(); });
247+
const setup = db.exec(
248+
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER NOT NULL) STRICT;'
249+
);
250+
t.assert.strictEqual(setup, undefined);
251+
const stmt = db.prepare('INSERT INTO data (key, val) VALUES (?1, ?3)');
252+
253+
t.assert.throws(() => {
254+
stmt.run(1);
255+
}, {
256+
code: 'ERR_SQLITE_ERROR',
257+
message: 'NOT NULL constraint failed: data.val',
258+
errcode: 1299,
259+
errstr: 'constraint failed',
260+
});
261+
});
262+
263+
test('binds ?NNN params by position', (t) => {
264+
const db = new DatabaseSync(nextDb());
265+
t.after(() => { db.close(); });
266+
const setup = db.exec(
267+
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER NOT NULL) STRICT;'
268+
);
269+
t.assert.strictEqual(setup, undefined);
270+
const stmt = db.prepare('INSERT INTO data (key, val) VALUES (?1, ?2)');
271+
t.assert.deepStrictEqual(stmt.run(1, 2), { changes: 1, lastInsertRowid: 1 });
272+
});
243273
});
244274

245275
suite('StatementSync.prototype.sourceSQL', () => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.