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
4 changes: 3 additions & 1 deletion src/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ namespace Values {
Field(_name, SQLITE_BLOB), length(len) {
value = new char[len];
assert(value != nullptr);
memcpy(value, val, len);
if (val != nullptr) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the assertion is wrong, if a null pointer is allowed

memcpy(value, val, len);
}
}
inline virtual ~Blob() override {
delete[] value;
Expand Down
14 changes: 14 additions & 0 deletions test/blob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ describe('blob', function() {
done();
});
});

it('should be able to select empty blobs', function(done) {
const empty = new sqlite3.Database(':memory:');
empty.serialize(function() {
empty.run("CREATE TABLE files (id INTEGER PRIMARY KEY, data BLOB)");
empty.run("INSERT INTO files (data) VALUES (X'')");
});
empty.get("SELECT data FROM files LIMIT 1", (err, row) => {
if (err) throw err;
assert.ok(Buffer.isBuffer(row.data));
assert.equal(row.data.length, 0);
empty.close(done);
});
})
});
Loading