0

I am experiencing an issue with an app that is published on the play store:

After a new update is released, some users cannot use the app properly, until they delete the app and reinstall it from scratch. I cannot reproduce this issue and I don't have any error logs.

The app features an internal SQLite database, which will be wiped everytime a new update is released. Also it implements a REST client via okhttp library.

I feel like I am missing something in the update process, but I am not aware of anything else that could go wrong. It seems like there could be issues with the DB, but it will be wiped completely. Also the REST client might be a problem, but I couldn't imagine this actually being an issue. There are no other libraries that seem relevant to this problem.

I am looking forward to any suggestions, thank you,

J.V.

Edit: the code segment that is used for SQLite handling

public RfidTagDbHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

public void onCreate(SQLiteDatabase db) {
    db.execSQL(SQL_CREATE_ENTRIES);
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(SQL_DELETE_ENTRIES);
}

public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    onUpgrade(db, oldVersion, newVersion);
}

SQL_DELETE_ENTRIES contains a piece of SQL code that drops all tables if existing, CREATE_ENTRIES does the opposite

Jan
  • 17
  • 1
  • 6
  • Are you using Java? There is a class called SQlite Helper. You can use that? – Xenolion Oct 19 '17 at 15:07
  • Yes, I am using Java and the library you mentioned. I think this might be more of a general workflow problem when updating my app, but it could also be a software issue, which is why I provided some information about the libs I used – Jan Oct 19 '17 at 15:10
  • Edit add the contents of the class? And we can see how it works – Xenolion Oct 19 '17 at 15:11
  • I edited my original post and included to code segment that handles the DB update mechanism. The SQL commands are defined in the same class and are valid and working properly. – Jan Oct 19 '17 at 15:13
  • Did you increment the version from lets say 1 to 2?? New version when you make an update to your app. – Xenolion Oct 19 '17 at 15:15
  • Good suggestion – Jan Oct 19 '17 at 15:21

2 Answers2

0

Your onUpgrade() must leave the database in a state appropriate for newVersion. Don't just delete the table but also create it anew. For a destructive upgrade process such as yours you can achieve it by calling onCreate() in onUpgrade():

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(SQL_DELETE_ENTRIES);
    onCreate(db);
}
laalto
  • 150,114
  • 66
  • 286
  • 303
0

You should upgrade the database Version of your class lets say from 1 to 2. In your SQliteHelper Class. Then delete entries and the create entries like:

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
     db.execSQL(SQL_DELETE_ENTRIES);
     db.execSQL(SQL_CREATE_ENTRIES);
}
Xenolion
  • 12,035
  • 7
  • 33
  • 48