SQLite“数据库磁盘映像格式错误” [英] SQLite "database disk image is malformed"

查看:1923
本文介绍了SQLite“数据库磁盘映像格式错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用SQLite数据库损坏的应用程序时遇到问题。之前有一个奇怪的例子,但在iOS 7.1发布后它似乎变得更加普遍。

I am having trouble with an app where the SQLite database is getting corrupted. There was the odd case of this previously, but it seems to have become a lot more common after the release of iOS 7.1.

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

I'm using the SQLite wrapper by Matteo Bertozzi that you can find here: https://github.com/ConnorD/simple-sqlite

数据库损坏并吐出错误数据库磁盘映像格式错误,一些查询可以运行,但现有数据搞砸了。

The database gets corrupted and spits out the error database disk image is malformed, some queries can be run but the existing data gets messed up.

我搜索了高低,无法找到解决方案,我希望有人在这里有一些这个想法在iOS更新后变成了一个更常见的问题。

I have searched high and low and can't find a solution, I'm hoping someone here has some ideas since this is becoming a more common issue after the iOS update.

我尝试过这些修复命令:

I've tried these repair commands:

[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的问题。

With some further digging I found this problem: Core Data and iOS 7: Different behavior of persistent store which mentions issues with SQLite after iOS7.

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

Though I have no idea how to use NSPersistentStore, so I tried running [sqlite executeNonQuery:@"pragma journal_mode = DELETE"]; and it just said SQLite Step Failed: unknown error.

还有其他人遇到此问题,还是指向了正确的方向?

Is anyone else experiencing this, or point me in the right direction?

与此同时,我觉得这个 NSPersistentStore 是我可能应该做的事情......将不得不考虑那个。

In the meantime I feel like this NSPersistentStore is something I potentially should be doing.. will have to look into that.

编辑:

从我发现你只使用 NSPersistentStore 当数据库不会更新时,我的定期更新。

From what I've found you only use NSPersistentStore when the database isn't going to be updated, which mine is regularly.

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

Here is how I open the database:

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 这种方式..?

So I assume I need to find a way to set pragma journal_mode = DELETE this way..?

编辑2:

我不相信它与 journal_mode 有关,因为我没有使用核心数据 - 回到绘图板。

I'm not convinced it's to do with the journal_mode as I'm not using Core Data - back to the drawing board.

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

The biggest flag to me is this error popping up so soon after iOs 7.1 was released, surely it can't be a coincidence.. I'll continue trying to replicate the issue on my device.

推荐答案

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

I had this problem too on iOS 7.0.6 using FMDB. I repaired it by copying to the Mac and using these commands:

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

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

My database dump was rather large at 200MB so I used Hexfiend to cut the transaction and rollback commands.

这篇关于SQLite“数据库磁盘映像格式错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆