On April 10, 2017 5:14:23 PM EDT, Jens Alfke <j...@mooseyard.com> wrote: >I'm aware that a database in WAL mode can't be opened read-only if its >directory isn't writeable[1]. However, I'm unexpectedly getting errors >opening a database when the directory _is_ writeable, but the database >is opened read-only. Specifically: > >* The database file is in WAL mode. >* The -wal and -shm files do not exist (i.e. the database was >previously closed cleanly.) >* The directory containing the database is writeable (i.e. the process >is allowed to create files in it.) >* The database is opened with sqlite3_open_v2, using the >SQLITE_OPEN_READONLY flag. > >In this situation, any SQLite call that actually accesses the database >will fail with SQLITE_CANTOPEN. > >It seems as though SQLite decides that because the handle is read-only, >it's not allowed to create the -shm file. There's some logic to this, >but I can't find any mention of it in the documentation. > >(I'm using SQLite 3.16 on macOS 10.12.4.) > >—Jens > >[1]: https://www.sqlite.org/wal.html#readonly >_______________________________________________ >sqlite-users mailing list >sqlite-users@mailinglists.sqlite.org >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
WAL databases must be opened read/write because readers need to write to the shm file. It is in the documention on WAL mode: It is not possible to open read-only WAL databases. The opening process must have write privileges for "-shm" wal-index shared memory file associated with the database, if that file exists, or else write access on the directory containing the database file if the "-shm" file does not exist. -- J. King _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users