Android SQLiteOpenHelper onUpgrade()

‹ Query the COUNT of rows in a SQLite table in Android | What is Gradle? (comparison of gradle vs ant vs make) ›

It's not necessary to wrap your SQLiteOpenHelper.onUpgrade() code in beginTransaction() and endTransaction() pairs, because ever since the earliest version of SQLiteOpenHelper, the Android source code has done this for you:

if (version != mNewVersion) {
    db.beginTransaction();
    try {
        if (version == 0) {
            onCreate(db);
        } else {
            onUpgrade(db, version, mNewVersion);
        }
        db.setVersion(mNewVersion);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

Subscribe to All Posts - Wesley Tanaka