SQLite有一個很嚴重的缺點就是不提供Repair命令。
致使死亡提示database disk image is malformed
它的產生有不少種可能,好比,磁盤空間不足,還有就是寫入數據過程當中忽然掉電等。
官方對產生緣由的一些說明:http://www.sqlite.org/lockingv3.html#how_to_corrupthtml
sqlite my.sqlite3 sqlite>PRAGMA integrity_check;
得到提示sql
*** in database main *** Page 1518: btreeInitPage() returns error code 11 On tree page 1566 cell 2: Child page depth differs On tree page 1566 cell 3: Child page depth differs SQL error: database disk image is malformed
能夠嘗試經過簡單的導出導入方式對損壞的庫文件做回覆。
首先導出數據ui
sqlite3 my.sqlite3 sqlite>.output tmp.sql sqlite>.dump sqlite>.quit
再倒入到一個新庫中code
sqlite3 mynew.sqlite3 sqlite>.read tmp.sql sqlite>.quit
這時新建的mynew.sqlite3通常可用。orm