1

My requirement is quite different than the normal scenario. I want to delete old database and copy new database on application update. I search the same on different forums and everyone saying that to run update scripts for that. But It's not fit with my requirements. My client want to delete the old and copy the new database for each release. Because our client can update any application version at a time.

It would be great if there is an alternative to do this on application update.

Note: Our application is not available on Google play store so We are updating application programmatically. If any new version available for user than we are prompting them with new version available. And in background we are downloading new apk file and re-direct user to INSTALL intent once download will complete.

2 Answers2

0

Why don't you run a SELECT statement of all your tables put them in a public shared txt file and then when new version installed read the file and run an insert script EDIT delete your db with the above instruction

context.deleteDatabase(DATABASE_NAME);
Nadir Belhaj
  • 11,953
  • 2
  • 22
  • 21
  • Hi Nadir, I don't want any data of old database. I just want to replace old database with new one on update. – Binita Shah Sep 12 '14 at 06:54
  • why don't you just delete the old database ? – Nadir Belhaj Sep 12 '14 at 06:55
  • Yeah. I got your point. But what is the suitable method to do that? As we are updating scripts on OnUpgrade() method of datahelper class. But we can not delete the db. And without deleting db we can not update new one. – Binita Shah Sep 12 '14 at 08:25
0

Why don't you use the number version of your database ?

My client want to delete the old and copy the new database for each release. Because our client can update any application version at a time.

=> it will exactly do what you need (or I don't exactly understand >_<)
You increment it in your new released version of application then the SQLOpenHelper will run the onUpgrade method. You just have to write your upgrade script to be executed.
You can read this answer for more details

Community
  • 1
  • 1
LE GALL Benoît
  • 7,159
  • 1
  • 36
  • 48