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

后端 未结 3 1270
北海茫月
北海茫月 2021-02-13 11:02

In the latest two weeks, without releasing an update to my app, I have started getting a bunch of reports with corrupted databases. Below is the stacktrace. Android cannot open

相关标签:
3条回答
  • 2021-02-13 11:42

    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.

    0 讨论(0)
  • 2021-02-13 11:48

    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.

    0 讨论(0)
  • 2021-02-13 11:52

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

    0 讨论(0)
提交回复
热议问题