Reputation: 197
I have an sqlite3 database in Android. There is a thread that works with the db. From another thread, I'd like to copy the sql file to a different location. I do not know whether the db is closed at the moment, or maybe there is a transaction going on at precisely the same moment. Can I assume that the copy of a file will always be a valid sqlite database?
Since the transactions in sqlite are atomic, this looks reasonable but I'd like to be sure.
The db is opened using DatabaseHelper
and data is inserted time to time with SQLiteDatabase.insert
. Some times the db is closed and then reopened.
Upvotes: 0
Views: 197
Reputation: 180080
Database transactions are atomic, but copying a file is, by itself, not a database transaction.
To ensure that no other SQLiteDatabase
object can access the database file, execute BEGIN EXCLUSIVE first.
As long as you do not change the database inside this transaction, the database file is in a consistent state.
Upvotes: 2