Better-sqlite3: Empty buffer (aka new Buffer(0)) transforms to null instead of empty blob

Created on 26 Oct 2016  路  4Comments  路  Source: JoshuaWise/better-sqlite3

const database  = require('better-sqlite3');
const db = new database('example.db');

db.on('open', () => {
  db.prepare('CREATE TABLE result(d BLOB, t integer);').run()

  const st = db.prepare('INSERT INTO result (d, t) VALUES (?, ?)')

  st.run([null, 1])
  st.run([new Buffer(0), 2])

  console.log('* in result:\n\t', db.prepare('SELECT * FROM result').all())

  console.log('SELECT d = null:\n\t', db.prepare('SELECT * FROM result WHERE d = ?').all(null))
  console.log('SELECT d = new Buffer(0):\n\t', db.prepare('SELECT * from result where d = ?').all(new Buffer(0)))
  console.log('SELECT d is new Buffer(0):\n\t', db.prepare('SELECT * from result where d is ?').all(new Buffer(0)))
  console.log('SELECT d is null:\n\t', db.prepare('SELECT * from result where d is ?').all(null))
});

output:

* in result:
     [ { d: null, t: 1 }, { d: null, t: 2 } ]
SELECT d = null:
     []
SELECT d = new Buffer(0):
     []
SELECT d is new Buffer(0):
     [ { d: null, t: 1 }, { d: null, t: 2 } ]
SELECT d is null:
     [ { d: null, t: 1 }, { d: null, t: 2 } ]

Most helpful comment

After some testing, I've determined that the bug was introduced in Node.js v6.6.0, but fixed in v6.7.0. It also has the correct behavior in v6.5.0 and previous versions.

So either downgrade or upgrade your version of Node.js. I don't think there's anything else we can do about the issue.

All 4 comments

I can't reproduce this behavior. Which version of better-sqlite3 and Node.js are you using?

Node.js v6.6.0,
Linux: Ubuntu 16.04
[email protected]

I update to master branch but bug are repeated.

After some testing, I've determined that the bug was introduced in Node.js v6.6.0, but fixed in v6.7.0. It also has the correct behavior in v6.5.0 and previous versions.

So either downgrade or upgrade your version of Node.js. I don't think there's anything else we can do about the issue.

Thanks. Now it's working good.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mann-david picture mann-david  路  5Comments

k1ngrnbz picture k1ngrnbz  路  4Comments

Alon-L picture Alon-L  路  5Comments

geopic picture geopic  路  3Comments

Silve2611 picture Silve2611  路  6Comments