I have a little issue with upgrading my sqlite database. For now I’m using this :
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w("","UPGRADE DATABASE : "+" oldVErsion : "+oldVersion+" newVersion : "+newVersion);
switch(newVersion){
case 2:
Log.w("","UPGRADE DATABASE : "+newVersion);
db.execSQL("ALTER TABLE collection_lang ADD COLUMN bonus_text VARCHAR(200)");
db.execSQL("ALTER TABLE collection_lang ADD COLUMN quantity integer");
case 3:
Log.w("","UPGRADE DATABASE : "+newVersion);
db.execSQL("ALTER TABLE users ADD COLUMN firstName varchar(70)");
db.execSQL("ALTER TABLE users ADD COLUMN lastName varchar(70)");
db.execSQL("ALTER TABLE users ADD COLUMN user varchar(70)");
}
}
It’s working if you already have the application installed from the beggining..but if you install it now, it will run queries only in case 3, because the current version is 3.
I need to find a way to run the queries from the beginning.. if my last version of database is 5, I want to run first the case 2, than case 3, than 4 and at last case 5. So I won’t need to write all the queries from the beginning because it will crash for the old users.
Any ideas how to achieve this?
Just add your queries from the case 2 into the case 3 and add break statement after each case. So in your case it will be something like this:
Update: Do smthg like this: