在应用程序的版本更新时,如何在iPhone的SQLite数据库中维护数据? [英] How to maintain data in an SQLite Database on an iPhone at a version update of the application?

查看:64
本文介绍了在应用程序的版本更新时,如何在iPhone的SQLite数据库中维护数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPhone应用程序的第一个版本中有一个SQLite数据库(位于应用程序商店中).现在,我想推出该应用程序的第二个版本,该版本中还包含一个SQLite数据库.

I have an SQLite database in the first version of my iPhone application (which is on the app store). Now I want to roll out the second version of the application, which also has an SQLite db in it.

我了解更新后,将删除SQLite数据库,然后添加新数据库.我不希望发生这种情况,因为该数据库保存了用户保存的一些信息.如果在更新时将其删除将不会很好.

I understood that upon update, the SQLite database is removed and then the new one is added. I don't want this to happen, since that database holds some information that the user has saved. It wouldn't be good if it is deleted upon update.

问题是,如何将数据从旧的SQLite(旧版本)数据库转移到新的数据库中?以及我该如何测试App Store上的版本更新过程?

任何帮助将不胜感激.谢谢.

Any help would be greatly appreciated. Thanks.

推荐答案

答案是:从一开始就在您的应用程序中实现版本控制:-)

The answer is: implement versioning in your app from the very start :-)

在这种情况下,您可以将没有版本信息的应用程序视为版本1.我要做的是将数据库的版本存储在某个地方(可能在数据库本身内部).打开数据库后,对照应用程序期望的版本检查其版本,然后根据需要进行任何模式更改并更新存储的版本号.

In this case, you can consider an app with no version information to be version 1. What I would do is store the version of the database somewhere (probably inside the database itself). When the database is opened, check its version against what version the app expects, then make any schema changes as needed and update the stored version number.

如果您还没有将数据库复制到应用程序的Documents目录中,那么这很无聊,因为无论如何它都是只读的.否则,两次更新之间将保留Documents目录的内容.

If you haven't copied the database to the app's Documents directory, then this is all moot because it would be read only anyway. Otherwise, the contents of the Documents directory are preserved between updates.

要测试更新,只需从设备上以前版本的全新副本开始.然后安装新的(构建并运行就可以了).您确实保留了旧版本的应用程序,对吗?

To test the update, just start with a fresh copy of the previous version on your device. Then install the new one (build and run will do just fine). You do keep old versions of your app, right?

这篇关于在应用程序的版本更新时,如何在iPhone的SQLite数据库中维护数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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