2016-07-05 28 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) 
相關問題