ios SQLite“数据库磁盘映像格式错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22623865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:48:13  来源:igfitidea点击:

SQLite "database disk image is malformed"

iosobjective-csqlitewrapperios7.1

提问by Batnom

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 数据库损坏的应用程序时遇到问题。以前有这种奇怪的情况,但在 iOS 7.1 发布后似乎变得更加普遍。

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

我正在使用Matteo Bertozzi的 SQLite 包装器,你可以在这里找到: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.

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

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.

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

I've tried these repair commands:

我试过这些修复命令:

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

And the output was:

输出是:

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`

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

通过进一步挖掘,我发现了这个问题:Core Data and iOS 7: Different behavior of persistent store其中提到了 iOS7 之后的 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.

虽然我不知道如何使用NSPersistentStore,所以我尝试运行[sqlite executeNonQuery:@"pragma journal_mode = DELETE"];,它只是说SQLite Step Failed: unknown error

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

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

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

与此同时,我觉得这NSPersistentStore是我可能应该做的事情……我必须研究一下。

edit:

编辑:

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

从我发现的内容来看,您仅NSPersistentStore在不打算更新数据库时使用,而我的数据库经常更新。

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");
}

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

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

edit 2:

编辑2:

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

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

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

回答by malhal

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

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

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

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

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

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

回答by LysanderM

sqlite: database disk image is malformed

sqlite:数据库磁盘映像格式错误

In your case, you may consider checking your Integrity Checkresults. That's how I've solved my problem.

在您的情况下,您可以考虑检查您的完整性检查结果。这就是我如何解决我的问题。