I have been given a directory of directories each containing a collection of .sqlite and .sqback files that I must parse.
The problem is that I believe some of these files to be corrupt when I receive them because I get the error: ERR: [SQLITE_CORRUPT] The database disk image is malformed (database disk image is malformed) on my console when I try to process them. This only happens with some of the files. I have isolated a few and tried running my program on fresh copies of these bad files individually and they cause errors. Most of the files are fine though :)
I realized that there is a chance that I may indeed be given corrupt files to begin with so I would like a way to determine, prior to trying to parse them, which files are good and which are not.
I am writing in Java. I am only interested in the sqlite and sqback validation as I know my parser works. I am reusing it from a previous project.
Hint? Suggestions? Answers?
Many Thanks for the knowledge transfer.
To verify that you're truly suffering from database corruption, enter the following command into the shell: sqlite> PRAGMA integrity_check; If the response is anything other than ok, the database is integrity checks have failed and needs to be repaired.
An SQLite database is highly resistant to corruption. If an application crash, or an operating-system crash, or even a power failure occurs in the middle of a transaction, the partially written transaction should be automatically rolled back the next time the database file is accessed.
Download and configure Kernel SQLite Database recovery on your system. Start the tool, and the home screen will appear on the screen. Click Open to select the corrupt . db file you want to repair, and click Recover.
If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With