android - Using onUpGrade with multiple versions of App to add columns -


i have versions 4,5 out in production application. between 4 , 5 added new columns app's database adapter using 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 next version (version 6) if wanted add new column. if had upgraded version 5, of course delete current onupgrade definition , change add new column.

but, if user upgrading version 4 version 6? if leave both alter table statements, fine them, would create duplicate columns version 5 people? running twice matter newer versions?

my question basically, how around missing columns non upgraded people?

you need make if statement each number

if(oldversion < 5)   ... sql alter statement first new column ...  if(oldversion < 6)   ... next sql alter statement 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -