From 6b17afba71b86ffe0d62fd6e5ea83a2e55a7cda4 Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Sun, 1 Mar 2026 10:08:21 -0700 Subject: [PATCH 1/5] sqlite: bind ArrayBuffer --- src/node_sqlite.cc | 7 +++++++ test/parallel/test-sqlite-data-types.js | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index fb229e19fd6aef..3f52b78d0b0b3f 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2293,6 +2293,13 @@ bool StatementSync::BindValue(const Local& value, const int index) { buf.data(), static_cast(buf.length()), SQLITE_TRANSIENT); + } else if (value->IsArrayBuffer()) { + Local ab = value.As(); + r = sqlite3_bind_blob64(statement_, + index, + ab->Data(), + static_cast(ab->ByteLength()), + SQLITE_TRANSIENT); } 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..95d0b12eaf3610 100644 --- a/test/parallel/test-sqlite-data-types.js +++ b/test/parallel/test-sqlite-data-types.js @@ -80,8 +80,20 @@ suite('data binding and mapping', () => { text: '', buf: new Uint8Array(), }); + + const uint8Array = new Uint8Array([ 49, 50, 51, 52 ]); + const arrayBuffer = uint8Array.buffer; + t.assert.deepStrictEqual( + stmt.run(5, null, null, null, arrayBuffer), + { changes: 1, lastInsertRowid: 5 }, + ); + t.assert.deepStrictEqual( + query.get(5), { + __proto__: null, key: 5, int: null, double: null, text: null, buf: uint8Array }); }); + + test('large strings are bound correctly', (t) => { const db = new DatabaseSync(nextDb()); t.after(() => { db.close(); }); From 446a513bf74a210d5e9a1f9fd039bb7d2ead7dd3 Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Sun, 1 Mar 2026 10:19:17 -0700 Subject: [PATCH 2/5] test lint --- test/parallel/test-sqlite-data-types.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-sqlite-data-types.js b/test/parallel/test-sqlite-data-types.js index 95d0b12eaf3610..c8786696e335f5 100644 --- a/test/parallel/test-sqlite-data-types.js +++ b/test/parallel/test-sqlite-data-types.js @@ -85,15 +85,14 @@ suite('data binding and mapping', () => { const arrayBuffer = uint8Array.buffer; t.assert.deepStrictEqual( stmt.run(5, null, null, null, arrayBuffer), - { changes: 1, lastInsertRowid: 5 }, + { changes: 1, lastInsertRowid: 5 } ); t.assert.deepStrictEqual( - query.get(5), { - __proto__: null, key: 5, int: null, double: null, text: null, buf: uint8Array }); + query.get(5), + { __proto__: null, key: 5, int: null, double: null, text: null, buf: uint8Array } + ); }); - - test('large strings are bound correctly', (t) => { const db = new DatabaseSync(nextDb()); t.after(() => { db.close(); }); From 0456c89d0261fb1f594ca180d37251565f51f227 Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Sun, 1 Mar 2026 11:46:33 -0700 Subject: [PATCH 3/5] combine IsArrayBuffer IsSharedArrayBuffer IsArrayBufferView --- src/node_sqlite.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 3f52b78d0b0b3f..e1c5be5aaf7489 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -198,7 +198,7 @@ void JSValueToSQLiteResult(Isolate* isolate, } else if (value->IsString()) { Utf8Value val(isolate, value.As()); sqlite3_result_text(ctx, *val, val.length(), SQLITE_TRANSIENT); - } else if (value->IsArrayBufferView()) { + } else if (value->IsArrayBuffer() || value->IsSharedArrayBuffer() || value->IsArrayBufferView()) { ArrayBufferViewContents buf(value); sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT); } else if (value->IsBigInt()) { @@ -2286,20 +2286,13 @@ bool StatementSync::BindValue(const Local& value, const int index) { } } else if (value->IsNull()) { r = sqlite3_bind_null(statement_, index); - } else if (value->IsArrayBufferView()) { + } else if (value->IsArrayBuffer() || value->IsSharedArrayBuffer() || value->IsArrayBufferView()) { ArrayBufferViewContents buf(value); r = sqlite3_bind_blob64(statement_, index, buf.data(), static_cast(buf.length()), SQLITE_TRANSIENT); - } else if (value->IsArrayBuffer()) { - Local ab = value.As(); - r = sqlite3_bind_blob64(statement_, - index, - ab->Data(), - static_cast(ab->ByteLength()), - SQLITE_TRANSIENT); } else if (value->IsBigInt()) { bool lossless; int64_t as_int = value.As()->Int64Value(&lossless); From c023aba3f191b3ac5e5198012551d4f030d0aabd Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Sun, 1 Mar 2026 11:51:15 -0700 Subject: [PATCH 4/5] reorder - most common first --- src/node_sqlite.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index e1c5be5aaf7489..b5e55f5e5d82a4 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -198,7 +198,7 @@ void JSValueToSQLiteResult(Isolate* isolate, } else if (value->IsString()) { Utf8Value val(isolate, value.As()); sqlite3_result_text(ctx, *val, val.length(), SQLITE_TRANSIENT); - } else if (value->IsArrayBuffer() || value->IsSharedArrayBuffer() || value->IsArrayBufferView()) { + } else if (value->IsArrayBufferView() || value->IsArrayBuffer() || value->IsSharedArrayBuffer()) { ArrayBufferViewContents buf(value); sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT); } else if (value->IsBigInt()) { @@ -2286,7 +2286,7 @@ bool StatementSync::BindValue(const Local& value, const int index) { } } else if (value->IsNull()) { r = sqlite3_bind_null(statement_, index); - } else if (value->IsArrayBuffer() || value->IsSharedArrayBuffer() || value->IsArrayBufferView()) { + } else if (value->IsArrayBufferView() || value->IsArrayBuffer() || value->IsSharedArrayBuffer()) { ArrayBufferViewContents buf(value); r = sqlite3_bind_blob64(statement_, index, From 1f2afe9563a359bcdac5efdbe0959faa0ba51cf0 Mon Sep 17 00:00:00 2001 From: mike-git374 <217764531+mike-git374@users.noreply.github.com> Date: Sun, 1 Mar 2026 12:20:59 -0700 Subject: [PATCH 5/5] lint <= 80 char line --- src/node_sqlite.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index b5e55f5e5d82a4..736c2757485c15 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -198,7 +198,8 @@ void JSValueToSQLiteResult(Isolate* isolate, } else if (value->IsString()) { Utf8Value val(isolate, value.As()); sqlite3_result_text(ctx, *val, val.length(), SQLITE_TRANSIENT); - } else if (value->IsArrayBufferView() || value->IsArrayBuffer() || value->IsSharedArrayBuffer()) { + } else if (value->IsArrayBufferView() || value->IsArrayBuffer() || + value->IsSharedArrayBuffer()) { ArrayBufferViewContents buf(value); sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT); } else if (value->IsBigInt()) { @@ -2286,7 +2287,8 @@ bool StatementSync::BindValue(const Local& value, const int index) { } } else if (value->IsNull()) { r = sqlite3_bind_null(statement_, index); - } else if (value->IsArrayBufferView() || value->IsArrayBuffer() || value->IsSharedArrayBuffer()) { + } else if (value->IsArrayBufferView() || value->IsArrayBuffer() || + value->IsSharedArrayBuffer()) { ArrayBufferViewContents buf(value); r = sqlite3_bind_blob64(statement_, index,