Is the onUpgrade
method of SQLiteOpenHelper
ever called? If so, when is it called and by what? Or if it is not called by developers, then why is it there? What should be done in the method I have seen examples where it drops all the tables, but then a comment says that dropping all the tables is NOT what you should do.
views:
55answers:
1
+3
A:
Hi,
It is called when you construct a SQLiteOpenHelper with version newer than the version of the opened database. What to do depends on the changes in the database that are made between the old and new versions. The only case when you don't drop a changed table is when the change is noting more than an added column. Then you can use ALTER TABLE statement to add the new column to the table signature.
ognian
2010-07-02 07:17:41
The change could also be adding new tables, in which case you might not drop any existing tables.
CommonsWare
2010-07-02 07:49:38
But how would yo know ahead of time that you will modify a table? Or do you just have to change the method every time you publish an update.
Mohit Deshpande
2010-07-02 13:26:11
You know when you're changing the database and add another case in onUpgrade. So when the user updates the app, the SQLiteOpenHelper knows that the existing database is obsolete and takes the according action. Check out a piece of Android source for reference: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
ognian
2010-07-02 13:42:53