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?
I want to keep my data
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…