On 14 Jul 2019, at 6:05pm, ardi <ardillasdelmo...@gmail.com> wrote:

> I have read the backup API page (https://www.sqlite.org/backup.html)
> that shows how to read a sqlite db from disk to memory, and how to
> save it back to disk, but it doesn't talk about the topic of
> performing the save in a safe way.

This is a feature which SQLite provides by itself.  If you keep a database on 
disk, SQLite ensures that a copy of your data – either before or after a change 
– is always available.  It does this by changing the contents of the file, not 
by renaming one file and making another.

This is one of the most important features of SQLite.  It means you do not have 
to write your own software to make it happen.

If your computer crashes while changes are being made, SQLite is always able to 
rescue one copy of the data from the file.  It may be the copy before the 
change or the copy after the change, but it will never lose both copies.

> Do you have any recommendation for saving the inmemory db in a safe
> way?

If you make an inmemory database you are yourself responsible for making sure 
your data is saved on disk.  If you choose to keep your data in memory you are 
disabling the feature of SQLite you are asking about.

> Another scenario of interest would be if the db is really huge and you
> consider the possibility of not overwriting the whole old file, but
> just committing the changes, in order to save unnecessary disk writes.

Again, this is taken care of automatically if you keep your data on disk.  
SQlite does not rewrite the entire data file when changes are made.  It 
rewrites only the rows which have changed.

It looks as if you have all the features you want, if only you use SQLite to 
keep data in a database file instead of trying to use the inmemory feature.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to