Closed lakmeer closed 5 months ago
Hey @lakmeer , thanks for the detailed report!
I think the issue lies within using WAL mode in the deserialized database. From the Deserialize a database docs:
The deserialized database should not be in WAL mode. If the database is in WAL mode, then any attempt to use the database file will result in an SQLITE_CANTOPEN error. The application can set the file format version numbers (bytes 18 and 19) of the input database P to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the database file into rollback mode and work around this limitation.
That SQLITE_CANTOPEN
error code has the corresponding 'Unable to open database file'
error message.
I think you can run db.pragma('journal_mode = DELETE')
before serializing the database, and it should work fine! Or maybe even:
buffer[18] = 0x01;
buffer[19] = 0x01;
But that seems sketchier to me. Let me know if that works!
Hi @asg017,
Perfect, you nailed it 😁
Thanks so much for you help, and thanks for this extension. Stay awesome
better-sqlite3
supports cloning a loaded db into memory by passing a serialized buffer into a new Database constructor. I would like to use this to have a test db that starts with some data and it's vector embeddings, but doesn't save any changes during testing (mainly to save me paying OpenAI to re-embed all my data each time I relaunch).When using my
test.db
(which is otherwise working great), I get this error, but using a fresh database with single basic table, it works. Perhaps there is some compatibility issue with.serialize()
?Repro Script
Outcome
USE_BUFFER
is false, there is no error, and we successfully print one row from theitems
table (even without applying VSS in this repro script)USE_BUFFER
is true, I get 'unable to open database file', but it seems to occur on the first line that I try to call some method ondb
, likeprepare
orpragma
, and not theDatabase(buffer)
constructor itselfFurther context
{ verbose }
option in Database constructor mode doesn't output anything before failurepragma user_version
to track migrationsSchema for creating test.db
Code that created test.db
Thanks for any advice you might have. This extension is very cool and has been making my project much more fun to work on :)