gpt4 book ai didi

ios - SQLite "database disk image is malformed"

转载 作者:IT王子 更新时间:2023-10-29 06:20:56 24 4
gpt4 key购买 nike

我在使用 SQLite 数据库损坏的应用程序时遇到问题。以前有过这种奇怪的情况,但在 iOS 7.1 发布后似乎变得更加普遍。

我正在使用 Matteo Bertozzi 的 SQLite 包装器,您可以在这里找到它:https://github.com/ConnorD/simple-sqlite

数据库损坏并吐出错误database disk image is malformed,一些查询可以运行但现有数据变得困惑。

我到处搜索都找不到解决方案,我希望这里有人有一些想法,因为这在 iOS 更新后变得更加普遍。

我试过这些修复命令:

[sqlite executeNonQuery:@"pragma integrity_check"];
[sqlite executeNonQuery:@"reindex nodes"];
[sqlite executeNonQuery:@"reindex pristine"];

输出是:

SQLite Step Failed: database disk image is malformed
SQLite Prepare Failed: unable to identify the object to be reindexed
- Query: reindex nodes
SQLite Prepare Failed: unable to identify the object to be reindexed
- Query: reindex pristine`

通过进一步挖掘,我发现了这个问题:Core Data and iOS 7: Different behavior of persistent store其中提到了 iOS7 之后 SQLite 的问题。

虽然我不知道如何使用 NSPersistentStore,所以我尝试运行 [sqlite executeNonQuery:@"pragma journal_mode = DELETE"]; 它只是说 SQLite 步骤失败:未知错误

有没有其他人遇到过这种情况,或者为我指明了正确的方向?

与此同时,我觉得这个 NSPersistentStore 是我可能应该做的事情。我必须对此进行调查。

编辑:

根据我的发现,当数据库不打算更新时,您只使用 NSPersistentStore,而我的更新是定期的。

这是我打开数据库的方式:

sqlite = [[Sqlite alloc] init];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"HomeOpenDatabase8.sql"];

if (![sqlite open:writableDBPath]) {
NSLog(@"DB Not Writable");
return;
} else {
NSLog(@"All good");
}

所以我假设我需要找到一种方法来以这种方式设置 pragma journal_mode = DELETE..?

编辑 2:

我不相信这与 journal_mode 有关,因为我没有使用 Core Data - 回到绘图板。

对我来说最大的问题是这个错误在 iOs 7.1 发布后很快弹出,这肯定不是巧合。我会继续尝试在我的设备上重现这个问题。

最佳答案

我在使用 FMDB 的 iOS 7.0.6 上也遇到了这个问题。我通过复制到 Mac 并使用这些命令修复了它:

http://www.dosomethinghere.com/2013/02/20/fixing-the-sqlite-error-the-database-disk-image-is-malformed/

我的数据库转储相当大,有 200MB,所以我使用 Hexfiend 来削减事务和回滚命令。

关于ios - SQLite "database disk image is malformed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22623865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com