I really like this approach for handling sqlite database when developing for Android but I have a question when it comes to upgrading the database during an upgrade of the application. Is this method recommended or is it so much safer to do the standard procedure (as it seem to be) with drop table/create table/insert into, within a transaction instead, in order to being able to roll back in case of failure?
A:
Is this method recommended
Is there a particular method you're talking about?
That link seems to show simple use of an SQLiteOpenHelper
which, as part of the standard API, I would say is recommended.
You can do whatever you like in the onUpgrade
method, whether it's DROP
ping tables, ALTER
ing them, or whatever.
If you want to wrap them in a transaction, that's up to you.
Christopher
2010-09-26 09:28:50
The method I was referring to is copying the database from assets folder if database haven't been created on the device/emulator yet. Look at copyDataBase() where the work is done.
Björn
2010-09-26 09:34:05
Ha, sorry. Yes, that's also a good solution when you need to import a pre-filled database. There's many other questions on this site about exactly that.
Christopher
2010-09-26 11:58:54
Alright, good to know that solution is a good alternative, also when upgrading app. I tried to search but didn't find any other good question/answers on stackoverflow. I guess I have to do another round of searching to see what's said about the subject.
Björn
2010-09-26 14:19:20