• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to update database after app update

behrapps

Newbie
Dec 15, 2010
10
0
I have an app that I am developing that has a SQLLite DB that I have already created in the assets folder and when my dbprovider starts up it looks to see if the database is loaded into memory and if not writes the file to the databases folder. My problem is if I ever need to update the database, I would just do an app update with the new db in the assets folder. My question is how can I write my code to now when the dbprovider starts up that the db has changed? I can view the date/time of the db in the databases folder but haven't found a way to find the same for the db in the assets folder. Does anyone know a way to do this or even just a way for my app to know it has been updated and clear out the databases folder the first time it loads after the update? I don't want to put the db on the web because this db will rarely ever get updated and I wanted my app to not require internet since it is a business app. Any help would be appreciated.
 
I put in a table that I update with a row that contains a version level for the DB. I store the 'current' db level as a variable in the program. When I start initially, the table gets created and the current level is recorded. On later startups with a new version of the code, it pulls the db level in the database, and if it doesn't match, then I run a block of code to update the db to the current level.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones