sqlite3 icon indicating copy to clipboard operation
sqlite3 copied to clipboard

Unable to read values with NUL in them

Open corrideat opened this issue 2 months ago • 1 comments

Using jsr:@db/[email protected], I'm unable to read values from the DB if they contain a NUL in them (the value is truncated)

import * as sqlite from 'jsr:@db/sqlite'

const db = new sqlite.Database('./example.db')
db.run('CREATE TABLE IF NOT EXISTS Data(key TEXT NOT NULL PRIMARY KEY, value TEXT NOT NULL)')
const readStatement = db.prepare('SELECT value FROM Data WHERE key = ?')
const writeStatement = db.prepare('REPLACE INTO Data(key, value) VALUES(?, ?)')

writeStatement.run('foo', 'bar\x00baz')
console.error(readStatement.get('foo'))
// Result is `{ value: "bar" }` but it should have been `{ value: "bar\x00baz" }`, or a buffer with "bar\x00baz"
// Opening the DB with SQLite shows the correct values

corrideat avatar Dec 15 '25 03:12 corrideat