Android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed
2016-09-19 18:05
603 查看
sqlite数据库文件损坏的问题
What is an SQLITE_CORRUPT error? What does it mean for the database to be "malformed"? Why am I getting this error?
An SQLITE_CORRUPT error is returned when SQLite detects an error in the structure, format, or other control elements of the database
file.
SQLite does not corrupt database files, except in the case of very rare bugs (see DatabaseCorruption) and even then
the bugs are normally difficult to reproduce. Even if your application crashes in the middle of an update, your database is safe. The database is safe even if your OS crashes or takes a power loss. The crash-resistance of SQLite has been extensively studied
and tested and is attested by years of real-world experience by millions of users."
That said, there are a number of things that external programs or bugs in your hardware or OS can do to corrupt a database file. Details can be found in the discussions on the atomic
commit and locking support in SQLite as well as in the mailing list archives.
Your can use PRAGMA integrity_check to do a thorough but time intensive test of the database integrity.
Your can use PRAGMA quick_check to do a faster but less thorough test of the database integrity.
Depending how badly your database is corrupted, you may be able to recover some of the data by using the CLI to dump the schema and contents to a file and then recreate. Unfortunately, once humpty-dumpty falls off the wall, it is generally not possible to
put him back together again.
最近研究发现,当磁盘空间写满或写入了格式不正确的数据或在操作db过程中内存溢出,那么.db文件的镜像就会被破坏,这种情况下再去执行有关此db的操作,android就会把该db文件删除掉,如果db文件损坏了,可在adb shell下恢复其数据,做法如下:
sqlite3 old.db(注:损坏的db文件)
.output tmp.sql
.dump
.quit
然后读取数据到新的db
sqlite3 new.db
.read tmp.sql
.quit
不过保险起见还是做好db的备份,因为一旦db文件损坏,在未知的情况下再去操作此db,android就会直接把此db给干掉(个人对android的这种做法不太满意)。我也郁闷了很久,看log和源码才知道的。
What is an SQLITE_CORRUPT error? What does it mean for the database to be "malformed"? Why am I getting this error?
An SQLITE_CORRUPT error is returned when SQLite detects an error in the structure, format, or other control elements of the database
file.
SQLite does not corrupt database files, except in the case of very rare bugs (see DatabaseCorruption) and even then
the bugs are normally difficult to reproduce. Even if your application crashes in the middle of an update, your database is safe. The database is safe even if your OS crashes or takes a power loss. The crash-resistance of SQLite has been extensively studied
and tested and is attested by years of real-world experience by millions of users."
That said, there are a number of things that external programs or bugs in your hardware or OS can do to corrupt a database file. Details can be found in the discussions on the atomic
commit and locking support in SQLite as well as in the mailing list archives.
Your can use PRAGMA integrity_check to do a thorough but time intensive test of the database integrity.
Your can use PRAGMA quick_check to do a faster but less thorough test of the database integrity.
Depending how badly your database is corrupted, you may be able to recover some of the data by using the CLI to dump the schema and contents to a file and then recreate. Unfortunately, once humpty-dumpty falls off the wall, it is generally not possible to
put him back together again.
最近研究发现,当磁盘空间写满或写入了格式不正确的数据或在操作db过程中内存溢出,那么.db文件的镜像就会被破坏,这种情况下再去执行有关此db的操作,android就会把该db文件删除掉,如果db文件损坏了,可在adb shell下恢复其数据,做法如下:
sqlite3 old.db(注:损坏的db文件)
.output tmp.sql
.dump
.quit
然后读取数据到新的db
sqlite3 new.db
.read tmp.sql
.quit
不过保险起见还是做好db的备份,因为一旦db文件损坏,在未知的情况下再去操作此db,android就会直接把此db给干掉(个人对android的这种做法不太满意)。我也郁闷了很久,看log和源码才知道的。
相关文章推荐
- Android编程之SparseArray<E>详解
- Android传感器的使用
- 安卓版本更新的逻辑
- 大牛们是怎么阅读 Android 系统源码的?
- Android:JS调用安卓方法介绍
- Android动画深入分析
- Android第一行代码学习笔记四----数据存储
- Android 游戏开发之 数独游戏
- android 一个 textview 设置不同的字体大小和颜色
- Android的消息机制
- Android的线程和线程池
- Android动态改变button顶部图片即drawableTop属性
- Android中的Drawable
- android:ToolBar的使用
- Android 中TextView部分文字颜色、点击跳转设置
- android 可拖动控件 ontouchevent
- Android 控件之ListView 的简单使用
- Android.mk详解
- Android弹出式对话框AlertDialog中的EditText自动打开软键盘
- android调用原生剪裁界面裁剪图片