我遇到SQLite數據庫損壞的應用程序問題。之前有過這種奇怪的情況,但它似乎在iOS 7.1發佈後變得更加普遍。SQLite「數據庫磁盤映像格式不正確」
我使用利瑪竇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"];
輸出功率爲:
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`
依照一些另外的挖掘,我發現這個問題:Core Data and iOS 7: Different behavior of persistent store這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");
}
所以我想我需要找到一種方法來設置pragma journal_mode = DELETE
這樣..?
編輯2:
我不相信這是因爲我沒有使用Core Data
與journal_mode
做的事情 - 回到繪圖板。
對我來說最大的標誌就是這個錯誤在iOS 7.1發佈後很快出現,肯定不會是巧合。我會繼續嘗試在我的設備上覆制問題。
是否可以執行某些步驟來可靠地重現損壞? – borrrden
我自己無法複製,這是一個巨大的痛苦,但我會繼續嘗試。 我不再相信這是'journal_mode',因爲我沒有使用'Core Data',所以它回到了原點。 – Batnom
你爲什麼一直在搞雜注呢? – borrrden