Skip to content

Commit 6b17afb

Browse files
committed
sqlite: bind ArrayBuffer
1 parent c9acf34 commit 6b17afb

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/node_sqlite.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,13 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
22932293
buf.data(),
22942294
static_cast<sqlite3_uint64>(buf.length()),
22952295
SQLITE_TRANSIENT);
2296+
} else if (value->IsArrayBuffer()) {
2297+
Local<ArrayBuffer> ab = value.As<ArrayBuffer>();
2298+
r = sqlite3_bind_blob64(statement_,
2299+
index,
2300+
ab->Data(),
2301+
static_cast<sqlite3_uint64>(ab->ByteLength()),
2302+
SQLITE_TRANSIENT);
22962303
} else if (value->IsBigInt()) {
22972304
bool lossless;
22982305
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless);

test/parallel/test-sqlite-data-types.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,20 @@ suite('data binding and mapping', () => {
8080
text: '',
8181
buf: new Uint8Array(),
8282
});
83+
84+
const uint8Array = new Uint8Array([ 49, 50, 51, 52 ]);
85+
const arrayBuffer = uint8Array.buffer;
86+
t.assert.deepStrictEqual(
87+
stmt.run(5, null, null, null, arrayBuffer),
88+
{ changes: 1, lastInsertRowid: 5 },
89+
);
90+
t.assert.deepStrictEqual(
91+
query.get(5), {
92+
__proto__: null, key: 5, int: null, double: null, text: null, buf: uint8Array });
8393
});
8494

95+
96+
8597
test('large strings are bound correctly', (t) => {
8698
const db = new DatabaseSync(nextDb());
8799
t.after(() => { db.close(); });

0 commit comments

Comments
 (0)