Skip to main content

Crate sa17

Crate sa17 

Source
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:

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, and TIMESTAMP WITH TIME ZONE columns appear as DataType::Unknown and read only NULL; 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_rows distinguishes them from tables that store rows.
  • Indexes are read from the catalog, not from index B-tree pages. Rows are fetched by RowAddress or 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 (0x20 and 0x40) 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 ISYSTAB are 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, TIME and TIMESTAMP that 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.
ForeignKey
A foreign key as the catalog describes it.
FormatVersion
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.
IndexColumn
One column of an index.
OpenOptions
How to open a file, for a program that wants it otherwise than Database::open does it.
OwnedRowAddresses
An owned, 'static iterator over the RowAddresses of a table’s live rows.
OwnedRows
An owned, 'static iterator over the live rows of a table.
Page
One page of the file, decoded.
PageKey
The signed key that scrambles one page.
PageStore
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 Columns it 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.
StoreKey
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.
TableDefinition
A table as the catalog describes it.
Undecoded
A value as a row stores it, which this reader has no Value for:
Verification
What checking a whole file found.

Enums§

CatalogProblem
What is wrong with the system catalog.
CompressionProblem
What is wrong with a compressed value.
DataType
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.
FormatProblem
Why a file is not a database file this reader knows.
IndexKind
What an index is for.
IndexOrder
The order that an index keeps a column in.
KeySign
Which way a file’s page keys turn the sector walk.
LengthUnit
What the declared width of a string or binary column counts.
LongValueProblem
What is wrong with a value stored outside its row.
PageKind
What a page holds, as far as this reader tells pages apart.
PageListProblem
What is wrong with a serialized page list.
PageProblem
What is wrong with a page.
PageState
Whether the engine ever wrote a page.
ParseDecimalError
Why a text is not a decimal number.
RowId
A row’s identity within its table.
RowProblem
What is wrong with one row.
TableKind
What kind of object a catalog table entry describes.
TextEncoding
How the bytes of a character column become text.
Value
One value of a row.
ValueProblem
How a value differs from what was asked for.
VerificationProblem
One thing that is wrong with a file.

Traits§

ColumnIndex
What names one of a row’s Columns: its position among them, or its name, ignoring ASCII case.
FromValue
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.

Type Aliases§

Result
A Result whose error is Error unless it says another.