jeudi 18 juin 2015

Using onUpGrade with multiple versions of App to add columns

I have versions 4,5 out in production for my application. Between 4 and 5 I added new columns to my app's database adapter using the alter statement:

  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //add new columns
        String alter = "ALTER TABLE " + DATABASE_TABLE + " ADD COLUMN " +
                KEY_NEWCOLUMN_NAME+ " integer DEFAULT 0";
        db.execSQL(alter);

}

So, in my next version (version 6) if I wanted to add another new column. If everyone had upgraded to version 5, then of course I would delete the current onUpgrade definition and change it to add the new column.

But, what if my user was upgrading from version 4 to version 6? If I were to leave both the alter table statements, then it would be fine for them, but would it create duplicate columns for version 5 people? Would running it twice matter for the newer versions?

My question is basically, how do I get around missing columns for the non upgraded people?

Aucun commentaire:

Enregistrer un commentaire