pub struct Reader<S: Source> { /* private fields */ }Expand description
A SQLite database file, opened for reading.
Implementations§
Source§impl<S: Source> Reader<S>
impl<S: Source> Reader<S>
Sourcepub fn survey_table(&self, object: &SchemaObject) -> Result<TableSurvey>
pub fn survey_table(&self, object: &SchemaObject) -> Result<TableSurvey>
Read every row of a table and report what each column holds.
This is the first of the import’s two passes: it writes nothing and its whole purpose is to let the second pass know the shape of what it is about to write, and to let a caller see every problem at once rather than the first one after ten minutes of work.
Source§impl<S: Source> Reader<S>
impl<S: Source> Reader<S>
Sourcepub fn open(source: S) -> Result<Reader<S>>
pub fn open(source: S) -> Result<Reader<S>>
Read and validate the header, then work out how many pages the file really has.
pub fn header(&self) -> &Header
Sourcepub fn page_count(&self) -> u32
pub fn page_count(&self) -> u32
Pages in the database. Page numbers run from 1 to this value.
Sourcepub fn read_page(&self, number: u32) -> Result<Vec<u8>>
pub fn read_page(&self, number: u32) -> Result<Vec<u8>>
Read one whole page, reserved trailer included.
Sourcepub fn btree_page(&self, number: u32) -> Result<BtreePage>
pub fn btree_page(&self, number: u32) -> Result<BtreePage>
Read a page and parse it as a b-tree page.
Sourcepub fn cell(&self, page: &BtreePage, index: usize) -> Result<Cell>
pub fn cell(&self, page: &BtreePage, index: usize) -> Result<Cell>
Parse one cell of a b-tree page, following overflow pages so the payload comes back whole.
Sourcepub fn schema(&self) -> Result<Schema>
pub fn schema(&self) -> Result<Schema>
Read the database’s own description of itself.
The schema lives in a table rooted at page 1, so this is an ordinary scan; it is separate only because everything else in the file is found through it.
Sourcepub fn table_scan(&self, root: u32) -> Result<TableScan<'_, S>>
pub fn table_scan(&self, root: u32) -> Result<TableScan<'_, S>>
Walk the table b-tree rooted at root, yielding rows in rowid order.
The walk is lazy: a table larger than memory is read a page at a time, and a caller that only wants the first row only pays for the pages down to it.
Sourcepub fn index_scan(&self, root: u32) -> Result<IndexScan<'_, S>>
pub fn index_scan(&self, root: u32) -> Result<IndexScan<'_, S>>
Walk the index b-tree rooted at root, yielding entries in key
order.
This reads real indexes and, because a without rowid table is an index b-tree holding whole rows, those tables too.
Sourcepub fn decode_record(&self, payload: &[u8]) -> Result<Vec<SqliteValue>>
pub fn decode_record(&self, payload: &[u8]) -> Result<Vec<SqliteValue>>
Decode a record with the encoding this database uses.
The same as the free function, minus the chance of passing the wrong encoding: this one reads it off the header in hand.
Sourcepub fn rows(&self, root: u32) -> Result<Rows<'_, S>>
pub fn rows(&self, root: u32) -> Result<Rows<'_, S>>
Rows of a table, whichever kind of table it is.
Which walk applies is not a matter of taste: a rowid table is a table b-tree and a without rowid table is an index b-tree, and the root page says which one it is. Reading that off the page rather than off the create statement means this works before any sql has been parsed, and cannot disagree with the file.