Nathaniel Smith <[EMAIL PROTECTED]> wrote: > > So, my question is -- what is a simple way to reliably corrupt a > sqlite db so that "PRAGMA integrity_check" will fail? >
For the SQLite regression tests, we open the database file separately using fopen() and then write bad stuff into the middle of the file. Here is a recipe for generating some corruption that PRAGMA integrity_check will detect but which will not cause lasting damage to the database - the damage can be repaired by running REINDEX - and will not cause an SQLITE_CORRUPT error. 1. Create a new table: CREATE TABLE test1(x UNIQUE); The UNIQUE argument is important because we want an index for this test. 2. Look at the SQLITE_MASTER table to find the ROOTPAGE for this table. Use fopen() to make a copy of this page, taking care to remember that SQLite page numbers begin with 1, not 0. 3. Insert one small row into the test table: INSERT INTO test1 VALUES(1); Commit this change. 4. Overwrite the rootpage of the test table with the copy of that page that was saved in step 2. This effectively deletes the entry you just inserted but without updating the index - so that the index and the table are now out of sync. -- D. Richard Hipp <[EMAIL PROTECTED]>