I've got a little problem with improving my sqlite database. For the time being I am by 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 have the applying installed in the beggining..but when you put in it now, it'll run queries only in case 3, since the current version is 3.

I want to find away out to operate the queries right from the start.. if my last version of database is 5, I wish to run first the situation 2, than situation 3, than 4 and finally situation 5. And So I will not have to write all of the queries right from the start since it will crash for that old customers.

Any ideas how to do this?

What going to make use of a loop?

       //or start = oldVersion;              
 for (int start = 2 , start<=newVersion ; start++){
      switch(start){
    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");
        break;
    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)");
        break;
    default:
        break;
    }

But it's not normal way. As though a person already added some alteration. And also you again run that alteration it can create exception.

Just add your queries in the situation 2 in to the situation 3 and add break statement after each situation. So inside your situation it will likely be something similar to 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");
        break;
    case 3:
        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");
        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)");
        break;
    }
}

Update: Do smthg such as this:

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");
    break;
case 3:
    Log.w("","UPGRADE DATABASE : "+newVersion);
    switch(oldVersion) {
        case 1:
            db.execSQL("ALTER TABLE collection_lang ADD COLUMN bonus_text VARCHAR(200)");
            db.execSQL("ALTER TABLE collection_lang ADD COLUMN quantity integer");
            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)");
            break;
        case 2: 
            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)");
            break;
    }

}