sqlite: bind undefined to NULL

Omitting a named parameter binds NULL, but passing `undefined` for that
same parameter threw ERR_INVALID_ARG_TYPE. Bind `undefined` to NULL so
the two forms agree. This matches the conversion already applied to a
user-defined function's `undefined` return value, as well as SQLite's
own WASM oo1 API.

Fixes: https://github.com/nodejs/node/issues/61824
Refs: https://github.com/nodejs/node/pull/61472
Refs: https://github.com/nodejs/node/pull/62008
Co-authored-by: mike-git374 <217764531+mike-git374@users.noreply.github.com>
Assisted-by: claude:opus-5
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65709
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Trevor Burnhamandmike-git374 authored and GitHub committed 2026-09-08 15:50:32 +00:00
1 parent 345074e360
commit 41cb09f8a5
3 files changed
+117 -12

No files matched your search

+3 -2
View File
@@ -3158,7 +3158,8 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
// Dates could be supported by converting them to numbers. However, there
// would not be a good way to read the values back from SQLite with the
// original type. JS Boolean binds to 1 and 0 because SQLite maps true and
// false keywords to 1 and 0.
// false keywords to 1 and 0. JS undefined binds to NULL so that passing it
// explicitly matches omitting the parameter altogether.
Isolate* isolate = env()->isolate();
int r;
if (value->IsNumber()) {
@@ -3182,7 +3183,7 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
SQLITE_TRANSIENT,
SQLITE_UTF8);
}
} else if (value->IsNull()) {
} else if (value->IsNullOrUndefined()) {
r = sqlite3_bind_null(statement_.get(), index);
} else if (value->IsArrayBufferView() || value->IsArrayBuffer() ||
value->IsSharedArrayBuffer()) {