Expand description
Pure-Rust reader for scrambled SAP SQL Anywhere 17 database files (format 3.201.12), without a database server.
Database::open reads a file, recovers the key that scrambles its pages,
and loads the system catalog. Each table then yields its schema, keys,
indexes, and rows as typed values:
use sa17::{Columns, Database};
let database = Database::open("garden.db")?;
let plants = database.table("plants")?;
let columns = Columns::new(plants.definition(), ["name", "height"])?;
for row in plants.scan(&columns) {
let row = row?;
let (name, height): (&str, Option<f64>) = (row.read("name")?, row.read("height")?);
println!("{name}: {height:?}");
}A program can work at any of three layers:
- A
DatabaseprovidesTables, and each table streamsRows. Every stored row carries itsRowAddress(page number and slot index). Database::storeexposes the underlyingPageStore, which also opens on its own. APageof rows gives the rawRecordof each slot.PageStore::keyandPageStore::storedexpose the recoveredStoreKeyand the raw bytes of each page.
Code that reads tables can accept a Source (implemented by Database)
so callers can wrap or substitute a database behind a uniform interface.
Reading never modifies the file.
§Scope and limitations
The reader supports scrambled SQL Anywhere 17 page stores (format 3.201.12, 4096-byte pages):
- A file with another format version or another page size is refused with
Error::Format. - Pages must use the additive-progression page cipher. Unscrambled files and
password-encrypted files are refused with
Error::NoKey. - Text columns must use Windows-1252 or UTF-8. Other encodings fail with
Error::UnsupportedEncoding. XML,NCHAR,UNIQUEIDENTIFIER, andTIMESTAMP WITH TIME ZONEcolumns appear asDataType::Unknownand read onlyNULL; a non-null value in such a column returns an error.- Views, global temporary tables, and text-index tables expose their catalog
definitions only.
TableDefinition::stores_rowsdistinguishes them from tables that store rows. - Indexes are read from the catalog, not from index B-tree pages. Rows are
fetched by
RowAddressor by scanning the table. - The entire file is held in memory. Decompressed long values are bounded to
16 MiB by default; override this with
OpenOptions::longest_value.
What the format alone cannot guarantee:
- A file copied while a database server had it open may lack uncommitted or
uncheckpointed changes stored in the separate transaction log (
.tlg), which is not read. Two flag bits (0x20and0x40) in the superblock are observed in some files with unknown meaning. - Each row stores a single byte for its schema version. If a table was altered more than 255 times, older rows wrap around modulo 256.
- Extension pages of
ISYSTABare not listed in the catalog and are identified from their own page headers.
Re-exports§
pub use chrono;
Modules§
- calendar
- The engine’s calendar: the first and the last
DATE,TIMEandTIMESTAMPthat a database can hold.
Structs§
- Column
- A column as the catalog describes it.
- Columns
- Columns of one table, chosen once by their names or their positions.
- Database
- A database file with its key found and its catalog read.
- Decimal
- An exact decimal number: a whole number of units of a power of ten.
- Foreign
Key - A foreign key as the catalog describes it.
- Format
Version - The version of the file format, which the first page names.
- Identity
- What tells one database file, and one state of it, from another: the number of its pages, its log sequence number, and a digest of its first page and of the checksum that each of its pages stores.
- Index
- An index as the catalog describes it.
- Index
Column - One column of an index.
- Open
Options - How to open a file, for a program that wants it otherwise than
Database::opendoes it. - Owned
RowAddresses - An owned,
'staticiterator over theRowAddresses of a table’s live rows. - Owned
Rows - An owned,
'staticiterator over the live rows of a table. - Page
- One page of the file, decoded.
- PageKey
- The signed key that scrambles one page.
- Page
Store - The pages of a database file, decoded on request.
- Record
- A record of a page of rows: a row, a forward to one, or a piece of a long value. The format’s description says what its bytes mean.
- Row
- One row: which one it is, and a value for each of the
Columnsit was read with. - RowAddress
- The place of a row in the file: a table page and a slot on it.
- RowAddresses
- The addresses of a table’s live rows, in page and slot order.
- RowKey
- The values of a key, to look a row up by: it can be hashed and sorted, and two are equal when their values are.
- Rows
- The live rows of one table, in page and slot order.
- Store
Key - The two constants and the sign that give every page of a file its key.
- Superblock
- What the first page says about the file.
- Table
- A table of an open database: its definition, and the way to its rows.
- Table
Definition - A table as the catalog describes it.
- Undecoded
- A value as a row stores it, which this reader has no
Valuefor: - Verification
- What checking a whole file found.
Enums§
- Catalog
Problem - What is wrong with the system catalog.
- Compression
Problem - What is wrong with a compressed value.
- Data
Type - The SQL type of a column, from the domain identifier in the catalog.
- Error
- Why a file, or one part of it, could not be read.
- Format
Problem - Why a file is not a database file this reader knows.
- Index
Kind - What an index is for.
- Index
Order - The order that an index keeps a column in.
- KeySign
- Which way a file’s page keys turn the sector walk.
- Length
Unit - What the declared width of a string or binary column counts.
- Long
Value Problem - What is wrong with a value stored outside its row.
- Page
Kind - What a page holds, as far as this reader tells pages apart.
- Page
List Problem - What is wrong with a serialized page list.
- Page
Problem - What is wrong with a page.
- Page
State - Whether the engine ever wrote a page.
- Parse
Decimal Error - Why a text is not a decimal number.
- RowId
- A row’s identity within its table.
- RowProblem
- What is wrong with one row.
- Table
Kind - What kind of object a catalog table entry describes.
- Text
Encoding - How the bytes of a character column become text.
- Value
- One value of a row.
- Value
Problem - How a value differs from what was asked for.
- Verification
Problem - One thing that is wrong with a file.
Traits§
- Column
Index - What names one of a row’s
Columns: its position among them, or its name, ignoring ASCII case. - From
Value - A type that a value of a row can be read as, with
Row::read. - Source
- What answers for the stored tables of a database: a file, or a file with changes laid over it.