sqlite数据库文件损坏的问题解决

sqlite数据库文件损坏的问题解决,第1张

概述再发生android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed异常时候,以下是解决办法:   What is an SQLITE_CORRUPT error? What does it mean for the database to be "malformed"? Why am

再发生androID.database.sqlite.sqliteDatabaseCorruptException: database disk image is malformed异常时候,以下是解决办法:

What is an sqlITE_CORRUPT error? What does it mean for the database to be "malformed"? Why am I getting this error?

AnSQLITE_CORRUPTerror 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 (seeDatabaseCorruption) 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 theatomic commitandlockingsupport in sqlite as well as in the mailing List archives.

Your can usePRAGMA integrity_checkto do a thorough but time intensive test of the database integrity.

Your can usePRAGMA quick_checkto 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然后读取数据到新的dbsqlite3 new.db.read tmp.sql.quit不过保险起见还是做好db的备份,因为一旦db文件损坏,在未知的情况下再去 *** 作此db,androID就会直接把此db给干掉(个人对androID的这种做法不太满意)。我也郁闷了很久,看log和源码才知道的。

总结

以上是内存溢出为你收集整理的sqlite数据库文件损坏的问题解决全部内容,希望文章能够帮你解决sqlite数据库文件损坏的问题解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1177420.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存