Wilson Yeung <[EMAIL PROTECTED]> wrote: > > Does SQLite detect database corruption? If so, what kind of > corruption is detected and how does it do so? >
SQLite does attempt to detect corruption in database files and returns SQLITE_CORRUPT when it finds it. The regression test suite for SQLite runs thousands of tests in which random binary data overwrites random small sections of a database file. These tests confirm that the corruption is detected and reported properly. However.... (1) Corruption is only detected when SQLite tries to use the corrupted section of the database. If the corruption occurs in table ABC and you are only accessing table PQR, then you will never see the SQLITE_CORRUPT error. (2) If the corruption occurs in the middle of (say) a large BLOB, the BLOB will be changed of course, but as SQLite does not store checksums or other error detecting codes on data, there is no way for SQLite to know this. (3) Corrupt detection has historically been a buggy area of SQLite. In spite of the many thousands of test cases that are run against the library, users do from time to time find creative ways to corrupt databases that lead to to segfaults. There are no outstanding issues in this area that I am aware of, but it has historically been a weakness.