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

Bat*_*nom 10 sqlite objective-c wrapper ios 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"];
Run Code Online (Sandbox Code Playgroud)

输出是:

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`
Run Code Online (Sandbox Code Playgroud)

通过进一步的挖掘,我发现了这个问题:核心数据和iOS 7:持久存储的不同行为,它提到了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");
}
Run Code Online (Sandbox Code Playgroud)

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

编辑2:

我不相信它与journal_mode我不使用的一样Core Data- 回到绘图板.

对我来说最大的一个标志就是这个错误在iOs 7.1发布后很快就出现了,这肯定不是巧合..我会继续尝试在我的设备上复制这个问题.

mal*_*hal 3

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