Question

I've got an Android app I'm about ready to release, and I'm reviewing some of my code. I'm worried about my implementation for my SQLiteOpenHelper. Specifically, I want to verify what the oldVersion and newVersion reference in the onUpgrade method. Is this based upon the versionCode in my AndroidManifest.xml? Or is this value something completely separate, specific to the database? If it's the latter, how does the database determine the version?

Was it helpful?

Solution

Is this based upon the versionCode in my AndroidManifest.xml?

Not normally, unless you upgrade your schema every time you publish an upgrade to your app, and even then the "based upon" would be mostly coincidental.

Or is this value something completely separate, specific to the database?

Yes. You increment the version every time you have a new database schema.

If it's the latter, how does the database determine the version?

On every onCreate() and onUpgrade(), Android sticks the then-new version of the database schema in a metadata table in the database. That's what Android then checks when you use your helper in the future, comparing that stored value to the one you provide in your SQLiteOpenHelper constructor.

OTHER TIPS

while you solved your question, that you can determine it just yourself on creation. I want to leave this for persons wondering:

how does the database determine the version..

.. if the database already exists?

it is stored with the db file and accessible via PRAGMA user_version; as noted in SQLiteOpenHelper.java:getVersion().

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