Android database corrupt, but can open in SQLite Manager. Recoverable?

旧时模样 提交于 2019-12-03 10:38:35

The canonical Good Way to recover a corrupt database is to dump it out as SQL and then read it back in to a new database. It's dead easy with the sqlite tool:

sqlite in.db .dump | sqlite out.db

...but, of course, you need to do it in code, and I really don't know if .dump is available from anywhere.

I'd suggest that you possibly want to look in to how it's getting corrupted in the first place --- SQLite has always been rock solid for me, although I've only ever used it on the internal storage. Can you check the FAT filesystem to see whether it's corrupt? I've seen, e.g., digital cameras which will thoroughly mangle filesystem on cards in various obscure ways...

Android deleting the database is an issue indeed.

I just realized a solution could be to use SQLJet instead of the default Android SQLite implementation.
As its name does not suggest, SQLJet is an open source Java SQLite client, and it works on Android.

In your app does you close the database before you exit the activity? Watch the logcat and check if there are any errors or warnings when you run your app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!