Sign in

    moonsqlitefile

    Pure MoonBit read-only SQLite file format parser and inspector

    sqlite
    parser
    database
    inspector
    Download zip
    Author
    Version
    0.8.0
    License
    Apache-2.0
    Last updated
    4 days ago
    Downloads
    77

    #MoonSQLiteFile

    CI Mooncakes License

    纯 MoonBit 的 SQLite 文件解析与检查库

    直接读取 SQLite 3 磁盘格式,用于离线数据库浏览、结构检查和存储格式教学。 核心只依赖 MoonBit 标准库,支持 Wasm、WasmGC、JavaScript 和 native,无需 SQLite 引擎或 FFI;文件 I/O 由宿主提供。

    #能力

    • 读取记录:普通表、索引、WITHOUT ROWID、overflow,以及 UTF-8 / UTF-16 文本。
    • 检查结构:页面空间、B-tree、freelist、页归属及 Ptrmap,提供诊断位置与空间汇总。
    • 读取 WAL:校验帧和提交边界,读取一致静态 db/WAL 副本的最新已提交快照。
    • 按需处理:64 位范围源、有界缓存与资源预算;独立 JS 适配提供异步扫描、背压和取消。

    #安装

    在 MoonBit 项目中运行:

    moon add prowk/moonsqlitefile@0.8.0

    在消费包的 moon.pkg 中导入:

    import {
    "prowk/moonsqlitefile" @sqlite,
    }

    已验证的工具链和宿主版本见支持矩阵。

    #快速上手

    由宿主读取静态数据库文件,将完整字节传入以下函数,读取 samples 表的前 10 行:

    fn read_rows(data : Bytes) -> Array[@sqlite.Row] raise @sqlite.SqliteError {
    let db = @sqlite.open_database(data)
    db.table_rows("samples", limit=10)
    }

    Row 包含 rowid、values 和所在 page_number。返回的是磁盘存储值,不自动还原 SQL 列名、默认值或类型亲和性;INTEGER PRIMARY KEY 的实际值应读取 rowid。

    上述表可用仓库中的 fixtures/core.sqlite 复现。索引、逐条扫描、检查报告与 WAL 示例见使用指南;大文件请使用范围源,避免先读入完整文件。

    #工具入口

    在仓库根目录运行:

    moon build --target js src/cmd/inspect node tools/inspect.cjs fixtures/core.sqlite summary

    #使用边界

    • 只读使用期间不变的静态副本;db/WAL 必须来自同一时刻。不执行 SQL、写入、checkpoint 或在线快照获取。
    • 检查 Complete 仅表示声明范围内工作完成,不等同于 SQLite integrity_check;不验证索引排序/collation 或表与索引内容一致性。
    • 缓存、页数、记录和 payload 各有预算;大文件寻址不等于常量内存,预算耗尽时须处理未完成状态。
    • 浏览器已验证本机 HTTP 载入后断网使用;直接 file:// 打开尚未验收。

    #文档与贡献

    问题反馈请提交到 GitHub Issues,附复现步骤、错误输出及可公开的最小数据库样本。

    #许可证

    Apache-2.0。依据 SQLite 官方磁盘格式 实现;第三方来源与实现边界见来源说明。

    PageSource

    pub(open) trait PageSource {
    fn byte_length(Self) -> Int
    fn read_range(Self, Int, Int) -> Bytes raise SqliteError
    }

    源必须在 Database 的使用期间保持同一份静态快照;不提供并发锁或事务语义。 旧同步静态源;长度与偏移为 Int,必须精确返回请求字节。不得修改快照;宿主 SqliteError 保留历史映射。大文件和细分类别应使用 RangeSource。

    RangeSource

    pub(open) trait RangeSource {
    fn byte_length64(Self) -> Int64
    fn read_range64(Self, Int64, Int) -> Bytes raise SourceError
    }

    长度和偏移为有符号 64 位;单次读取长度仍为 Int,必须精确返回请求长度。 同步静态范围源;长度与偏移为非负 Int64,单次长度为非负 Int,必须精确返回请求字节,失败抛 SourceError。宿主负责一致副本、I/O 和句柄生命周期。

    SourceError

    pub(all) suberror SourceError {
    HostFailure(String)
    ShortRead(String)
    RangeOutOfBounds(String)
    }

    宿主错误与文件格式错误分离;所有数据源须提供不可变的静态快照。 宿主范围读取错误:HostFailure 为实际宿主抛错,ShortRead 为返回长度不符,RangeOutOfBounds 为范围越界。不是 SQLite 格式损坏。

    SqliteError

    pub(all) suberror SqliteError {
    Invalid(String)
    Unsupported(String)
    LimitExceeded(String)
    } derive(
    Debug
    )

    解析、参数或资源错误。Invalid 可来自旧 PageSource 的宿主抛错,不能单凭该枚举判定损坏;新 RangeSource 的宿主失败以 source/ 前缀映射为 Unsupported,检查状态为 Incomplete。

    BTreeCursor

    pub struct BTreeCursor {
    // private fields
    }

    无 I/O 的可暂停 B-tree 状态机。调用 next 后按请求 supply 页面;消费者等待期间不预读。失败后查看 progress/location,并 stop 释放状态。

    BTreeCursor::location

    返回实际阶段和可用位置;失败后仍可读取,不从错误字符串推断。

    BTreeCursor::next

    fn BTreeCursor::next(self : BTreeCursor) -> ScanEvent raise SqliteError

    连续 next 在尚未供页时重复同一请求;错误后游标不可继续使用。 推进至一条记录、一个供页请求或结束;等待供页时重复调用不改变请求。解析/预算失败抛 SqliteError,进度和位置仍可读取。

    BTreeCursor::progress

    fn BTreeCursor::progress(self : BTreeCursor) -> ScanProgress

    返回已交付记录、已认领 B-tree/overflow 页与已请求 payload 进度;失败记录的 payload 可能已计费。

    BTreeCursor::provide_page

    fn BTreeCursor::provide_page(self : BTreeCursor, number : Int, bytes : Bytes) -> Unit raise SqliteError

    仅允许供应当前请求的完整页面;宿主须在调用前自行分类短读和读取失败。 仅接受当前 NeedPage 请求对应的完整页面;错页、短页、重复供给或未请求供给抛 Invalid。宿主应在供给前区分读取失败与格式失败。

    BTreeCursor::stop

    fn BTreeCursor::stop(self : BTreeCursor) -> ScanSummary

    提前终止并释放当前路径和未完成的 payload;不再请求页面。 停止并释放路径、页缓冲和 payload;保留已观察计数。未自然结束时返回 VisitorStopped,不把取消当完整。

    BTreeInspection

    pub(all) struct BTreeInspection {
    root_page : Int
    status : InspectionStatus
    records_decoded : Int
    summary : ScanSummary?
    error : SqliteError?
    } derive(
    Debug
    )

    不保存记录数组;发生错误时仍保留此前成功解码的记录数。 单树检查报告。root_page 是入口根页,records_decoded 只含成功交付记录;失败时可能没有 summary,error 保存原始 SqliteError。

    BTreeInspectionDetails

    pub(all) struct BTreeInspectionDetails {
    inspection : BTreeInspection
    location : DiagnosticLocation?
    } derive(
    Debug
    )

    单树检查与可用的失败位置;inspection 的状态语义与原同步报告一致。

    BTreeRecord

    pub(all) struct BTreeRecord {
    rowid : Int64?
    values : Array[Value]
    page_number : Int
    cell_offset : Int
    } derive(
    Debug
    )

    原始存储记录;index B-tree 没有独立 rowid,字段按磁盘顺序保留。 B-tree 原始存储记录。values 按磁盘顺序保留;索引和 WITHOUT ROWID 的 rowid 为 None。page_number 从 1 开始,cell_offset 为页内字节偏移。

    BytesSource

    pub struct BytesSource {
    data : Bytes
    }

    不可变内存字节源;同时实现旧 PageSource 与 64 位 RangeSource,实际容量仍受 Bytes 和宿主内存限制。

    BytesSource::byte_length

    fn BytesSource::byte_length(self : BytesSource) -> Int

    BytesSource::byte_length64

    fn BytesSource::byte_length64(self : BytesSource) -> Int64

    BytesSource::new

    fn BytesSource::new(data : Bytes) -> BytesSource

    包装不可变 Bytes,不复制整个输入;源容量受 Bytes/Int 限制。

    BytesSource::read_range

    fn BytesSource::read_range(self : BytesSource, offset : Int, count : Int) -> Bytes raise SqliteError

    BytesSource::read_range64

    fn BytesSource::read_range64(self : BytesSource, offset : Int64, count : Int) -> Bytes raise SourceError

    CacheStatistics

    pub(all) struct CacheStatistics {
    hits : Int64
    misses : Int64
    bytes_read : Int64
    resident_pages : Int
    } derive(
    Debug
    )

    缓存累计统计;hits/misses 是块请求次数,bytes_read 是宿主实际返回字节数,resident_pages 是当前驻留块数。

    CachedSource

    pub struct CachedSource {
    // private fields
    }

    按固定块缓存,FIFO 淘汰;缓存与扫描状态、归属报告、WAL 索引预算互相独立。 固定块 FIFO 范围缓存;驻留块有界,返回字节副本,失败不缓存。不会限制遍历状态、单条 payload、全库报告或 WAL 索引的内存。

    CachedSource::byte_length64

    fn CachedSource::byte_length64(self : CachedSource) -> Int64

    CachedSource::new

    fn CachedSource::new(source : &RangeSource, block_size? : Int, max_pages? : Int) -> CachedSource raise SqliteError

    创建固定块 FIFO 缓存;block_size 默认 4096,max_pages 默认 256,均须为正并符合限制。不是数据库或报告内存上限。

    CachedSource::read_range64

    fn CachedSource::read_range64(self : CachedSource, offset : Int64, count : Int) -> Bytes raise SourceError

    CachedSource::statistics

    fn CachedSource::statistics(self : CachedSource) -> CacheStatistics

    返回累计块命中、未命中、实际宿主字节和当前驻留块数,不进行额外读取。

    Database

    pub struct Database {
    source : &PageSource
    header : Header
    page_count : Int
    limits : Limits
    // private fields
    }

    已打开的只读静态数据库视图。页号从 1 开始;page_count 是逻辑页数,WAL 视图以最新提交为准。旧 source 字段保留 Int 寻址兼容性,完整源应通过 source64 访问。

    Database::freelist

    fn Database::freelist(self : Database) -> Array[Int] raise SqliteError

    返回 freelist 中的 trunk 与 leaf 页号,并校验计数与循环。 校验 freelist trunk/leaf、数量和重复引用,返回空闲页号;页号从 1 开始并受页预算限制。

    Database::header

    fn Database::header(self : Database) -> Header

    返回打开时已校验的文件头,不重读源;WAL 视图的逻辑页数应读取 page_count。

    Database::index_records

    fn Database::index_records(self : Database, name : String, limit? : Int) -> Array[BTreeRecord] raise SqliteError

    按索引名读取包含内部 cell 的原始记录;不验证排序、collation 或表/索引内容一致性。

    Database::inspect_btree

    fn Database::inspect_btree(self : Database, root : Int, limit? : Int, max_total_payload_bytes? : UInt64) -> BTreeInspection

    检查单棵 B-tree,保留完成状态或原始错误;资源不足不判为格式损坏。 检查一棵树并保留成功记录数;不收集记录。新范围源宿主失败为 Incomplete,旧源 Invalid 保留 Failed 历史行为,不能仅据状态判定损坏。

    Database::inspect_btree_details

    fn Database::inspect_btree_details(self : Database, root : Int, limit? : Int, max_total_payload_bytes? : UInt64) -> BTreeInspectionDetails

    与 inspect_btree 使用相同扫描和状态语义,额外保留失败上下文。 返回单树报告及实际失败位置,不进行第二次扫描;位置未知为 None。

    Database::inspect_database

    fn Database::inspect_database(self : Database, max_total_payload_bytes? : UInt64, max_issues? : Int) -> DatabaseInspection

    扫描 schema、独立 B-tree 和 freelist,使用整个检查过程共享的预算。 检查 schema、对象树、freelist 和 Ptrmap 的全局归属;保存部分结果。默认累计 payload 64 MiB、最多 100 条诊断,不检查 SQL 排序或表/索引内容一致性。

    Database::inspect_database_details

    fn Database::inspect_database_details(self : Database, max_total_payload_bytes? : UInt64, max_issues? : Int) -> DatabaseInspectionDetails

    一次全库检查同时保留每个问题的可用位置,不从错误字符串猜测;语义与 inspect_database 相同。

    Database::inspect_page

    fn Database::inspect_page(self : Database, number : Int) -> PageInspection

    仅读取指定页并校验 B-tree 布局/空间;读取失败为 Incomplete,格式错误为 Failed,保留可用诊断,不检查 record 或 overflow 链。

    Database::inspection_cursor

    fn Database::inspection_cursor(self : Database, max_total_payload_bytes? : UInt64, max_issues? : Int) -> InspectionCursor

    创建包含 schema、对象树、freelist、Ptrmap 的全库游标;默认累计 payload 64 MiB、诊断 100 条。配置错误返回失败报告,宿主按事件供页或拒绝读请求。

    Database::page

    fn Database::page(self : Database, number : Int) -> Page raise SqliteError

    读取并验证指定 B-tree 页的完整 cell/freeblock 空间布局;不是通用 overflow/freelist 解码入口,不检查 record 或 overflow 内容。

    Database::page_count

    fn Database::page_count(self : Database) -> Int

    返回当前视图的逻辑页数;WAL 视图采用最新完整提交页数,不直接采用旧主文件声明。

    Database::ptrmap_entries

    fn Database::ptrmap_entries(self : Database) -> Array[PtrmapEntry] raise SqliteError

    读取 auto-vacuum 反向指针;与真实页归属对照请使用 inspect_database。 读取并校验 auto-vacuum 的 Ptrmap 条目;非 auto-vacuum 返回空数组。真实归属交叉检查由 inspect_database 完成。

    Database::read_btree

    fn Database::read_btree(self : Database, root : Int, limit? : Int, max_total_payload_bytes? : UInt64) -> Array[BTreeRecord] raise SqliteError

    收集任意 B-tree 的原始记录,索引内部 cell 也交付;显式 limit 可返回前缀。单条仍完整解码,集合本身可能占用大量内存。

    Database::read_index

    fn Database::read_index(self : Database, root : Int, limit? : Int) -> Array[BTreeRecord] raise SqliteError

    收集 index B-tree/WITHOUT ROWID 的原始记录;普通 rowid 表类型不符合时抛 Invalid,不检查索引排序或 collation。

    Database::read_page

    fn Database::read_page(self : Database, number : Int) -> Bytes raise SqliteError

    读取完整的逻辑页,number 从 1 开始;页号越界为 Invalid,范围宿主失败保留 source/ 分类。此入口不解析页布局。

    Database::read_table

    fn Database::read_table(self : Database, root : Int, limit? : Int) -> Array[Row] raise SqliteError

    以 rowid 顺序读取普通表;保留首版接口与原始存储值语义。 收集普通 rowid 表的原始记录;显式 limit 可返回前缀,默认预算造成未完成时抛 LimitExceeded。不支持 index/WITHOUT ROWID,改用 read_btree。

    Database::scan_btree

    fn Database::scan_btree(self : Database, root : Int, visit : (BTreeRecord) -> Bool raise SqliteError, limit? : Int, max_total_payload_bytes? : UInt64) -> ScanSummary raise SqliteError

    按 B-tree 顺序逐条回调,返回 false 可停止;无需在库中保存所有结果。 逐条调用 visit,返回 false 停止;不收集结果数组。默认累计 payload 64 MiB,失败请求也计费;报告区分遍历结束、记录前缀上限和消费者停止。

    Database::scan_cursor

    fn Database::scan_cursor(self : Database, root : Int, limit? : Int, max_total_payload_bytes? : UInt64, table_only? : Bool) -> BTreeCursor raise SqliteError

    创建可恢复的扫描,不读取根页;next 返回需要的页面或一条记录。 创建无 I/O 扫描游标,next 按需请求完整页。limit 不能超过 Limits.max_rows,累计 payload 默认 64 MiB;table_only 额外要求 table B-tree。

    Database::schema

    fn Database::schema(self : Database) -> Array[SchemaEntry] raise SqliteError

    完整读取并校验 sqlite_schema;受 Limits.max_rows 预算限制,超出时抛 LimitExceeded,不把 schema 前缀冒充完整对象集合。

    Database::source64

    fn Database::source64(self : Database) -> &RangeSource

    返回用于完整读取的 64 位源;旧 source 字段保持 v0.5 的 Int 契约。 获取完整 64 位静态范围视图;旧源经适配器返回,不扩展旧源实际地址空间。

    Database::table_records

    fn Database::table_records(self : Database, name : String, limit? : Int) -> Array[BTreeRecord] raise SqliteError

    返回普通表或 WITHOUT ROWID 表的原始存储记录,不推断 SQL 列顺序。 按表名读取原始记录,包含 WITHOUT ROWID;values 保留存储顺序,显式 limit 可返回前缀。

    Database::table_rows

    fn Database::table_rows(self : Database, name : String, limit? : Int) -> Array[Row] raise SqliteError

    按 schema 名称读取普通 rowid 表;不执行 SELECT,也不恢复 INTEGER PRIMARY KEY 磁盘 Null 字段,WITHOUT ROWID 请用 table_records。

    DatabaseInspection

    pub(all) struct DatabaseInspection {
    status : InspectionStatus
    ownership_complete : Bool
    ptrmap_checked : Bool
    diagnostics_truncated : Bool
    roots_inspected : Int
    records_decoded : Int
    payload_bytes : UInt64
    pages : Array[PageOwnership]
    unclaimed_pages : Array[Int]
    issues : Array[DatabaseIssue]
    } derive(
    Debug
    )

    只检查逻辑数据库页;完整页归属不等价于 SQL 完整性检查。 全库已观察报告。ownership_complete 与 ptrmap_checked 分别标记覆盖;diagnostics_truncated 表示诊断截断。schema 记录计入 records_decoded,失败 payload 请求也计费。

    DatabaseInspection::summarize

    不读取数据源、不解码记录;未完成报告的统计只表示已观察到的页。 对已有页归属报告作纯汇总,不重读数据源;冲突页只按首次归属计数,未完成报告只代表已观察前缀。

    DatabaseInspectionDetails

    pub(all) struct DatabaseInspectionDetails {
    inspection : DatabaseInspection
    issues : Array[LocatedDatabaseIssue]
    } derive(
    Debug
    )

    issues 与 inspection.issues 同序同长度,位置来自同一次检查,不重新读取源。 全库报告与按问题顺序对应的位置;不会额外重读数据库。

    DatabaseIssue

    pub(all) enum DatabaseIssue {
    ScanError(Int?, SqliteError)
    PageConflict(PageOwnership, PageOwnership)
    UnclaimedPage(Int)
    UnsupportedFeature(String)
    PtrmapMismatch(PtrmapEntry, PageOwnership)
    } derive(
    Debug
    )

    全库结构问题:扫描错误、跨用途页冲突、完整覆盖后的未认领页、不支持特性及 Ptrmap 归属不一致。

    DiagnosticLocation

    pub(all) struct DiagnosticLocation {
    phase : DiagnosticPhase
    page_number : Int?
    byte_offset : Int?
    cell_index : Int?
    page_diagnostic : PageDiagnostic?
    } derive(
    Debug
    )

    偏移从页面起点计数,下标从零计数;不能确定位置时保留 None。 可用的失败位置。页号从 1 开始,byte_offset 相对页面,cell_index 从 0 开始;未知字段为 None,初始化失败不产生该报告。

    DiagnosticPhase

    pub(all) enum DiagnosticPhase {
    Configuration
    ReadPage
    PageLayout
    TreeTraversal
    CellPayload
    OverflowChain
    RecordDecode
    SchemaDecode
    FreelistCheck
    PtrmapCheck
    PageOwnershipCheck
    } derive(Eq,
    Debug
    )

    失败发生的检查阶段;读取失败不能仅凭 SqliteError 判断为格式损坏。 失败时实际执行的检查阶段;不从错误文本猜测阶段或位置。

    DiagnosticPhase::equal

    DiagnosticPhase::not_equal

    fn DiagnosticPhase::not_equal(x : DiagnosticPhase, y : DiagnosticPhase) -> Bool

    pub(all) struct Header {
    page_size : Int
    usable_size : Int
    write_version : Int
    read_version : Int
    change_counter : UInt
    declared_pages : UInt
    freelist_trunk : UInt
    freelist_pages : UInt
    schema_cookie : UInt
    schema_format : Int
    largest_root_page : UInt
    incremental_vacuum : Bool
    text_encoding : Int
    user_version : UInt
    application_id : UInt
    version_valid_for : UInt
    sqlite_version : UInt
    } derive(Eq,
    Debug
    )

    已校验的 100 字节 SQLite 头。page_size 为实际字节数,usable_size 扣除保留空间;declared_pages 是头部声明值,不一定等于打开视图的逻辑页数。text_encoding 为 1/2/3,未初始化空库也允许 0。

    Header::equal

    fn Header::equal(Header, Header) -> Bool

    Header::not_equal

    fn Header::not_equal(x : Header, y : Header) -> Bool

    Header::to_repr

    InspectionCursor

    pub struct InspectionCursor {
    // private fields
    }

    无 I/O 全库检查游标;包含 schema、对象树、freelist 和 Ptrmap。宿主可供页、拒绝当前读请求或停止,并保留此前观察到的归属与诊断。

    InspectionCursor::location

    返回检查实际阶段及可用位置;None 字段表示未掌握位置。

    InspectionCursor::next

    推进一个供页/进度事件或返回详细报告;已完成或停止后重复调用保持最终结果,不执行宿主 I/O。

    InspectionCursor::progress

    返回全库已成功解码记录、已认领页面和已请求 payload;schema 记录也计数。

    InspectionCursor::provide_page

    fn InspectionCursor::provide_page(self : InspectionCursor, number : Int, bytes : Bytes) -> Unit raise SqliteError

    供给当前请求的完整页;错页、重复或长度不符抛 Invalid,不允许把宿主短读送入格式解析。

    InspectionCursor::reject_page

    fn InspectionCursor::reject_page(self : InspectionCursor, reason : SqliteError) -> Unit raise SqliteError

    将本次页读取失败送回状态机,其他可独立检查的对象仍可继续。 将当前页面读取错误交给核心,保留部分报告并继续可独立检查的对象;schema 读取失败不能继续发现全部根页。范围宿主错误应先使用 source/ 映射。

    InspectionCursor::stop

    宿主失败或取消保留观察结果,并明确标记检查未完成。 停止全库检查并释放游标,保留已观察页面、记录、诊断和位置;未完成时状态为 Incomplete,可提供停止原因。

    InspectionEvent

    pub(all) enum InspectionEvent {
    NeedInspectionPage(Int)
    InspectionProgress(ScanProgress)
    InspectionFinished(DatabaseInspectionDetails)
    } derive(
    Debug
    )

    全库检查按需请求页面,进度事件允许宿主让出执行权和取消。 全库供页协议:按需请求完整页、发送可让出执行权的进度事件,最后交付包含部分结果的详细报告。

    InspectionStatus

    pub(all) enum InspectionStatus {
    Complete
    Incomplete
    Failed
    } derive(Eq,
    Debug
    )

    仅描述指定根页的扫描结果,不代表整个数据库的完整性结论。 结构检查状态。Complete 仅表示声明范围完成;Incomplete 包含预算、宿主失败及不支持;Failed 表示已观察到格式错误或历史旧源 Invalid。

    InspectionStatus::equal

    InspectionStatus::not_equal

    fn InspectionStatus::not_equal(x : InspectionStatus, y : InspectionStatus) -> Bool

    InspectionSummary

    pub(all) struct InspectionSummary {
    claimed_pages : Int
    unclaimed_pages : Int
    page_kinds : Array[PageKindCount]
    objects : Array[ObjectPageCount]
    } derive(Eq,
    Debug
    )

    对已有报告的纯汇总;完整程度、诊断及 payload 请求总量仍以原报告为准。 已有归属报告的纯汇总;不重新读取源。未完成检查的统计只代表已观察前缀,完整程度仍看原报告。

    InspectionSummary::equal

    InspectionSummary::not_equal

    fn InspectionSummary::not_equal(x : InspectionSummary, y : InspectionSummary) -> Bool

    Limits

    pub(all) struct Limits {
    max_rows : Int
    max_payload_bytes : Int
    max_pages : Int
    max_depth : Int
    } derive(
    Debug
    )

    单次操作的资源上限;不是堆内存上限。max_rows 默认 100000,单条 payload 默认 16 MiB,max_pages 默认 100000,max_depth 默认 64;累计 payload 由扫描参数独立控制。

    Limits::default

    fn Limits::default() -> Limits

    返回默认单次预算:100000 条记录、16 MiB 单条 payload、100000 页、深度 64;累计 payload 默认值由扫描接口另行提供。

    Limits::to_repr

    LocatedDatabaseIssue

    pub(all) struct LocatedDatabaseIssue {
    issue : DatabaseIssue
    location : DiagnosticLocation?
    } derive(
    Debug
    )

    全库问题及观察到的位置;缺失位置不代表页 0,不从根页或字符串推断。

    ObjectPageCount

    pub(all) struct ObjectPageCount {
    root_page : Int
    object_name : String?
    btree_pages : Int
    overflow_pages : Int
    } derive(Eq,
    Debug
    )

    仅统计已经认领的页,不把冲突引用重复计入另一个对象。 一个对象已认领的 B-tree 与 overflow 页数;包含页内空闲空间,不是有效 payload 长度。

    ObjectPageCount::equal

    ObjectPageCount::not_equal

    fn ObjectPageCount::not_equal(x : ObjectPageCount, y : ObjectPageCount) -> Bool

    Page

    pub(all) struct Page {
    number : Int
    kind : PageType
    first_freeblock : Int
    cell_count : Int
    content_start : Int
    fragmented_bytes : Int
    right_child : Int?
    cell_offsets : Array[Int]
    } derive(
    Debug
    )

    已校验的 B-tree 页元数据。number 从 1 开始,所有偏移均相对页起始;right_child 只存在于内部页,cell_offsets 按逻辑 cell 顺序排列。

    Page::to_repr

    PageDiagnostic

    pub(all) struct PageDiagnostic {
    code : PageDiagnosticCode
    page_number : Int
    byte_offset : Int?
    cell_index : Int?
    error : SqliteError
    } derive(
    Debug
    )

    byte_offset 从页面起点计数;cell_index 从零计数。位置指向检查失败的字段或区间。 单页错误及可定位的页内偏移/cell 下标;error 保留原始类别和具体原因。

    PageDiagnosticCode

    pub(all) enum PageDiagnosticCode {
    PageRead
    PageTypeTag
    PageHeader
    CellPointer
    CellFormat
    Freeblock
    SpaceOverlap
    UntrackedSpace
    FragmentCount
    ChildPointer
    } derive(Eq,
    Debug
    )

    页内格式错误的分类;PageRead 表示输入或宿主读取失败。 单页失败的结构化类别;PageRead 仅表示读取失败,不能直接断定格式损坏。

    PageDiagnosticCode::equal

    PageDiagnosticCode::not_equal

    PageInspection

    pub(all) struct PageInspection {
    status : InspectionStatus
    page : Page?
    statistics : PageStatistics?
    diagnostic : PageDiagnostic?
    } derive(
    Debug
    )

    仅检查指定 B-tree 页的布局;失败时不返回可能误导的部分统计。 单页 B-tree 检查结果;读取失败为 Incomplete。失败时 page/statistics 可能缺失,diagnostic 保留已知位置。

    PageKind

    pub(all) enum PageKind {
    BtreeRoot
    BtreeChild
    OverflowFirst
    OverflowContinuation
    FreelistTrunk
    FreelistLeaf
    PointerMap
    LockByte
    } derive(Eq,
    Debug
    )

    全库归属报告的八类页用途;一页只统计首次归属,冲突另外报告。

    PageKind::equal

    fn PageKind::equal(PageKind, PageKind) -> Bool

    PageKind::not_equal

    fn PageKind::not_equal(x : PageKind, y : PageKind) -> Bool

    PageKind::to_repr

    PageKindCount

    pub(all) struct PageKindCount {
    kind : PageKind
    pages : Int
    } derive(Eq,
    Debug
    )

    某一页用途的首次归属页数;不重复计入冲突引用。

    PageKindCount::equal

    PageKindCount::not_equal

    fn PageKindCount::not_equal(x : PageKindCount, y : PageKindCount) -> Bool

    PageOwnership

    pub(all) struct PageOwnership {
    page_number : Int
    kind : PageKind
    root_page : Int?
    object_name : String?
    parent_page : Int?
    } derive(Eq,
    Debug
    )

    首次认领页面的用途、根页、对象和父页;不属于对象或没有父页时相应字段为 None。

    PageOwnership::equal

    PageOwnership::not_equal

    fn PageOwnership::not_equal(x : PageOwnership, y : PageOwnership) -> Bool

    PageSourceAdapter

    pub struct PageSourceAdapter {
    source : &PageSource
    }

    将旧 PageSource 包装为 RangeSource。自身检查越界和短读;旧源实际抛出的 SqliteError 归为 HostFailure。不能扩展旧源的实际 Int 地址空间。

    PageSourceAdapter::byte_length64

    fn PageSourceAdapter::byte_length64(self : PageSourceAdapter) -> Int64

    PageSourceAdapter::new

    包装旧同步源,不立即读取;之后分别检查越界和短读,实际宿主抛错归 HostFailure。

    PageSourceAdapter::read_range64

    fn PageSourceAdapter::read_range64(self : PageSourceAdapter, offset : Int64, count : Int) -> Bytes raise SourceError

    PageStatistics

    pub(all) struct PageStatistics {
    database_header_bytes : Int
    btree_header_bytes : Int
    pointer_bytes : Int
    unallocated_bytes : Int
    cell_bytes : Int
    freeblock_bytes : Int
    fragmented_bytes : Int
    reserved_bytes : Int
    payload_bytes : UInt64
    local_payload_bytes : UInt64
    max_payload_bytes : Int
    overflow_cells : Int
    } derive(
    Debug
    )

    空间项互不重叠,总和等于页面大小;payload 计数是 cell 声明值,不验证 overflow 链。 单页空间分项,单位为字节。payload_bytes 是声明总量,local_payload_bytes 是页内部分;仅检查当前页,不验证 overflow 内容或 record 解码。

    PageType

    pub(all) enum PageType {
    TableLeaf
    TableInterior
    IndexLeaf
    IndexInterior
    } derive(Eq,
    Debug
    )

    四种 SQLite B-tree 页面类型;不用于 overflow、freelist、Ptrmap 或 lock-byte 页面。

    PageType::equal

    fn PageType::equal(PageType, PageType) -> Bool

    PageType::not_equal

    fn PageType::not_equal(x : PageType, y : PageType) -> Bool

    PageType::to_repr

    PtrmapEntry

    pub(all) struct PtrmapEntry {
    page_number : Int
    map_page : Int
    kind : PtrmapType
    parent_page : Int
    } derive(Eq,
    Debug
    )

    已校验的反向指针;page_number 和 map_page 从 1 开始,parent_page 为格式存储的父页值,根页/空闲页使用 0。

    PtrmapEntry::equal

    fn PtrmapEntry::equal(PtrmapEntry, PtrmapEntry) -> Bool

    PtrmapEntry::not_equal

    fn PtrmapEntry::not_equal(x : PtrmapEntry, y : PtrmapEntry) -> Bool

    PtrmapType

    pub(all) enum PtrmapType {
    RootPage
    FreePage
    FirstOverflow
    NextOverflow
    NonRootBtree
    } derive(Eq,
    Debug
    )

    auto-vacuum Ptrmap 的五种页面反向引用类型。

    PtrmapType::equal

    fn PtrmapType::equal(PtrmapType, PtrmapType) -> Bool

    PtrmapType::not_equal

    fn PtrmapType::not_equal(x : PtrmapType, y : PtrmapType) -> Bool

    RangeWalCommit

    pub(all) struct RangeWalCommit {
    frame_index : Int
    database_pages : UInt
    } derive(Eq,
    Debug
    )

    范围 WAL 的有效提交边界;帧号仍为 Int,逻辑页数来自提交帧。

    RangeWalCommit::equal

    RangeWalCommit::not_equal

    fn RangeWalCommit::not_equal(x : RangeWalCommit, y : RangeWalCommit) -> Bool

    RangeWalFrame

    pub(all) struct RangeWalFrame {
    index : Int
    byte_offset : Int64
    page_number : UInt
    database_pages : UInt
    checksum1 : UInt
    checksum2 : UInt
    } derive(Eq,
    Debug
    )

    范围 WAL 中的一帧;byte_offset 使用 Int64,指向帧头,其他字段保持原帧语义。

    RangeWalFrame::equal

    RangeWalFrame::not_equal

    fn RangeWalFrame::not_equal(x : RangeWalFrame, y : RangeWalFrame) -> Bool

    RangeWalInspection

    pub(all) struct RangeWalInspection {
    header : WalHeader?
    frames : Array[RangeWalFrame]
    commits : Array[RangeWalCommit]
    committed_frames : Int
    database_pages : UInt?
    stop_reason : WalStopReason
    stop_offset : Int64
    trailing_bytes : Int64
    } derive(
    Debug
    )

    范围 WAL 报告;stop_offset 与 trailing_bytes 为 Int64,未完成校验的帧不能用于最新快照。

    RangeWalSource

    pub struct RangeWalSource {
    // private fields
    }

    64 位主文件/WAL 静态覆盖源;只保存有界覆盖索引,按范围读取实际来源,逻辑页数以最新完整提交为准。宿主必须提供一致且不可变的配对副本。

    RangeWalSource::byte_length64

    fn RangeWalSource::byte_length64(self : RangeWalSource) -> Int64

    RangeWalSource::from_cursor

    fn RangeWalSource::from_cursor(base : &RangeSource, wal : &RangeSource, cursor : WalCursor, tail_policy? : WalTailPolicy, max_overlay_pages? : Int) -> RangeWalSource raise SqliteError

    使用已经完成的供帧游标创建索引;游标输入必须来自相同的不可变 WAL。 从完成的 WalCursor 构造覆盖索引,不重新验证 WAL;传入源必须与供给校验时相同且不可变。未完成/取消游标拒绝构造。

    RangeWalSource::inspection

    返回覆盖视图的 64 位 WAL 验证报告,不重新读取源;调用者不应修改报告数组。

    RangeWalSource::new

    fn RangeWalSource::new(base : &RangeSource, wal : &RangeSource, tail_policy? : WalTailPolicy, max_frames? : Int, max_overlay_pages? : Int) -> RangeWalSource raise SqliteError

    只读最新已提交快照;调用者负责提供同一数据库、同一时刻的不可变副本。 逐帧校验配对静态范围源并构建有界最新提交覆盖索引;max_frames/max_overlay_pages 默认各 100000。宿主失败或预算不足不能回退为旧成功快照。

    RangeWalSource::page_count

    fn RangeWalSource::page_count(self : RangeWalSource) -> Int

    返回最新完整提交的逻辑页数,隔离未提交尾部和缩小后旧页。

    RangeWalSource::page_range

    fn RangeWalSource::page_range(self : RangeWalSource, number : Int) -> SnapshotPageRange raise SqliteError

    查询逻辑页实际读取来源;返回页面内容起始的 Int64 偏移,WAL 偏移不包含 24 字节帧头。页号越界抛 Invalid。

    RangeWalSource::read_range64

    fn RangeWalSource::read_range64(self : RangeWalSource, offset : Int64, count : Int) -> Bytes raise SourceError

    Row

    pub(all) struct Row {
    rowid : Int64
    values : Array[Value]
    page_number : Int
    } derive(
    Debug
    )

    普通 rowid 表的原始记录。INTEGER PRIMARY KEY 的磁盘字段可能为 Null,主键位于 rowid;不执行 SQL 列映射或类型亲和性转换。

    Row::to_repr

    ScanCompletion

    pub(all) enum ScanCompletion {
    Complete
    RecordLimit
    VisitorStopped
    } derive(Eq,
    Debug
    )

    扫描终止原因:Complete 为实际遍历结束,RecordLimit 为尚有数据时到达记录前缀上限,VisitorStopped 为消费者停止;不代表 integrity_check。

    ScanCompletion::equal

    ScanCompletion::not_equal

    fn ScanCompletion::not_equal(x : ScanCompletion, y : ScanCompletion) -> Bool

    ScanEvent

    pub(all) enum ScanEvent {
    NeedPage(Int)
    RecordReady(BTreeRecord)
    ScanFinished(ScanSummary)
    } derive(
    Debug
    )

    页面由调用者提供;游标不执行 I/O,记录之间可暂停以实现异步背压。 B-tree 供页协议。NeedPage 请求一个完整页面;RecordReady 交付一条记录;ScanFinished 包含终止原因。等待供页时重复 next 保持相同请求。

    ScanProgress

    pub(all) struct ScanProgress {
    records_read : Int
    pages_read : Int
    payload_bytes : UInt64
    } derive(Eq,
    Debug
    )

    已完成的记录和已认领页面进度,不表示整个扫描已完成。 尚未完成扫描的已交付记录、已认领页面及已请求 payload 进度;不能据此声称完整。

    ScanProgress::equal

    ScanProgress::not_equal

    fn ScanProgress::not_equal(x : ScanProgress, y : ScanProgress) -> Bool

    ScanSummary

    pub(all) struct ScanSummary {
    records_read : Int
    pages_read : Int
    payload_bytes : UInt64
    completion : ScanCompletion
    } derive(
    Debug
    )

    扫描结果及终止原因。pages_read 包含已认领 B-tree/overflow 页,payload_bytes 是已请求 payload 字节数;不是成功记录字节数或精确内存消耗。

    SchemaEntry

    pub(all) struct SchemaEntry {
    object_type : String
    name : String
    table_name : String
    root_page : Int
    sql : String?
    } derive(
    Debug
    )

    sqlite_schema 的一条已校验记录。root_page 为 0 表示无独立根页;sql 可为空,不解析 CREATE 语句,也不恢复列名或 SQL 语义。

    SnapshotPageRange

    pub(all) enum SnapshotPageRange {
    MainPage(Int64)
    WalPage(Int64)
    } derive(Eq,
    Debug
    )

    异步适配器使用同一个核心覆盖索引确定页来源,不重复实现提交或缩小语义。 覆盖视图中页面的真实来源;MainPage/WalPage 携带页面内容起始的 Int64 字节偏移,WalPage 跳过 24 字节帧头。

    SnapshotPageRange::equal

    SnapshotPageRange::not_equal

    fn SnapshotPageRange::not_equal(x : SnapshotPageRange, y : SnapshotPageRange) -> Bool

    Value

    pub(all) enum Value {
    Null
    Integer(Int64)
    Real(Double)
    Text(String)
    Blob(Bytes)
    } derive(Eq,
    Debug
    )

    SQLite 记录中的原始值,保留整数、浮点数与二进制数据的区别。 SQLite record 的磁盘值类型;Integer 保留 Int64,Text 按数据库编码解码,Blob 保留字节。不是 SQL 引擎计算后的逻辑值。

    Value::equal

    fn Value::equal(Value, Value) -> Bool

    Value::not_equal

    fn Value::not_equal(x : Value, y : Value) -> Bool

    Value::to_repr

    WalChecksumOrder

    pub(all) enum WalChecksumOrder {
    LittleEndianChecksum
    BigEndianChecksum
    } derive(Eq,
    Debug
    )

    WAL 累计 checksum 的字节序,由 header magic 决定;其他 WAL 数值仍按大端存储。

    WalChecksumOrder::equal

    WalChecksumOrder::not_equal

    fn WalChecksumOrder::not_equal(x : WalChecksumOrder, y : WalChecksumOrder) -> Bool

    WalCommit

    pub(all) struct WalCommit {
    frame_index : Int
    database_pages : UInt
    } derive(Eq,
    Debug
    )

    完整有效提交边界;frame_index 从 1 开始,database_pages 是该提交的逻辑页数。

    WalCommit::equal

    fn WalCommit::equal(WalCommit, WalCommit) -> Bool

    WalCommit::not_equal

    fn WalCommit::not_equal(x : WalCommit, y : WalCommit) -> Bool

    WalCursor

    pub struct WalCursor {
    // private fields
    }

    不执行 I/O 的顺序 WAL 校验游标;供给范围必须符合当前请求。取消或失败的游标不能用于构造覆盖快照。

    WalCursor::close

    fn WalCursor::close(self : WalCursor) -> Unit

    取消后释放缓冲和索引;不能把此前的提交当成最新快照返回。 取消并释放供给缓冲、帧和提交数组;取消后的游标不能构造覆盖快照。

    WalCursor::frames_read

    fn WalCursor::frames_read(self : WalCursor) -> Int

    返回已校验有效帧数;未完成时不能当作最新完整 WAL 的边界,close 后计数归零。

    WalCursor::new

    fn WalCursor::new(size : Int64, max_frames? : Int) -> WalCursor raise SqliteError

    创建顺序 WAL 校验游标,不读取数据;size 为非负 Int64,max_frames 默认为 100000 且必须为正,非空短 header 立即拒绝。

    WalCursor::next

    fn WalCursor::next(self : WalCursor) -> WalReadEvent raise SqliteError

    未供给数据时重复同一请求,成功接受一帧后才推进 offset 和 checksum。 顺序推进至完整 header/帧请求或验证报告;等待供给时重复请求不变,失败后关闭游标。异常尾部记录在停止原因。

    WalCursor::provide

    fn WalCursor::provide(self : WalCursor, offset : Int64, bytes : Bytes) -> Unit raise SqliteError

    只接受当前请求,调用者须先分类宿主短读、越界与读取失败。 只接受当前 NeedWalRange 的准确偏移和长度;错位、短读、重复供给或已关闭抛 Invalid。先由宿主分类读取错误。

    WalFrame

    pub(all) struct WalFrame {
    index : Int
    byte_offset : Int
    page_number : UInt
    database_pages : UInt
    checksum1 : UInt
    checksum2 : UInt
    } derive(Eq,
    Debug
    )

    内存 WAL 中的一帧;index 从 1 开始,byte_offset 指向帧头,database_pages 非零表示提交边界。

    WalFrame::equal

    fn WalFrame::equal(WalFrame, WalFrame) -> Bool

    WalFrame::not_equal

    fn WalFrame::not_equal(x : WalFrame, y : WalFrame) -> Bool

    WalFrame::to_repr

    WalHeader

    pub(all) struct WalHeader {
    checksum_order : WalChecksumOrder
    version : UInt
    page_size : Int
    checkpoint_sequence : UInt
    salt1 : UInt
    salt2 : UInt
    checksum1 : UInt
    checksum2 : UInt
    } derive(Eq,
    Debug
    )

    已校验的 32 字节 WAL 头;page_size 是实际页长,salt 与 checksum 用于逐帧验证,不提供在线锁或恢复协议。

    WalHeader::equal

    fn WalHeader::equal(WalHeader, WalHeader) -> Bool

    WalHeader::not_equal

    fn WalHeader::not_equal(x : WalHeader, y : WalHeader) -> Bool

    WalInspection

    pub(all) struct WalInspection {
    header : WalHeader?
    frames : Array[WalFrame]
    commits : Array[WalCommit]
    committed_frames : Int
    database_pages : UInt?
    stop_reason : WalStopReason
    stop_offset : Int
    trailing_bytes : Int
    } derive(
    Debug
    )

    内存 WAL 连续有效帧和提交报告;异常尾部可返回报告而非抛错,构造快照时再应用尾部策略。空 WAL 没有 header。

    WalReadEvent

    pub(all) enum WalReadEvent {
    NeedWalRange(Int64, Int)
    WalReady(RangeWalInspection)
    } derive(
    Debug
    )

    按顺序供给完整 WAL header 或帧;不执行宿主 I/O。 WAL 供给协议:NeedWalRange 指定准确 64 位偏移及完整 header/帧长度;WalReady 返回验证报告。

    WalSource

    pub struct WalSource {
    base : &PageSource
    wal : Bytes
    page_size : Int
    page_count : Int
    base_pages : Int
    overlay : Map[Int, Int]
    inspection : WalInspection
    }

    持有完整 WAL 字节的旧 PageSource 覆盖视图;读取最新完整提交,隔离未提交更新及缩小/增长后的旧页,受 Int 地址空间限制。

    WalSource::byte_length

    fn WalSource::byte_length(self : WalSource) -> Int

    WalSource::inspection

    fn WalSource::inspection(self : WalSource) -> WalInspection

    返回构造覆盖视图时的 WAL 验证报告,不重新扫描源;调用者不应修改报告数组。

    WalSource::new

    fn WalSource::new(base : &PageSource, wal : Bytes, tail_policy? : WalTailPolicy, max_frames? : Int) -> WalSource raise SqliteError

    只读最新已提交快照;调用者负责提供同一数据库、同一时刻的不可变副本。 使用完整 WAL 字节构造旧 Int 地址空间覆盖视图;默认拒绝异常尾部,显式有效前缀策略也不能绕过帧预算。配对源必须静态一致。

    WalSource::page_count

    fn WalSource::page_count(self : WalSource) -> Int

    返回最新完整提交的逻辑页数;没有提交时使用主文件逻辑页数。

    WalSource::read_range

    fn WalSource::read_range(self : WalSource, offset : Int, count : Int) -> Bytes raise SqliteError

    WalStopReason

    pub(all) enum WalStopReason {
    WalEndOfFile
    WalTruncatedFrame
    WalSaltMismatch
    WalChecksumMismatch
    WalInvalidFrame
    WalFrameLimit
    } derive(Eq,
    Debug
    )

    WAL 扫描停止原因;异常尾部与完整提交分开记录。WalFrameLimit 不能被有效前缀策略当作最新快照成功。

    WalStopReason::equal

    WalStopReason::not_equal

    fn WalStopReason::not_equal(x : WalStopReason, y : WalStopReason) -> Bool

    WalTailPolicy

    pub(all) enum WalTailPolicy {
    RejectInvalidTail
    UseValidPrefix
    } derive(Eq,
    Debug
    )

    异常尾部策略:默认 RejectInvalidTail;显式 UseValidPrefix 使用此前完整提交。帧预算不足或宿主读取失败不能降级为旧快照。

    WalTailPolicy::equal

    WalTailPolicy::not_equal

    fn WalTailPolicy::not_equal(x : WalTailPolicy, y : WalTailPolicy) -> Bool

    decode_record

    fn decode_record(payload : Bytes, encoding : Int) -> Array[Value] raise SqliteError

    解码完整的 SQLite record payload;编码编号与数据库文件头保持一致。 完整解码 record 的 serial types 与 payload;encoding 为 1/2/3,保留磁盘值顺序,不执行 SQL 转换。截断、非法编码或不支持类型通过 SqliteError 返回。

    decode_schema_entry

    fn decode_schema_entry(values : Array[Value], page_count : Int) -> SchemaEntry raise SqliteError

    异步适配层校验已解码的 sqlite_schema 记录,语义与同步 schema 一致。 校验一条已解码 sqlite_schema record 和根页范围;不解析 sql 字符串,page_count 必须是视图的逻辑页数。

    decode_varint

    fn decode_varint(data : Bytes, offset : Int) -> (UInt64, Int) raise SqliteError

    从 offset 解码 1–9 字节 SQLite varint,返回无符号值与消耗字节数;截断或越界抛 Invalid,不进行有符号 rowid 转换。

    inspect_wal

    fn inspect_wal(data : Bytes, max_frames? : Int) -> WalInspection raise SqliteError

    只接受连续有效帧;遇到首个无效帧后不搜索更后面的提交标记。 顺序验证完整内存 WAL,返回连续有效帧、提交边界和停止原因。默认最多 100000 帧;异常尾部与帧预算在报告中区分。

    inspect_wal_source

    fn inspect_wal_source(source : &RangeSource, max_frames? : Int) -> RangeWalInspection raise SqliteError

    只接受连续有效帧;遇到首个无效帧后不搜索更后面的提交标记。 逐帧验证 64 位静态 WAL 源,不持有完整 WAL;默认帧预算 100000。实际宿主失败抛 source/ 错误,不作为有效前缀成功。

    open_database

    fn open_database(data : Bytes, limits? : Limits) -> Database raise SqliteError

    从完整静态 Bytes 打开只读库;只验证初始化与文件头。后续格式错误在实际访问时返回;不获取并发快照或执行完整性检查。

    open_range_source

    fn open_range_source(source : &RangeSource, limits? : Limits, max_report_pages? : Int) -> Database raise SqliteError

    64 位寻址;页号保持 Int,超过 2147483647 页显式拒绝,避免静默截断。 打开 64 位静态范围源,初始化只读取 100 字节头;页号仍最多 2147483647。宿主 SourceError 映射为 Unsupported(source/...),报告为 Incomplete。max_report_pages 独立约束全库报告。

    open_range_wal_source

    fn open_range_wal_source(source : RangeWalSource, limits? : Limits, max_report_pages? : Int) -> Database raise SqliteError

    从已校验的 64 位覆盖源打开 Database,使用提交逻辑页数;初始化失败没有部分检查报告,调用者仍管理源生命周期。

    open_source

    fn open_source(source : &PageSource, limits? : Limits) -> Database raise SqliteError

    打开旧同步 PageSource;初始化只请求 100 字节头。长度/偏移受 Int 限制,宿主 SqliteError 保留历史分类;调用者管理源生命周期。

    open_wal_database

    fn open_wal_database(base : Bytes, wal : Bytes, limits? : Limits, tail_policy? : WalTailPolicy, max_frames? : Int) -> Database raise SqliteError

    便捷打开完整静态 db/WAL 字节;不是在线锁、checkpoint 或恢复协议。默认严格尾部策略,空 WAL 使用主文件。

    open_wal_source

    fn open_wal_source(source : WalSource, limits? : Limits) -> Database raise SqliteError

    从已构造的 WAL 覆盖源打开只读 Database;使用提交逻辑页数,包括缩小和增长,不把旧主文件页数当快照页数。

    parse_header

    fn parse_header(data : Bytes) -> Header raise SqliteError

    验证至少 100 字节的 SQLite 文件头,不读取页面;页长编码 1 还原为 65536。输入无效或格式不支持时抛 SqliteError。

    parse_wal_header

    fn parse_wal_header(data : Bytes) -> WalHeader raise SqliteError

    验证 WAL header;头部不完整、格式或 checksum 错误直接抛出错误。 验证 32 字节 WAL header、magic、版本、页长及 checksum;不扫描帧。