Keeping SQLite data after update
I have an app that has an sqlite with 3 tables. My concern is that, if I introduce an update that adds another table (so that's 4 tables) then the updated version will wipe out the database.
How can I backup/restore db given that the backup happens before the update and the restore after the update? If I do it using the IO (copy to SD card and copy back) then it will fail.
I am thinking probably of exporting data to xml and loading manually. Is there another way? any example on how to do it?
If you simply want to add a new table, comment out the DROP TABLE commands in your onUpgrade()
method. You have full control of the code in onUpgrade()
so it can just be:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("CREATE TABLE ...");
}
Technically you don't even need to increment the database version, anytime you have access to a copy of db
you can execute your CREATE statement.
上一篇: 如何从模板名称集合渲染流星模板?
下一篇: 更新后保留SQLite数据