2016-07-05 71 views
1

可以在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.

欲使用该功能的使用和创建一个正常,空数据库尝试过了,手动改变该字节(报头,在偏移20;使用十六进制编辑器),以一个非空值( - >十六个保留字节的x10)。

在sqlite3的使用.dbinfo:

(…) reserved bytes: 16 (…)

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

Error: database disk image is malformed

所以我的问题是:如何创建一个SQLite数据库与该保留的空间(这将不会被拒绝畸形)?

回答

2

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


无论如何,如果SQLite库不与SQLITE_OMIT_BUILTIN_TEST编译,你可以使用sqlite3_test_control() function设置这个值(一个空数据库):

sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N) 
相关问题