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

I have been given a directory of directories, each of which contains a collection of .sqlite and .sqback files that I must parse.

The problem is that I believe that some of these files get corrupted when I receive them because I get the error: ERR: [SQLITE_CORRUPT] The database disk image is damaged (the image of the database disk is distorted) on my console when I try them process. This only happens with some of the files. I highlighted a few and tried to run my program on fresh copies of these bad files individually, and they cause errors. Most files are fine though :)

I realized that there is a chance that I can actually get corrupt files to start with this, so I would like to determine a way before trying to analyze them, which files are good and which are not.

I am writing in Java. I'm only interested in checking sqlite and sqback, since I know that my parser is working. I am reusing it from a previous project.

Hint? Suggestions? The answers?

Thank you very much for the transfer of knowledge.

+7
source share
1 answer

Run PRAGMA quick_check as a regular SQL query. The result is the same as a single-column table containing rows; for an intact database you get one line with the inscription "ok", for a damaged 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.

+5
source

All Articles