SQLite User Forum

Opening a DB with SQLITE_OPEN_EXCLUSIVE
Login
Thanks.

I hadn't noticed that locking_mode provides a way to avoid unlocking the database between one transaction and a following pragma journal_mode.

However, if I kill my process after commit; but before setting wal, I've still got a database that shows my application_id, but which has never been wal. Admittedly, that is a very small window for failure.

To close that window it seems like my choices are

1) A looser definition of "empty" that ignores the current journal mode, and for an empty database I set wal first, and then do my first transaction. This means that by the time I set application_id, the database had already been set to wal (somebody else could unset wal in-between, but since they can do that at any time, anyway, I'm ok with that).

2) Do what you suggested, but have my initial transaction set a "WAL pending" flag that gets cleared after my app (this one, or a later instance) succeeds in setting wal mode.