I'm writing an Android app and extending the SqliteOpenHelper class in order to access, create and upgrade the database. In older versions of our app we were saving a domain name to the database. In future versions we want to make a change so that we save a fully qualified url instead of a domain name. (e.g. used to save "example" now want to save "www.example.com"). One requirement is that we not drop any tables during the upgrade so dropping the table that holds this value and then writing the new value as a fully qualified url after the upgrade is not an option.
I know how to alter tables and such on database upgrade, but I'm wondering if there's a way to upgrade the value of data in the database (even better if it can be done conditionally) during an upgrade.
I searched through Sqlite documentation but couldn't find what I was looking for.
One idea I had was to do a query in the onUpgrade() method of SqliteOpenHelper. So something like:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
for (int i = oldVersion; i < newVersion; i++) {
if (oldVersion == VERSION_SAVING_DATA_AS_DOMAIN) {
//Query database for domain
//Convert domain to fully qualified url
//Write fully qualified url to database
//Do database upgrade
}
}
}
Not sure if the strategy shown above is bad practice or if there is a more obvious way of fixing this that I'm not thinking of.