继承SQLiteOpenHelper类后,实现其中的onUpgrade 方法
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//遍历所有版本
//定义每个版本更新内容
for (int j = oldVersion + 1; j <= newVersion; j++) {
switch (j) {
case 2:
case 3:
case 4:
case 5:
for (String sql : userTableList) {
db.execSQL(sql, new String[]{});
}
break;
case 6:
//添加 CODE 字段
String sql = "ALTER TABLE " + DBConfig.TABLE_NAME + " ADD CODE VARCHAR(255);";
db.execSQL(sql, new String[]{});
break;
default:
break;
}
}
}