iOS - 在更新到新版本时保留旧的sqlite数据库 [英] iOS - Keep the old sqlite database while updating to new version

查看:480
本文介绍了iOS - 在更新到新版本时保留旧的sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些其他问题,但我没有得到任何明确的想法如何保持数据从旧的数据库,而应用程序更新在ios。



案例1 :
我可以保留旧数据库吗?



如果情况1是YES:
我可以插入新列或在旧数据库中进行任何更改并且它是否安全?



如果case 1是NO:
我可以在新数据库中获取旧的数据库数据吗?将会删除旧数据库吗?



情况2:如果我给新数据库不同的名称(它将包含在bundle中)?如果给一个新的名称保留旧的数据库,我可以编程删除旧的数据库?



最好的做法是什么?为数据库文件指定一个新名称以保留旧数据库,然后将旧数据库复制到新数据库并删除旧数据库文件?


解决方案

情况1:我可以保留旧数据库吗?



是,更新应用程序不会删除存储的数据库文件文档目录。



如果案例1是:我可以插入新列或在列中进行任何更改旧数据库,它会安全吗?



这将取决于您的实现。您可以使用 ALTER TABLE 查询添加或删除列。您需要处理代码中的新更改,否则可能会导致问题。
添加列不会在正常情况下导致任何问题(取决于您的插入查询语句和新字段约束)


I've found some other question but I didn't get any clear idea how to keep the data from old database while application update in ios.

Case 1: Can I keep the old database?

if Case 1 is YES: Can I insert new column or doing any changes in the old database and will it be safe?

if case 1 is NO: Can I get the old database data in new database? Will the old database will be removed?

Case 2: If I give a different name to new data base (it'll be included in bundle)? If giving a new name keeps the old database can I delete the old database programatically?

What will be the best practice? Give a new name to database file for keeping the old one and then copy the old to to new database and delete the old database file? Just start using the old one?

Looking for help.. :)

解决方案

Case 1: Can I keep the old database?

Yes, updating your application won't delete the database file stored in the documents directory. (But if it is in your bundle, it'll be removed)

if Case 1 is YES: Can I insert new column or doing any changes in the old database and will it be safe?

That'll depend on your implementation. You can use ALTER TABLE query for adding or removing column. You need to handle the new changes in your code, else it can cause problems. Adding a column won't cause any issues in normal scenarios (Depends on your insert query statements and new field constraints)

这篇关于iOS - 在更新到新版本时保留旧的sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆