mardi 15 avril 2014

what is the correct way to upgrade sqllite db?


Vote count:

0





private static final String TABLE_MAIN_CREATE = "CREATE TABLE IF NOT EXISTS " + TABLE_MAIN_NAME + " ( a INTEGER, b LONG, c TEXT, d TEXT, e DATETIME, f TEXT)";
private static final String TABLE_MAIN_UPGRADE = "ALTER TABLE " + TABLE_MAIN_NAME + " ADD Column f TEXT";

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_MAIN_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < newVersion) {
db.execSQL(TABLE_MAIN_UPGRADE);
}
onCreate(db);
}


The previous db version was without the "f" field. Is this the correct way to upgrade the DB? Do I need onCreate(db) in onUpgrade?


I did this several times and each time I got another exception: 1) table already exists so I added "IF NOT EXISTS" 2) could not read row 0, col 5 error here I lost it....


IS this the correct way to upgrade the db?



asked 43 secs ago






Aucun commentaire:

Enregistrer un commentaire