Skip to main content

Module rebuild

Module rebuild 

Source
Expand description

Pure-Rust writer that rebuilds a valid SQLite database file from carved deleted records (the inverse of the reader in crate).

build_recovered_db takes a set of RebuildRows and returns the bytes of a single-table SQLite database (recovered_records) holding one row per carved record, each cell stored in its native storage class — an INTEGER/REAL/TEXT/BLOB is written as itself, so a recovered BLOB is preserved losslessly rather than stringified. The table b-tree is bulk loaded: leaves are packed in rowid order and interior pages built bottom-up, because every row is known up front (no insertion/splitting). Cells larger than the usable page size spill onto overflow-page chains per the file format (§1.6), so a large recovered BLOB/TEXT survives intact.

build_recovered_db_with_fragments additionally emits a second table, recovered_fragments, in the same file — the Tier-2 partial rows kept structurally separate from the full rows (a fragment is never mixed into recovered_records). Both tables are built from one generic internal table spec, so the page allocation, bulk-load and overflow handling are shared; passing no fragment set reproduces the single-table bytes exactly.

The output re-opens with crate::Database::open (the independent reader) and is read identically by the real sqlite3 engine — the writer’s two oracles. No new dependencies, no unsafe, panic-free.

Structs§

FragmentRow
One carved fragment (a Tier-2 partial row) to materialize as a row of the rebuilt recovered_fragments table. A fragment has no rowid (it was clobbered) and only a subset of its columns survived; each survivor is placed at its own native column index, with every other column left NULL. The CLI maps its CarvedFragment onto this; the writer owns the SQLite-format encoding.
RebuildRow
One carved record to materialize as a row of the rebuilt recovered_records table. The CLI maps its CarvedRecord onto this; the writer owns the SQLite-format encoding.
RecoveredTable
One table to materialize in a multi-table rebuilt database (build_recovered_db_tables): an arbitrary (SQL-identifier-quoted) table name, its full ordered column names, and its rows already projected to exactly columns.len() values each.

Functions§

build_recovered_db
Build the bytes of a valid single-table SQLite database holding every RebuildRow as a row of recovered_records. See the module docs for the schema and the bulk-load / overflow guarantees.
build_recovered_db_tables
Build the bytes of a valid SQLite database holding N arbitrary tables, each with its own name and column set, every identifier safely quoted.
build_recovered_db_with_fragments
Build the bytes of a valid SQLite database holding the full carved records in recovered_records and, when fragments is Some, the Tier-2 partial rows in a separate recovered_fragments table.