Android onUpgrade后ORMlite数据库版本未增加

Android onUpgrade后ORMlite数据库版本未增加,android,ormlite,Android,Ormlite,我一直在做一个Android项目,我一直在使用ORMLite。到目前为止,我已经能够做我需要的一切,我现在正在使用一个相当复杂的数据模型 现在看来我对助手的onUpgrade方法有问题 以下是我的onUpgrade方法的要点: public void onUpgrade(final SQLiteDatabase db, final ConnectionSource connectionSource, int oldVersion, final int newVersion) { try {

我一直在做一个Android项目,我一直在使用ORMLite。到目前为止,我已经能够做我需要的一切,我现在正在使用一个相当复杂的数据模型

现在看来我对助手的onUpgrade方法有问题

以下是我的onUpgrade方法的要点:

public void onUpgrade(final SQLiteDatabase db, final ConnectionSource connectionSource, int oldVersion, final int newVersion) {
try {
    // Simply loop round until newest version has been reached and add the appropriate migration
    while (++oldVersion <= newVersion) {
        // Get all the available update SQL statements and execute them
        final String[] availableUpdates = SQLStaticContentHelper.getMigrationStatements(oldVersion);
        executeStatements(db, availableUpdates, true);
    }           
}
catch (Exception e) {
    Log.e(LOG_TAG, "onUpgrade() - Can't migrate databases, bootstrap database, data will be lost", e);
    onCreate(db, connectionSource);
}
public void onUpgrade(最终SQLiteDatabase数据库、最终ConnectionSource ConnectionSource、int旧版本、最终int新版本){
试一试{
//只需循环,直到达到最新版本,并添加适当的迁移

虽然(++oldVersion您是否也有可能抛出onCreate?我认为如果onUpgrade毫无例外地返回,Android操作系统将为您更新版本。可能会抛出一个
RuntimeException
?没有。我甚至在RuntimeException之后插入了几行日志,以确保正确。它会重新创建数据库和应用程序按预期工作,但每次我重新启动应用程序时,它都会再次尝试升级。
public void onCreate(SQLiteDatabase database ,ConnectionSource connectionSource) {    
try {
    //create the tables
    for (Class<?> c : allTablesArray)
    {
        try {
            TableUtils.dropTable(connectionSource, c, false);
        } catch (SQLException e) {Log.d(LOG_TAG, "onCreate() - Not droping table " + c.getCanonicalName() + ". Does not exist.");}
        TableUtils.createTable(connectionSource, c);
    }

} catch (Exception e) {
    Log.e(LOG_TAG, "onCreate() - Problem creating tables : ", e);
    throw new RuntimeException(e);
}