How do you determine if an .sqlite or .sqback is corrupt in Java?

戏子无情 提交于 2019-12-05 05:51:10

Run PRAGMA quick_check like a normal SQL query. The result is the same as a one-column table containing strings; for an intact database, you get a single row saying "ok", for a corrupt one, a bunch of error messages.

sqlite> pragma quick_check;
ok

after changing some bytes in the file:

sqlite> pragma quick_check;
*** in database main ***
Page 64: btreeInitPage() returns error code 11
On tree page 40 cell 23: Child page depth differs
On tree page 40 cell 24: Child page depth differs

There is no guarantee that errors will be found by this.

I would and do use

pragma integrity_check

This pragma does an integrity check of the entire database. The integrity_check pragma looks for out-of-order records, missing pages, malformed records, missing index entries, and UNIQUE, CHECK, and NOT NULL constraint errors. If the integrity_check pragma finds problems, strings are returned (as multiple rows with a single column per row) which describe the problems. Pragma integrity_check will return at most N errors before the analysis quits, with N defaulting to 100. If pragma integrity_check finds no errors, a single row with the value 'ok' is returned. (ref)

Why is this better than pragma quick_check?

The pragma is like integrity_check except that it does not verify UNIQUE constraints and does not verify that index content matches table content. (ref)

In other words, pragma integrity_check is more thorough.

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