Don't want to replace the old database when app is updated

后端 未结 3 1715
面向向阳花
面向向阳花 2021-01-03 13:21

In my app I am using sqlite database 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 re

相关标签:
3条回答
  • 2021-01-03 13:30

    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.

    0 讨论(0)
  • 2021-01-03 13:31

    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:

    1. Store a sequence of sql scripts in resources.
    2. I have a file which references the list of scripts to run.
    3. For a new DB, it just runs those scripts in order.
    4. As each script runs, I record in a tracking metadata table the last script that ran.
    5. 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.

    0 讨论(0)
  • 2021-01-03 13:46

    @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.

    0 讨论(0)
提交回复
热议问题