我在我的android应用程序中有一个只读数据库,我定期更新。该应用程序始终在其资产中携带最新版本的数据库。SQLiteOpenHelper onUpgrade多次调用
我增加,我传入构造为我SQLiteOpenHelper的子类的版本号,碰撞它(这种情况下)到版本4
我有以下代码:
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// copy from assets to local storage; version really doesn't matter;
// DB will be opened from the target location.
copyDataBase();
}
这得到叫我拨打电话获得可读数据库:
SQLiteDatabase db = myDBHelper.getReadableDatabase();
// Here db.getVersion() correctly returns "4", the newVersion.
// db is also usable and has the correct data.
但每次我打电话getReadableDatabase onUpgrade时间会从oldVersion = 3叫NEWVERSION = 4。
任何想法为什么版本不粘?
这可能有助于查看您的代码,了解如何从您的活动中调用这些代码。 – Nate 2012-07-16 21:17:26