Skip to content
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.

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

Cannot insert empty buffer (it becomes NULL) #651

Closed
Labels

Comments

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Jun 30, 2021

Similar to #11

My NOT NULL constraint is failing for empty BLOB.

better-sqlite3@7.4.1
Node v14.17.0
const Database = require('better-sqlite3');
const db = new Database(':memory:');

db.exec('CREATE TABLE data (contents BLOB)');
db.prepare('INSERT INTO data (contents) VALUES (?)').run(new Uint8Array(0));
console.log(db.prepare('SELECT * FROM data').all());
[ { contents: null } ]

Related

ericsink/SQLitePCL.raw@e324598
dotnet/efcore#17494 (comment)
https://github.com/aspnet/Microsoft.Data.Sqlite/pull/208/files
https://sqlite.org/forum/forumpost/5bae43cbd77fc654?t=h
https://www.mail-archive.com/sqlite-users@mailinglists.sqlite.org/msg35366.html

Also what is it with SQLite forums and "The author has deleted this message."....

Prinzhorn added a commit to Prinzhorn/better-sqlite3 that referenced this issue Jul 2, 2021
@Prinzhorn
Copy link
Contributor Author

Prinzhorn commented Jul 8, 2021

For now I'm working around it by binding an empty string when the buffer is empty

stmt.run({
    content: content.length === 0 ? '' : content,
});

@JoshuaWise JoshuaWise added the bug label Jul 8, 2021
@JoshuaWise
Copy link
Member

JoshuaWise commented Jul 19, 2021

It appears this bug only occurs in newer version of node, because they changed how their C++ API works. Oh well.

This is fixed in v7.4.3.

@Prinzhorn
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment