# SQLite format coverage

PageLens implements the persistent structures documented by SQLite's Database
File Format specification.

## Database header

The parser checks the 16-byte magic, page size, read/write versions, reserved
bytes, fixed payload fractions, counters, database size, freelist metadata,
schema metadata, encoding, vacuum flags, application ID, and SQLite version
fields. Schema format zero is accepted for a database that does not yet contain
a schema, including a base file whose first schema transaction is in a WAL.

## B-tree pages and records

Flags 0x02, 0x05, 0x0a, and 0x0d map to index-interior, table-interior,
index-leaf, and table-leaf pages. Page 1 begins after the 100-byte database
header. Cell pointers are offsets within the page. Payload-local sizing follows
SQLite's usable-page formulas, and the remainder is read through four-byte
next-page overflow links.

Record headers begin with a varint header size followed by serial-type varints.
The body decoder supports signed integer widths of 1, 2, 3, 4, 6, and 8 bytes;
64-bit floating point; NULL; constants zero and one; text in the declared
database encoding; and blobs.

## Freelist

A trunk begins with the next-trunk page number and leaf-pointer count, followed
by four-byte leaf page numbers. PageLens validates capacity, ranges, loops,
duplicate roles, and agreement with the count in the database header.

## WAL

The 32-byte header and each 24-byte frame header are big-endian structurally.
Checksum words are little-endian for magic 0x377f0682 and big-endian for
0x377f0683. The two checksum accumulators wrap at 32 bits. Frame checksums
continue from the header and all preceding frames.

A nonzero database-size field marks a commit. Snapshot lookup searches backward
for the latest valid page frame not newer than the selected commit. Frames
after the last commit remain visible in a WAL report but do not alter a
SnapshotView.

## Primary reference

SQLite Database File Format: https://www.sqlite.org/fileformat2.html
