简体   繁体   English

在iPhone应用程序升级上部署sqlite DB

[英]Deploying sqlite DB on iPhone app upgrade

I'm using sqlite as a datasource in an iPhone app. 我在iPhone应用程序中使用sqlite作为数据源。 I have two questions regarding application upgrades. 关于应用程序升级,我有两个问题。

1.) The data is all config/nontransactional. 1.)数据都是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? 当用户获得更新的iPhone应用程序时,是否会卸载原始应用程序? If that is the case, I'm ok because the new db config data will be deployed. 如果是这种情况,我很好,因为将部署新的db配置数据。 If that isn't the case, how do I replace data? 如果不是这样,我该如何替换数据?

2.) The data is config and transactional. 2.)数据是配置和事务性的。 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. 我猜我需要在应用程序中存储INSERT和UPDATE脚本来完成此任务。 What is an efficient way to go about it? 什么是有效的方法呢?

cdespinosa has described scenario #1 well, so I'll tackle #2. cdespinosa已经很好地描述了场景#1,所以我将解决#2问题。

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. 我还没有在iPhone上完成此操作,但在桌面环境中,处理此问题的最简单方法是将配置数据保存在单独的数据库中。 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: 然后sqlite3_exec一个ATTACH语句,如下所示:

ATTACH 'filepath' AS config;

From then on, you can do something like this: 从那时起,你可以这样做:

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

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. 我的理解是,如果您写入配置数据库,应用程序将无法通过签名检查而无法启动,并且iPhone附带的SQLite版本已足够大,不支持只读标志。 For this reason, you should copy your configuration database file into the sandbox and open that copy instead of the one in your bundle. 因此,您应该将配置数据库文件复制到沙箱中并打开该副本而不是捆绑中的副本。

(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.) (当然,您可以使用SQL并将值从一个数据库复制到另一个数据库。但是如果您已经将整个配置数据库复制到沙箱中......那么您应该...那么这只是一个额外的步骤。请附上。)

I hope someone else can provide you with more details. 我希望其他人能为您提供更多细节。 :) :)

When the user upgrades the app, the old app bundle is uninstalled and the new app bundle is installed, but the user data associated with the app bundle is intact. 当用户升级应用程序时,将卸载旧的应用程序包并安装新的应用程序包,但与应用程序包关联的用户数据完好无损。

So your choices are to a) leave your data in the app bundle (it'll be replaced automatically) or b) unilaterally copy it to the user data area on first run (so you'll intentionally replace it on upgrade). 因此,您的选择是:a)将数据保留在应用程序包中(它将自动替换)或b)在首次运行时单方面将其复制到用户数据区域(因此您将在升级时有意替换它)。

I'll leave #2 to a sqlite-knowledgable person, but you may want to use the "sqlite" tag instead of the "mysql" tag if that's what you're actually doing. 我会把#2留给一个知识渊博的人,但你可能想要使用“sqlite”标签而不是“mysql”标签,如果你正在做的那样的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM