I have an app that uses a database. At startup I check to see if my tables are missing and if so I create them. Works great.
I’ve noticed that if I “adb uninstall” then the next time I run my app the tables are created again (this is what I need), but what about when updating through the marketplace?
I’m in the process of releasing an update, and I’ve made major changes to the tables. I’d like it if the tables were completely wiped and re-created, in fact my app needs this to happen. If someone updates and has the old tables then there will be a force close.
Does anyone know the specifics of this scenario?
My tables are only for lookup, I store no user data so I dont really care about losing data on the updates.
Of course I know an option is to use some type of “version” table and check to see if I need to manually drop and create, but I was wondering if that was even needed.
Thanks.
On an update the tables are left alone. I’m going to assume you have implemented a subclass of
SQLiteOpenHelperto explain this. The way Android is able to handle version changes is through the use ofonUpgradein theSQLiteOpenHelperclass. This method is called fromSQLiteOpenHelpers constructor if the DB version is older than the version the app expects. From insideonUpgradeis where you are going to drop your old tables and create the new ones.It is important to note the way Android tells if you are using a new DB version.
That field
DATABASE_VERSIONis used, so you should use a final static int member as part of your DB implementation.Hope that helps, leave me a comment if you have questions.