Question

I wonder what is the maximum number of SQLiteOpenHelper version?

For the version code, I found a SO topic says that this number is just an integer to indicate version of the code base. There will be no issue as long as this number keep increasing when we deploy a new version, the value can be as much as we like.

But, I couldn't find any information about SQLiteOpenHelper version maximum value and what will happen if we increase this number more than 1 at a time. (In every online tutorial I found will increase this number by 1 at a time, says 3 >> 4 or 10 >> 11)

Was it helpful?

Solution 2

In the database, the version number is stored with PRAGMA user_version, so it must fit into a signed 32-bit integer. (The Android libraries use the same data type.)

Valid version numbers must be greater than zero, so you could have 2147483647 different versions, but there are no other restrictions.

It is possible for version numbers to jump by more than 1 at a time. This could be because you never used the other numbers, or because the app was not updated for a long time. (In the latter case, your onUpgrade method must be able to upgrade through multiple steps.)

OTHER TIPS

Here is a chunk of code from SQLiteOpenHelper.getWritableDatabase() method:

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

It invokes onCreate if version number is 0, onUpgrade otherwise; the implementation is your responsibility.

The increment does not matter and it can be as big as Integer.MAX_VALUE, as long as the version number is greater than zero.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top