On Saturday, 21 December, 2019 03:27, Thomas Kurz <sqlite.2...@t-net.ruhr> 
wrote:

>I have a problem when opening a read-only database, which is a WAL-mode
>database.

>When trying to open it in read-only mode, i.e. using
>file:test.sqlite?mode=ro, SHM and WAL file are created. That's
>unpleasant, but the actual problem is the two files don't get deleted
>when closing the database.

>Steps to reproduce (OS=Windows, SQLite=3.30.1):

>.open test.sqlite
>create table test (a integer primary key autoincrement);
>insert into test (a) values (null);
>select * from test;
>.quit

>Now set the read-only attribute to test.sqlite, and continue:

>.open file:test.sqlite?mode=ro
>select * from test;   <-- creates wal and shm
>.quit

>Result: SHM and WAL files are kept.

A WAL database can only be opened as Read-Only if the WAL and SHM files exist.  
Therefore, when a WAL database is opened in read-only mode they must be created 
if they do not exist (and an error will ensue if they neither exist nor can be 
created).  However, when you close such a database, you (the royal you) have 
said that it is to be read-only.  If it is read-only why would you (the royal 
you) expect that the files would be deleted, since they must exist in order to 
open the file?

The three files (the database file plus the WAL and SHM file) can now be 
written to "read only media" such as a CD, and they will be able to be opened 
and closed as read-only without problems.  If the database was opened on CD 
media and and attempt was made to "delete" the SHM and WAL files, then that 
attempt would fail and there would be complaints that SQLite was attempting to 
"delete things from a read-only database".

This behaviour is almost certainly by design.  In fact, I do believe that I 
have managed to read documentation regarding it somewhere, but that somewhere 
does not yield specificity beyond "in the documentation on the sqlite.org 
website" at the moment.

-- 
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.




_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to