mardi 26 janvier 2016

How to implement DBHelper upgrade method for SQLite

I have a Content Provider that is backed by a SQLite database. Say I need to add a new column called goodTimes to the database. Say further that I cannot simply do

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + Dog.TABLE_NAME);
    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + Pen.TABLE_NAME);
    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + Cap.TABLE_NAME);
    onCreate(sqLiteDatabase);
}

as my user may have tasks in progress. So how do I upgrade the database? I also cannot simply not implement onUpgrade as I would end up with a SQLiteException when I try to query concerning goodTimes. So how do I implement onUpgrade?

Aucun commentaire:

Enregistrer un commentaire