我正在尝试在我的 Android 应用程序中更新我的数据库。当我更新版本号时,会调用 onUpgrade,但版本号不会增加,所以每次访问数据库时,都会调用 onUpgrade。这是我的代码:
private final static int DB_VERSION = 8;
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.myContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "in onCreate");
try {
copyDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(TAG, "in onUpgrade. Old is: " + oldVersion + " New is: " + newVersion);
myContext.deleteDatabase(DB_NAME);
Log.d(TAG, "the version is " + db.getVersion());
db.setVersion(newVersion);
Log.d(TAG, "the version is " + db.getVersion());
onCreate(db);
}
有谁知道为什么会这样?