0

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?

1 Answer 1

1

You need to make an if statement for each number

if(oldVersion < 5)
  ... sql alter statement for the first new column ...

if(oldVersion < 6)
  ... next sql alter statement
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.