SQLite

View Ticket
Login
Ticket Hash: 89b8c9ac540eb58af7c79f1b4995a44fa2d8fa59
Title: False reports of corruption after writing db with two different versions (3.7 and 3.6).
Status: Fixed Type: Code_Defect
Severity: Minor Priority: Immediate
Subsystem: B-Tree Resolution: Fixed
Last Modified: 2011-02-10 19:24:13
Version Found In: 3.7.0 - 3.7.5
Description:
Version 3.7.0 and greater may incorrectly report that an auto-vacuum capable database is corrupt if the following sequence occurs:

  #  The database is written by version 3.7.0 or greater, then
  #  The database file is written to by a version earlier than 3.7.0 and the write operation causes the database file to shrink (either because data was removed from the db in auto-vacuum mode or because "PRAGMA incremental_vacuum" was executed in incr-vacuum mode).

This leaves the database in a state where 3.7.0 and greater report that it is corrupt (and no data can be read from it). It is not actually corrupt, and all data can still be read by earlier versions.

A database can be "repaired" by vacuuming it with a version earlier than 3.7.0.

<verbatim>
   SQLite version 3.7.6
   Enter ".help" for instructions
   Enter SQL statements terminated with a ";"
   sqlite> PRAGMA auto_vacuum = 1;
   sqlite> CREATE TABLE t1(x);
   sqlite> .quit

   SQLite version 3.6.23.1
   Enter ".help" for instructions
   Enter SQL statements terminated with a ";"
   sqlite> DROP TABLE t1;
   sqlite> .quit

   SQLite version 3.7.6
   Enter ".help" for instructions
   Enter SQL statements terminated with a ";"
   sqlite> PRAGMA integrity_check;
   Error: database disk image is malformed
</verbatim>

<hr><i>drh added on 2011-02-09 18:39:32:</i><br>
The database can also be "repaired" in SQLite version 3.7.5 and later by using

   PRAGMA writable_schema=ON;

Immediately after opening the connection, and then running VACUUM (or any other
write operation) on the database.