Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,8 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
buf.data(),
static_cast<sqlite3_uint64>(buf.length()),
SQLITE_TRANSIENT);
} else if (value->IsUndefined()) {
r = sqlite3_bind_null(statement_, index);
} else if (value->IsBigInt()) {
bool lossless;
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless);
Expand Down
21 changes: 20 additions & 1 deletion test/parallel/test-sqlite-data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ suite('data binding and mapping', () => {
stmt.run(4, 99n, 0xf, '', new Uint8Array()),
{ changes: 1, lastInsertRowid: 4 },
);
t.assert.deepStrictEqual(
stmt.run(5, undefined, undefined, undefined, undefined),
{ changes: 1, lastInsertRowid: 5 },
);

const query = db.prepare('SELECT * FROM types WHERE key = ?');
t.assert.deepStrictEqual(query.get(1), {
Expand Down Expand Up @@ -80,6 +84,22 @@ suite('data binding and mapping', () => {
text: '',
buf: new Uint8Array(),
});
t.assert.deepStrictEqual(query.get(5), {
__proto__: null,
key: 5,
int: null,
double: null,
text: null,
buf: null,
});

const insertNamed = db.prepare('INSERT INTO types VALUES ($key, $int, $double, $text, $buf)');
const params = { int: undefined, double: undefined, text: undefined, buf: undefined };
const nulls = { int: null, double: null, text: null, buf: null };
t.assert.deepStrictEqual(insertNamed.run({ key: 6, ...params }), { changes: 1, lastInsertRowid: 6 });
t.assert.deepStrictEqual(insertNamed.run({ key: 7 }), { changes: 1, lastInsertRowid: 7 });
t.assert.deepStrictEqual(query.get(6), { __proto__: null, key: 6, ...nulls });
t.assert.deepStrictEqual(query.get(7), { __proto__: null, key: 7, ...nulls });
});

test('large strings are bound correctly', (t) => {
Expand Down Expand Up @@ -126,7 +146,6 @@ suite('data binding and mapping', () => {
t.assert.strictEqual(setup, undefined);

[
undefined,
() => {},
Symbol(),
/foo/,
Expand Down