Reputation: 35
In the last time I get some strange reviews on the PlayStore.
Whyever after installing the update of my app, users complain all their app data has been wiped. I have absolutely no idea how this can happen. Database is only recreated if tables do not exist.
Code which is executed after opening database connection:
private void createTablesIfNotExist() {
//query tables
Cursor c = DatabaseManager.executeSelect("SELECT name FROM sqlite_master WHERE type = \"table\"");
//if tables already created, do nothing (+1 because of header table)
if (!((tableAmount + 1) == c.getCount())) {
//meta data table
this.database.execSQL("DROP TABLE IF EXISTS android_metadata;");
this.database.execSQL("CREATE TABLE android_metadata (locale TEXT);");
this.database.execSQL("INSERT INTO android_metadata VALUES('de_DE');");
}
//create event table
c = DatabaseManager.executeSelect("SELECT name FROM sqlite_master WHERE name = \"" + EVENTS + "\"");
c.moveToFirst();
if(c.isAfterLast()) {
this.database.execSQL("CREATE TABLE.....");
}
c = DatabaseManager.executeSelect("SELECT name FROM sqlite_master WHERE name = \"" + ASSIGNED_PRODUCTS + "\"");
c.moveToFirst();
if(c.isAfterLast()) {
this.database.execSQL("CREATE TABLE.......");
}
}
Has anyone an idea? Thanks :)
Upvotes: 0
Views: 260
Reputation: 617
I think you don't "rewrite" your data from old database to new one.
Android: upgrading DB version and adding new table
Check this link and if it is your problem then if possible you can transfer data for each version to new one and everything will be fine. You have to remember to design database and dataflow to keep in mind that old users can lack some data, so some data in new database can be nullable
Upvotes: 1