SQLite出现database disk image is malformed(11)的处理

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一般可用。

原文地址:http://www.sunnyu.com/?p=201

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能