I have created a very big app that uses much SQLite reading/writing. Since I'm not able to see database in the phone in easy manner, I have backup function in the app which uploads db file to server (which is for developing purposes my local computer).
For the beginning I had initial database state both on server and in a phone. Then I made some changes in the phone database (added some stuff in it). When I list data, I can see new stuff listed.
Then I want to backup database - I have logged everything prior to run backup - location from where is db file taken (it is /data/user/0/APPLICATION_PACKAGE/databases/DATABASE_FILENAME). Also I have erased all files on the server. When backup is completed, I have checked newly db file on server - file size in bytes matches, but there are NO changes in the file???
I said OK, maybe, somehow, it is not flushed. I have closed the app, run it again, list data to see if changes are there (and they were), run backup again, and when checked new database file on server - no changes again.
How is this possible? Is there a way to flush changes into db file so I can backup it regularly?
Most likely wal (write-ahead logging) mode is enabled. To disable it you need to do something like this:
public class MyDbHelper extends SQLiteOpenHelper {
//...
@Override
public void onOpen(SQLiteDatabase db) {
db.disableWriteAheadLogging();
super.onOpen(db);
}
//...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.