在iphone应用程序更新期间sqlite DB待办事项 [英] sqlite DB to-do during iphone app update

查看:123
本文介绍了在iphone应用程序更新期间sqlite DB待办事项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些关于涉及sqlite db的iphone应用更新的一般性问题。

I have some general questions about iphone app updates that involves sqlite db.


  1. 随着新的更新,现有的sqlite db被一个新的副本覆盖?

  1. With the new update does the existing sqlite db get overwritten with a copy of the new one?

如果更新不涉及任何架构更改,那么用户应该能够将现有数据库与其保存的数据一起使用,对吗? (如果现有数据库没有被上面的1覆盖)

If the update doesn't involve any schema changes then the user should be able to reuse the existing database with their saved data, right? (if the existing database doesn't get overwritten from 1 above )

如果有一些架构更改,从旧数据库传输数据的最佳方法是什么进入新的?有人可以给我指导和示例代码吗?

If there are some schema changes, what's the best way to transfer data from the old database into the new one? Can some one please give me guidelines and sample code?


推荐答案


  1. 仅替换应用包内的文件。如果数据库文件位于应用程序的Documents目录中,则不会替换它。 (请注意,如果更改应用程序包中的文件,代码签名将不再有效,并且应用程序将无法启动。因此,除非您使用的是只读数据库,否则它必须位于Documents目录中。)

  1. Only files inside the app bundle are replaced. If the database file is in your app's Documents directory, it will not be replaced. (Note that if you change files inside your app bundle, the code signature will no longer be valid, and the app will not launch. So unless you are using a read-only database, it would have to be in the Documents directory.)

是。

什么是最好的取决于数据。您不会为这样的通用问题找到示例代码。首先,您需要检测您的应用程序是否使用旧的数据库版本运行。然后你需要升级它。

What's best depends on the data. You're not going to find sample code for such a generic question. First, you need to detect that your app is running with an old DB version. Then you need to upgrade it.

检查版本:


  • 您可以为新架构使用不同的文件名。如果Version2.db不存在但Version1.db不存在,请进行升级。

  • 您可以在数据库中嵌入模式版本。我有一个名为元数据的表,其中名称柱。我用它来存储一些通用值,包括 dataversion 数字。我在打开数据库时检查该号码,如果它小于当前版本,我会进行升级。

  • 您也可以使用sqlite内置的表格而不是创建表格 user_version pragma 检查并存储版本号。

  • 您可以直接检查表结构:查找是否存在列或表。

  • You could use a different file name for the new schema. If Version2.db does not exist but Version1.db does, do an upgrade.
  • You could embed a schema version in your database. I have a table called metadata with a name and value column. I use that to store some general values, including a dataversion number. I check that number when I open the database, and if it is less than the current version, I do an upgrade.
  • Instead of creating a table, you could also use sqlite's built-in user_version pragma to check and store a version number.
  • You could check the table structure directly: look for the existence of a column or table.

要升级:


  • 您可以使用一系列SQL命令进行适当的升级。您甚至可以将SQL文件作为资源存储在应用程序包中,只需将其传递给 sqlite3_exec 即可完成所有工作。 (如果出现问题,请在事务中执行此操作!)

  • 您可以通过将数据从一个数据库文件复制到新数据库来进行升级。

  • You could upgrade in place by using a series of SQL commands. You could even store a SQL file inside your app bundle as a resource and simply pass it along to sqlite3_exec to do all the work. (Do this inside a transaction, in case there is a problem!)
  • You could upgrade by copying data from one database file to a new one.

如果您的升级可能会运行很长时间(超过一秒),您应该显示一个升级屏幕,向用户解释发生了什么。

If your upgrade may run a long time (more than one second), you should display an upgrading screen, to explain to the user what is going on.

这篇关于在iphone应用程序更新期间sqlite DB待办事项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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