gpt4 book ai didi

database - 如何创建具有保留字节的数据库?

转载 作者:搜寻专家 更新时间:2023-10-30 22:35:22 34 4
gpt4 key购买 nike

可以在 SQLite 数据库中的每一页末尾保留字节。

根据documentation :

SQLite has the ability to set aside a small number of extra bytes at the end of every page for use by extensions. These extra bytes are used, for example, by the SQLite Encryption Extension to store a nonce and/or cryptographic checksum associated with each page. The "reserved space" size in the 1-byte integer at offset 20 is the number of bytes of space at the end of each page to reserve for extensions. This value is usually 0. The value can be odd.

我想使用此功能并尝试创建一个普通的空数据库并手动将字节( header ,偏移量为 20;使用十六进制编辑器)更改为非空值(-> x10 用于 16 个保留字节).

在 sqlite3 中使用 .dbinfo:

(…) reserved bytes: 16 (…)

所以一切似乎都是正确的,但是没有一个编辑数据库的命令会成功。每个命令(例如 CREATE TABLE example('id' int);)都会导致此错误消息:

Error: database disk image is malformed

所以我的问题是:如何使用此保留空间(不会因格式错误而被拒绝)创建 SQLite 数据库?

最佳答案

第一个数据库页面不仅包含标题,还包含第一个 B-tree page sqlite_master 表。您必须确保没有任何数据指向页面可用区域之外。如果主表是空的,唯一需要调整的是指向 B 树头偏移量 5 处的单元格内容区域开始的指针(在这种情况下,它应该简单地指向可用区域的末尾)。


无论如何,如果 SQLite 库不是用 SQLITE_OMIT_BUILTIN_TEST 编译的, 您可以使用 sqlite3_test_control() function设置此值(对于空数据库):

sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)

关于database - 如何创建具有保留字节的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38201975/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com