sqlite3.dart
sqlite3.dart copied to clipboard
Cannot open WAL database via web/wasm
Describe the bug
Full disclosure - I haven't worked with sqlite (or any database, for that matter) for a number of years so there may be a trivial solution to this issue.
I have a specific binary sqlite database file (say myfile.db
) that I want to open with sqlite3.dart wasm. This file has WAL enabled (so there are also two other files (myfile.db-shm
and myfile.db-wal
).
Trying to open via sqlite3.dart web/wasm will fail with "file is not a database" (before I can even access the database, when sqlite3.dart is internally try to set the userVersion).
Specifically, I've pinned down that sqlite is returning SQLITE_NOTADB from this check here https://github.com/sqlite/sqlite/blob/bfa0de86e6a530550bb77cc4ff1e751b0d6d3cbb/src/btree.c#L3260. From this, I infer that the version of sqlite shipped with sqlite3.dart has WAL disabled (I can see that SQLITE_OMIT_WAL is set in your CMake configuration), but myfile.db
itself has some kind of flag set (I can see via xxd
that the 19th byte of the database file is 02, which I guess is some kind of flag that WAL-enabled databases set that means it can't be opened when WAL is disabled).
If I open the binary database file via macOS sqlite CLI, call PRAGMA journal_mode=delete
, then re-open via sqlite3.dart in browser, the database is opened without any issue.
I tried to insert the same statement as early as possible in the sqlite3.dart loading process, but that didn't seem to help.
I don't actually need WAL - I just need to read the database. The sqlite docs suggest that a WAL database can be opened in a non-WAL sqlite if it's opened readonly, but passing OpenMode.readOnly didn't help.
I can't (easily) manipulate the database before trying to load in sqlite3.dart, because it's actually the backing database for the newer format for Anki flashcard deck packages.
TLDR: is there any way to read a WAL database file in the web/wasm build of sqlite3.dart?