Fix "destination database is in use " error during database backup #425
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT 05/10/2018: The analysis of this PR is wrong. See #427 for the "real" fix.
This PR addresses #424.
The
DatabaseWriter.erase()
method internally uses the SQLite Online Backup API:This technique used to fail with an error of code 1 (SQLITE_ERROR), message "destination database is in use" when live SQLite prepared statement would prevent the backup from starting (see the regression tests for the precise failure setup).
It happens that Record methods keep prepared statements in a cache, in order to optimize insertions, updates, deletions, and tests for record existence.
This PR thus clears the statement cache before starting a backup, when we used to do it after a successful backup.
The error "destination database is in use" can still happen during a backup, if the client application keeps its own prepared statements alive. To fix this error, the client application must release all prepared statements before starting the backup.