1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! 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:
//!
//! ```no_run
//! 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:?}");
//! }
//! # Ok::<(), sa17::Error>(())
//! ```
//!
//! A program can work at any of three layers:
//!
//! - A [`Database`] provides [`Table`]s, and each table streams [`Row`]s. Every
//! stored row carries its [`RowAddress`] (page number and slot index).
//! - [`Database::store`] exposes the underlying [`PageStore`], which also opens
//! on its own. A [`Page`] of rows gives the raw [`Record`] of each slot.
//! - [`PageStore::key`] and [`PageStore::stored`] expose the recovered
//! [`StoreKey`] and 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`, 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.
pub use chrono;
pub use ;
pub use Database;
pub use ;
pub use ;
pub use FormatVersion;
pub use FromValue;
pub use Identity;
pub use OpenOptions;
pub use ;
pub use RowAddress;
pub use RowId;
pub use RowKey;
pub use ;
pub use Source;
pub use ;
pub use Table;
pub use ;
pub use ;