Reputation: 279
My SQLite database is getting corrupted. It became more common since iOS 7.1. I'm using the SQLite wrapper by Matteo Bertozzi. The error:
database disk image is malformed
Some queries can be run but the existing data gets messed up. 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`
This question mentions issues with SQLite after iOS 7. I tried [sqlite executeNonQuery:@"pragma journal_mode = DELETE"];
and it just said:
SQLite Step Failed: unknown error
I've found you only use NSPersistentStore
when the database isn't going to be updated, which mine is regularly. 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");
}
Do I need to set pragma journal_mode = DELETE
this way? I'm not convinced it's to do with journal_mode
as I'm not using Core Data.
Upvotes: 12
Views: 54531
Reputation: 125
sqlite: database disk image is malformed
In your case, you may consider checking your Integrity Check results. That's how I've solved my problem.
Upvotes: -1
Reputation: 30573
I had this problem too on iOS 7.0.6 using FMDB. I repaired it by copying to the Mac and using these commands:
My database dump was rather large at 200MB so I used Hexfiend to cut the transaction and rollback commands.
Upvotes: 3