From 2d62a373eb158c0c3f4aaa430d4869b8aac31ce0 Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Wed, 25 Feb 2026 18:25:05 -0700 Subject: [PATCH 1/3] sqlite: bind Boolean --- src/node_sqlite.cc | 8 +++++++- test/parallel/test-sqlite-data-types.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index fb229e19fd6aef..ce75470ca2a71c 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2257,7 +2257,7 @@ bool StatementSync::BindParams(const FunctionCallbackInfo& args) { bool StatementSync::BindValue(const Local& value, const int index) { // SQLite only supports a subset of JavaScript types. Some JS types such as - // functions don't make sense to support. Other JS types such as booleans and + // functions don't make sense to support. Other JS types such as // 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. @@ -2293,6 +2293,12 @@ bool StatementSync::BindValue(const Local& value, const int index) { buf.data(), static_cast(buf.length()), SQLITE_TRANSIENT); + } else if (value->IsBoolean()) { + if (value->IsTrue()) { + r = sqlite3_bind_int(statement_, index, 1); + } else { + r = sqlite3_bind_int(statement_, index, 0); + } } else if (value->IsBigInt()) { bool lossless; int64_t as_int = value.As()->Int64Value(&lossless); diff --git a/test/parallel/test-sqlite-data-types.js b/test/parallel/test-sqlite-data-types.js index 26af15a777d234..90bd84d4c6f9e5 100644 --- a/test/parallel/test-sqlite-data-types.js +++ b/test/parallel/test-sqlite-data-types.js @@ -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, true, false, true, null), + { changes: 1, lastInsertRowid: 5 }, + ); const query = db.prepare('SELECT * FROM types WHERE key = ?'); t.assert.deepStrictEqual(query.get(1), { @@ -80,6 +84,14 @@ suite('data binding and mapping', () => { text: '', buf: new Uint8Array(), }); + t.assert.deepStrictEqual(query.get(5), { + __proto__: null, + key: 5, + int: 1, + double: 0, + text: '1', + buf: null, + }); }); test('large strings are bound correctly', (t) => { From ecd3d0c895b704a84ddcfb2dd0e34f71b3ad67fc Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:11:07 -0700 Subject: [PATCH 2/3] Simplify --- src/node_sqlite.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index ce75470ca2a71c..1e265f087acbeb 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2294,11 +2294,7 @@ bool StatementSync::BindValue(const Local& value, const int index) { static_cast(buf.length()), SQLITE_TRANSIENT); } else if (value->IsBoolean()) { - if (value->IsTrue()) { - r = sqlite3_bind_int(statement_, index, 1); - } else { - r = sqlite3_bind_int(statement_, index, 0); - } + r = sqlite3_bind_int(statement_, index, value->IsTrue() ? 1 : 0); } else if (value->IsBigInt()) { bool lossless; int64_t as_int = value.As()->Int64Value(&lossless); From 7e8f43d1dff6fc66aa6ed42b271dfe6f8a19c9c8 Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Thu, 26 Feb 2026 07:03:46 -0700 Subject: [PATCH 3/3] Update comment --- src/node_sqlite.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 1e265f087acbeb..4d24b998d0aec5 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2260,7 +2260,8 @@ bool StatementSync::BindValue(const Local& value, const int index) { // functions don't make sense to support. Other JS types such as // 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. + // original type. We make an exception for JS Boolean binding to 1 and 0 + // because SQLite maps true and false keywords to 1 and 0. Isolate* isolate = env()->isolate(); int r; if (value->IsNumber()) {