SQLite"数据库磁盘映像格式错误"

时间:2014-03-25 01:32:46

标签: ios objective-c sqlite wrapper ios7.1

我在使用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 Step Failed: unknown error

是否有其他人遇到过这种情况,或者指出我的方向是正确的?

与此同时,我觉得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发布后很快就出现了这个错误,肯定不会是巧合..我会继续尝试在我的设备上复制这个问题。

2 个答案:

答案 0 :(得分:2)

我在使用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来削减事务和回滚命令。

答案 1 :(得分:0)

sqlite: database disk image is malformed

对于您而言,您可以考虑检查完整性检查结果。这就是我解决问题的方式。

相关问题