【问题标题】:Is SQLite 2 database header format different from that of SQLite 3?SQLite 2 数据库头格式与 SQLite 3 不同吗?
【发布时间】:2019-07-23 19:34:59
【问题描述】:

我通过读取文件的前 16 个字节来确定文件是否为 SQLite 数据库(如https://www.sqlite.org/fileformat.html 中所述)。如果我读过SQLite format 3,那么它就是一个 SQLite 数据库。

我没有示例 SQLite 2 数据库,所以我不知道它有什么标头,也无法在文档中找到它。谁知道标题是什么?

【问题讨论】:

    标签: sqlite file-format


    【解决方案1】:

    SQLite 2 数据库以

    开头
    ** This file contains an SQLite 2.1 database **
    

    我只见过2.1的数据库,但大概2.0的数据库是2.0开头的而不是2.1

    【讨论】:

      【解决方案2】:

      虽然没有明确说明标头已更改,但我相信前 16 个字节会有所不同,至少 3(第 15 个字节 x'33')可能会有所不同不是3,足以让SQLite3认为文件不兼容。

      您可以通过History Of SQLite Releases 获取版本并阅读SQLite Source Repository自述文件。编译并执行适合的测试。

      您还可以找到感兴趣的File Format Changes in SQLiteSQLite Version 3 Overview

      【讨论】:

      • 感谢您的建议。实际上他们没有 2.x.x 版本的下载。我在他们的网站上查找了“SQLite 格式”字符串,发现了这个文件:sqlite.org/src/doc/trunk/magic.txt,但第一次签到是在 2014 年,字符串是“SQLite 格式 3”
      【解决方案3】:

      对于 SQLite 2 数据库,这些是基于 SQLite 2.0.0(GitHub mirrorofficial 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 mirrorofficial 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"
      

      相关版本号取自official file format changes document

      【讨论】:

        猜你喜欢
        • 2020-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-24
        • 2014-03-23
        • 2013-03-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多