【发布时间】:2019-07-23 19:34:59
【问题描述】:
我通过读取文件的前 16 个字节来确定文件是否为 SQLite 数据库(如https://www.sqlite.org/fileformat.html 中所述)。如果我读过SQLite format 3,那么它就是一个 SQLite 数据库。
我没有示例 SQLite 2 数据库,所以我不知道它有什么标头,也无法在文档中找到它。谁知道标题是什么?
【问题讨论】:
标签: sqlite file-format
我通过读取文件的前 16 个字节来确定文件是否为 SQLite 数据库(如https://www.sqlite.org/fileformat.html 中所述)。如果我读过SQLite format 3,那么它就是一个 SQLite 数据库。
我没有示例 SQLite 2 数据库,所以我不知道它有什么标头,也无法在文档中找到它。谁知道标题是什么?
【问题讨论】:
标签: sqlite file-format
SQLite 2 数据库以
开头** This file contains an SQLite 2.1 database **
我只见过2.1的数据库,但大概2.0的数据库是2.0开头的而不是2.1
【讨论】:
虽然没有明确说明标头已更改,但我相信前 16 个字节会有所不同,至少 3(第 15 个字节 x'33')可能会有所不同不是3,足以让SQLite3认为文件不兼容。
您可以通过History Of SQLite Releases 获取版本并阅读SQLite Source Repository 的自述文件。编译并执行适合的测试。
您还可以找到感兴趣的File Format Changes in SQLite 和SQLite Version 3 Overview。
【讨论】:
对于 SQLite 2 数据库,这些是基于 SQLite 2.0.0(GitHub mirror、official repo 和 SQLite 2.8.0 (@987654323) 的可能前缀(作为引用的 C 字符串,没有隐式尾随 \0) @,official repo,on SourceForge) 源代码,源文件中常量zMagicHeadersrc/btree.c:
"** This file contains an SQLite 2.0 database **\x00\xda\xe3\x75\x28"
"** This file contains an SQLite 2.0 database **\x00\x28\x75\xe3\xda"
"** This file contains an SQLite 2.1 database **\x00\xda\xe3\x75\x28"
"** This file contains an SQLite 2.1 database **\x00\x28\x75\xe3\xda"
对于 SQLite 3 数据库,这些是可能的前缀(作为引用的 C 字符串,没有隐式尾随 \0),基于 official file format documentation 和 SQLite 3.0.0(GitHub mirror,official repo)源代码, 源文件中的常量zMagicHeader src/btree.c:
"SQLite format 3\x00\x00\x01"
"SQLite format 3\x00\x02\x00"
"SQLite format 3\x00\x04\x00"
"SQLite format 3\x00\x08\x00"
"SQLite format 3\x00\x10\x00"
"SQLite format 3\x00\x20\x00"
"SQLite format 3\x00\x40\x00"
"SQLite format 3\x00\x80\x00"
【讨论】: