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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/554009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:28:59  来源:igfitidea点击:

Deploying sqlite DB on iPhone app upgrade

iphonexcodesqliteapp-store

提问by 4thSpace

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

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

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?

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

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?

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

回答by Steven Fisher

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. 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_execan ATTACHstatement, which looks like this:

我还没有在 iPhone 上这样做过,但在桌面环境中,处理这个问题的最简单方法是将您的配置数据保存在一个单独的数据库中。您可以很容易地附加到多个数据库。首先打开您的主数据库,它可能应该是可以更改的数据库。然后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. For this reason, you should copy your configuration database file into the sandbox and open that copy instead of the one in your bundle.

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

(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. :)

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

回答by cdespinosa

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 的人,但如果您实际这样做,您可能希望使用“sqlite”标签而不是“mysql”标签。