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§
- Fragment
Row - One carved fragment (a Tier-2 partial row) to materialize as a row of the
rebuilt
recovered_fragmentstable. 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 itsCarvedFragmentonto this; the writer owns theSQLite-format encoding. - Rebuild
Row - One carved record to materialize as a row of the rebuilt
recovered_recordstable. The CLI maps itsCarvedRecordonto this; the writer owns theSQLite-format encoding. - Recovered
Table - 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 exactlycolumns.len()values each.
Functions§
- build_
recovered_ db - Build the bytes of a valid single-table
SQLitedatabase holding everyRebuildRowas a row ofrecovered_records. See the module docs for the schema and the bulk-load / overflow guarantees. - build_
recovered_ db_ tables - Build the bytes of a valid
SQLitedatabase 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
SQLitedatabase holding the full carved records inrecovered_recordsand, whenfragmentsisSome, the Tier-2 partial rows in a separaterecovered_fragmentstable.