在 iPhone 应用程序升级上部署 sqlite DB [英] Deploying sqlite DB on iPhone app upgrade

查看:36
本文介绍了在 iPhone 应用程序升级上部署 sqlite DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iPhone 应用程序中使用 sqlite 作为数据源.我有两个关于应用升级的问题.

I'm using sqlite as a datasource in an iPhone app. I have two questions regarding application upgrades.

1.) 数据都是配置/非事务性的.意思是,它是只读的.当我更新/添加配置数据时,我会为应用程序发布升级.当用户获得更新的 iPhone 应用程序时,原始应用程序是否会被卸载?如果是这种情况,我没问题,因为将部署新的 db 配置数据.如果不是这种情况,我该如何替换数据?

1.) The data is all config/nontransactional. Meaning, it is readonly. When I update/add config data, I'll issue an upgrade for the app. When a user gets an updated iPhone app, does the original get uninstalled? If that is the case, I'm ok because the new db config data will be deployed. If that isn't the case, how do I replace data?

2.) 数据是配置和事务性的.这意味着用户可以将数据保存到数据库中.当用户升级到新版本的应用程序时,我想维护他们现有的数据但替换所有配置数据.我猜我需要在应用程序中存储 INSERT 和 UPDATE 脚本才能完成此操作.什么是有效的方法?

2.) The data is config and transactional. Meaning the user can save data into the db. When the user upgrades to a new version of the app, I want to maintain their existing data but replace all config data. I'm guessing I'd need to have INSERT and UPDATE scripts stored within the app to accomplish this. What is an efficient way to go about it?

推荐答案

cdespinosa 已经很好地描述了场景 #1,所以我将解决 #2.

cdespinosa has described scenario #1 well, so I'll tackle #2.

我还没有在 iPhone 上这样做过,但在桌面环境中,最简单的处理方法是将您的配置数据保存在一个单独的数据库中.您可以很容易地附加到多个数据库.首先打开您的主数据库,它可能应该是可以更改的数据库.然后sqlite3_exec一个ATTACH语句,如下所示:

I haven't done this on the iPhone yet, but on a desktop environment the easiest way to handle this is to keep your configuration data in a separate database. You can attach to multiple databases rather easily. Start by opening your main database, which should probably be the database that can change. Then sqlite3_exec an ATTACH statement, which looks like this:

ATTACH 'filepath' AS config;

从那时起,您可以执行以下操作:

From then on, you can do something like this:

SELECT * FROM UserTableName;
SELECT * FROM config.ConfigurationTableName;

据我所知,如果您写入配置数据库,应用程序将无法通过签名检查并且无法启动,而且 iPhone 中包含的 SQLite 版本已经足够旧,不支持只读标志.出于这个原因,您应该将配置数据库文件复制到沙箱中,然后打开该副本而不是包中的副本.

It's my understanding that if you write to the configuration database the application will fail a signature check and won't start, and the version of SQLite included with the iPhone is old enough to not support the read only flag. For this reason, you should copy your configuration database file into the sandbox and open that copy instead of the one in your bundle.

(当然,您可以使用 SQL 并将值从一个数据库复制到另一个数据库.但是如果您已经将整个配置数据库复制到您的沙箱中...并且您应该...那么这只是一个额外的步骤.只需附加.)

(You can, of course, use SQL and copy the values from one database to another. But if you're already copying the entire configuration database to your sandbox... and you should be... then that's just an extra step. Just attach.)

我希望其他人可以为您提供更多详细信息.:)

I hope someone else can provide you with more details. :)

这篇关于在 iPhone 应用程序升级上部署 sqlite DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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