sqlite: handle ?NNN parameters as positional · nodejs/node@e2b6bdc

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', () => {