根据我之前提出的问题(请参阅this),如果我在分发应用程序后进行更改并添加新数据,那么删除和重新创建表将不会很好地工作,因为用户将失去他们所有的数据。
是否有处理此问题的推荐策略和/或您是否有一些示例说明我必须采取哪些措施来管理此问题?
谢谢
编辑 :
会是这样的
@Override
public void onUpgrade (SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion){
// TODO Auto-generated method stub
//This is why I'm currently trying
while(oldVersion < newVersion){
switch(oldVersion){
case 2:
//add new datas from version 2 here
break;
case 3:
//add new datas from version 3 here
break;
default:
break;
}
oldVersion++;
}
/*
try {
Log.i(DatabaseHelper.class.getName(), "onUpgrade");
TableUtils.dropTable(connectionSource, Category.class, true);
TableUtils.dropTable(connectionSource, Level.class, true);
TableUtils.dropTable(connectionSource, Hint.class, true);
TableUtils.dropTable(connectionSource, HintCount.class, true);
TableUtils.dropTable(connectionSource, Question.class, true);
// after we drop the old databases, we create the new ones
onCreate(db, connectionSource);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
*/
}