sqlite错误 The database disk image is malformed database disk image is malformed 可解决

以下为原文。

http://www.sunnyu.com/?p=201

SQLite有一个很严重的缺点就是不提供Repair命令。
导致死亡提示database disk image is malformed
它的产生有很多种可能,比如,磁盘空间不足,还有就是写入数据过程中突然掉电等。
官方对产生原因的一些说明: http://www.sqlite.org/lockingv3.html#how_to_corrupt

sqlite  my.sqlite3
sqlite>PRAGMA integrity_check;

获得提示

*** 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

可以尝试通过简单的导出导入方式对损坏的库文件作回复。
首先导出数据

sqlite3 my.sqlite3
sqlite>.output tmp.sql
sqlite>.dump
sqlite>.quit

再倒入到一个新库中

sqlite3 mynew.sqlite3
sqlite>.read tmp.sql
sqlite>.quit

这时新建的mynew.sqlite3一般可用。

原文地址:https://www.cnblogs.com/llbofchina/p/3062852.html