GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sqlite: bind empty ArrayBuffer as empty blob by araujogui · Pull Request #67657 · nodejs/node

sqlite: bind empty ArrayBuffer as empty blob #67657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
nodejs-github-bot merged 2 commits into nodejs:main from araujogui:sqlite-empty-arraybuffer
Nov 22, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

sqlite: bind empty ArrayBuffer as empty blob #67657

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
68e9096
sqlite: bind empty ArrayBuffer as empty blob
araujogui Nov 20, 2026
a8da587
fixup! sqlite: bind empty ArrayBuffer as empty blob
araujogui Nov 20, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

22 changes: 16 additions & 6 deletions 22 src/node_sqlite.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ void JSValueToSQLiteResult(Isolate* isolate,
} else if (value->IsArrayBufferView() || value->IsArrayBuffer() ||
value->IsSharedArrayBuffer()) {
ArrayBufferViewContents<uint8_t> buf(value);
sqlite3_result_blob64(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
if (buf.length() == 0) {
// Empty buffers may lack a data pointer, which SQLite treats as NULL.
sqlite3_result_zeroblob(ctx, 0);
} else {
sqlite3_result_blob64(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
}
} else if (value->IsBigInt()) {
bool lossless;
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless);
Expand Down Expand Up @@ -3632,11 +3637,16 @@ bool Statement::BindValue(const Local<Value>& value, const int index) {
} else if (value->IsArrayBufferView() || value->IsArrayBuffer() ||
value->IsSharedArrayBuffer()) {
ArrayBufferViewContents<uint8_t> buf(value);
r = sqlite3_bind_blob64(statement_.get(),
index,
buf.data(),
static_cast<sqlite3_uint64>(buf.length()),
SQLITE_TRANSIENT);
if (buf.length() == 0) {
// Empty buffers may lack a data pointer, which SQLite treats as NULL.
r = sqlite3_bind_zeroblob(statement_.get(), index, 0);
} else {
r = sqlite3_bind_blob64(statement_.get(),
index,
buf.data(),
static_cast<sqlite3_uint64>(buf.length()),
SQLITE_TRANSIENT);
}
} else if (value->IsBoolean()) {
r = sqlite3_bind_int(statement_.get(), index, value->IsTrue() ? 1 : 0);
} else if (value->IsBigInt()) {
Expand Down
24 changes: 24 additions & 0 deletions 24 test/parallel/test-sqlite-custom-functions.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,30 @@ suite('Database.prototype.function()', () => {
});
});

test('empty buffers are returned as empty blobs, not NULL', () => {
using db = new Database(':memory:');
db.function('retEmptyArrayBuffer', () => new ArrayBuffer(0));
db.function('retEmptySharedArrayBuffer', () => new SharedArrayBuffer(0));
db.function('retEmptyUint8Array', () => {
return new Uint8Array(new ArrayBuffer(0));
});
using stmt = db.prepare(`SELECT
typeof(retEmptyArrayBuffer()) AS arrayBufferType,
typeof(retEmptySharedArrayBuffer()) AS sharedArrayBufferType,
typeof(retEmptyUint8Array()) AS uint8ArrayType,
retEmptyArrayBuffer() AS arrayBuffer,
retEmptySharedArrayBuffer() AS sharedArrayBuffer
`);
assert.deepStrictEqual(stmt.get(), {
__proto__: null,
arrayBufferType: 'blob',
sharedArrayBufferType: 'blob',
uint8ArrayType: 'blob',
arrayBuffer: new Uint8Array(),
sharedArrayBuffer: new Uint8Array(),
});
});

test('throws if returned BigInt is too large for SQLite', () => {
const db = new Database(':memory:');
db.function('retBigInt', () => {
Expand Down
35 changes: 35 additions & 0 deletions 35 test/parallel/test-sqlite-typed-array-and-data-view.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,38 @@ suite('Statement with ArrayBuffer and SharedArrayBuffer', () => {
});
}
});

suite('Statement with empty buffers', () => {
const emptyBuffers = [
['ArrayBuffer', () => new ArrayBuffer(0)],
['SharedArrayBuffer', () => new SharedArrayBuffer(0)],
['Uint8Array', () => new Uint8Array()],
['Uint8Array on empty ArrayBuffer', () => new Uint8Array(new ArrayBuffer(0))],
['DataView on empty ArrayBuffer', () => new DataView(new ArrayBuffer(0))],
];

for (const [displayName, createBuffer] of emptyBuffers) {
test(`${displayName} binds as an empty blob, not NULL`, (t) => {
using db = new Database(':memory:');
db.exec('CREATE TABLE test (data BLOB NOT NULL)');
const buffer = createBuffer();
// Anonymous binding
{
using stmt = db.prepare('SELECT typeof(?) AS type');
t.assert.strictEqual(stmt.get(buffer).type, 'blob');
}
// Named binding (object)
{
using stmt = db.prepare('SELECT typeof($data) AS type');
t.assert.strictEqual(stmt.get({ '$data': buffer }).type, 'blob');
}
// Insert into a NOT NULL column and read it back
{
using insert = db.prepare('INSERT INTO test VALUES (?)');
insert.run(buffer);
using select = db.prepare('SELECT data FROM test');
t.assert.deepStrictEqual(select.get().data, new Uint8Array());
}
});
}
});
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.