sqlite-net icon indicating copy to clipboard operation
sqlite-net copied to clipboard

Trouble with automatic WAL mode

Open effpath999 opened this issue 7 years ago • 3 comments

Hello, as well known, since the latest version sqlite-net defaults to WAL mode for journal. Unfortunately, this has caused me a lot of trouble: I have an app that offers export data functionality and, until this change, I implemented it simply by copying the db file, confident that all the data was there. But this is no more true now that WAL is enabled: a lot of recently written data reside in the -WAL file and, trying to simply copy the db file often end with a corrupt file. Doing a checkpoint (PRAGMA wal_checkpoint(FULL)) before exporting at least put the db file in a consistent state, but still most recent data are often missing. Also, trying to close the connection does not help: the -WAL file is still there, retaining the most recent data. I am wondering if someone knows a better way to export data (that is, create a consistent copy of the database) with WAL enabled and if, in a future version, it will be possible to opt out from WAL mode at connection ctor level (trying to change journal_mode after the connection is open does not work consistently [in fact, almost never, and, even when it seems to work, it is soon reverted to WAL mysteriously]). Any help would be much appreciated.

effpath999 avatar Jan 19 '19 19:01 effpath999

I have made two changes (1.6-beta to be released soon) that help address this:

  1. I have made it possible to disable WAL mode if it's not a good fit (see the new ConnectionsString)
  2. I have added a Backup function that will output a file using sqlite's own backup routines. This should give you the most up-to-date data.

praeclarum avatar Jan 23 '19 23:01 praeclarum

Thank you Frank, I look forward to use these new features, especially the backup function, so I won't have to disable WAL if it works well.

effpath999 avatar Jan 24 '19 00:01 effpath999

You can try them out with 1.6-beta now. My tests are passing so I'm going to close this for now. Please let me know if it doesn't work for you.

praeclarum avatar Jan 24 '19 01:01 praeclarum