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
6 changes: 4 additions & 2 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ void JSValueToSQLiteResult(Isolate* isolate,
} else if (value->IsString()) {
Utf8Value val(isolate, value.As<String>());
sqlite3_result_text(ctx, *val, val.length(), SQLITE_TRANSIENT);
} else if (value->IsArrayBufferView()) {
} else if (value->IsArrayBufferView() || value->IsArrayBuffer() ||
value->IsSharedArrayBuffer()) {
ArrayBufferViewContents<uint8_t> buf(value);
sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
} else if (value->IsBigInt()) {
Expand Down Expand Up @@ -2286,7 +2287,8 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
}
} else if (value->IsNull()) {
r = sqlite3_bind_null(statement_, index);
} else if (value->IsArrayBufferView()) {
} else if (value->IsArrayBufferView() || value->IsArrayBuffer() ||
value->IsSharedArrayBuffer()) {
ArrayBufferViewContents<uint8_t> buf(value);
r = sqlite3_bind_blob64(statement_,
index,
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-sqlite-data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ 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) => {
Expand Down
Loading