Don't want to replace the old database when app is updated
In my app I am using sqlite dat开发者_如何学Cabase I don't want to replace an existing database when app is updated in app store.
Will it replace with new database? Or will it remain the same database?
@Ankit: Hi..
Answer is NO it will not replace the database it will remain the same old database for the users who are aready using previous version of your app and then they just download and install the new version of the app without deleting the previous version.
It will replace database on App Store but it does not replace the database by default if the user is using previous version of your app. If database already exists then it does not replace the database procedure
We have to make a database upgrade procedure where in we have to check some flag or the version number in database if provided and based on that we have to create a database upgrade procedure.
You have to make the changes in database using database upgrade procedure and make alterations into existing tables such as adding or deleting a column or may be changing the structure of the table using SQL Queries.
Then you have to finally update the version number or some flag in the database which would let it know that the database is already upgraded so it should not run the same procedure every time when application loads.
Also it is important that you take care of the existing data that the user has stored in his/her database. It should not be deleted.
Feel free to contact me if you need more help.
Hope this helps.
The next time your new app connects to the database, you will have to detect that it needs to be updated, then you need to run the series of sql commands or scripts against it to pull it up (and hopefully in a background thread async).
What my sqlite wrapper does:
- Store a sequence of sql scripts in resources.
- I have a file which references the list of scripts to run.
- For a new DB, it just runs those scripts in order.
- As each script runs, I record in a tracking metadata table the last script that ran.
- When the app is updated (or during my developement), when connecting, it detects the latest script is not the one in the table. It then iterates on the scripts and only runs the ones after the one that was already run.
That servers me on updates but also on day to day development without throwing away the data constantly.
it will replace with new database , because when you create binary for your app it will be build with new database.
if you want to do it with old database , you have to create build with old database in your app.
精彩评论