SQLite“数据库磁盘映像格式不正确”
我遇到SQLite数据库被损坏的应用程序的问题。 以前有过这种奇怪的情况,但在iOS 7.1发布之后,它似乎已经变得更加普遍了。
我使用Matteo Bertozzi的SQLite包装,你可以在这里find: https : //github.com/ConnorD/simple-sqlite
数据库被破坏,并吐出错误database disk image is malformed
,一些查询可以运行,但现有的数据会搞砸。
我search了高和低,并找不到解决scheme,我希望有人在这里有一些想法,因为这是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`
随着一些进一步的挖掘,我发现这个问题: 核心数据和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"); }
所以我想我需要find一种方法来设置pragma journal_mode = DELETE
这种方式..?
编辑2:
我不相信这是做journal_mode
因为我不使用Core Data
– 回到绘图板。
对我来说最大的标志就是这个错误在iOS 7.1发布后不久就会popup,肯定不会是巧合。我会继续尝试在我的设备上复制这个问题。
我使用FMDB在iOS 7.0.6上也有这个问题。 我修复它通过复制到Mac和使用这些命令:
我的数据库转储是相当大的200MB,所以我用Hexfiend削减事务和回滚命令。