SQLite

View Ticket
Login
2011-02-20
03:40
Do not report the database corruption if the the db size header field is greater than the file size on disk unless the two change-counter header fields are identical. Fix for ticket [89b8c9ac54]. Backport by cherrypick of [00c4596f0b270]. (check-in: e2616004 user: drh tags: branch-3.7.4)
2011-02-10
19:24 Fixed ticket [89b8c9ac]: False reports of corruption after writing db with two different versions (3.7 and 3.6). plus 1 other change (artifact: 4ff25986 user: drh)
2011-02-09
18:39 Ticket [89b8c9ac]: 3 changes (artifact: 58f6afac user: drh)
18:20 Ticket [89b8c9ac]: 2 changes (artifact: a149ec4f user: dan)
18:19
Do not report corruption if the the db size header field is greater than the file size on disk unless the two change-counter header fields are identical. Fix for ticket [89b8c9ac54]. (check-in: 00c4596f user: dan tags: trunk)
18:08 New ticket [89b8c9ac] False reports of corruption after writing db with two different versions (3.7 and 3.6).. (artifact: c3bfe79f user: dan)

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:
  1. The database is written by version 3.7.0 or greater, then
  2. 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.

   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

drh added on 2011-02-09 18:39:32:
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.