MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / write_sqlite_file_header

Function write_sqlite_file_header

internal/cbm/sqlite_writer.c:1814–1838  ·  view source on GitHub ↗

Write the SQLite file header on page 1 with master entries. */

Source from the content-addressed store, hash-verified

1812
1813/* Write the SQLite file header on page 1 with master entries. */
1814static void write_sqlite_file_header(uint8_t *page1, uint32_t total_pages) {
1815 memcpy(page1, "SQLite format 3\000", 16);
1816 put_u16(page1 + HDR_OFF_CBM_PAGE_SIZE,
1817 CBM_PAGE_SIZE == SQLITE_MAX_PAGE_SIZE ? (uint16_t)SKIP_ONE : (uint16_t)CBM_PAGE_SIZE);
1818 page1[HDR_OFF_WRITE_VERSION] = FILE_FORMAT;
1819 page1[HDR_OFF_READ_VERSION] = FILE_FORMAT;
1820 page1[HDR_OFF_RESERVED] = 0;
1821 page1[HDR_OFF_MAX_EMBED_FRAC] = MAX_EMBED_FRACTION;
1822 page1[HDR_OFF_MIN_EMBED_FRAC] = MIN_EMBED_FRACTION;
1823 page1[HDR_OFF_LEAF_FRAC] = LEAF_PAYLOAD_FRACTION;
1824 put_u32(page1 + HDR_OFF_FILE_CHANGE, SKIP_ONE);
1825 put_u32(page1 + HDR_OFF_DB_SIZE, total_pages);
1826 put_u32(page1 + HDR_OFF_FREELIST_TRUNK, 0);
1827 put_u32(page1 + HDR_OFF_FREELIST_COUNT, 0);
1828 put_u32(page1 + HDR_OFF_SCHEMA_COOKIE, SKIP_ONE);
1829 put_u32(page1 + HDR_OFF_SCHEMA_FORMAT, SCHEMA_FORMAT);
1830 put_u32(page1 + HDR_OFF_DEFAULT_CACHE, 0);
1831 put_u32(page1 + HDR_OFF_AUTOVAC_TOP, 0);
1832 put_u32(page1 + HDR_OFF_TEXT_ENCODING, SKIP_ONE);
1833 put_u32(page1 + HDR_OFF_USER_VERSION, 0);
1834 put_u32(page1 + HDR_OFF_INCR_VACUUM, 0);
1835 put_u32(page1 + HDR_OFF_APP_ID, 0);
1836 put_u32(page1 + HDR_OFF_VERSION_VALID, SKIP_ONE);
1837 put_u32(page1 + HDR_OFF_SQLITE_VERSION, SQLITE_VERSION);
1838}
1839
1840/* Build master records, write page 1 B-tree + file header. */
1841static int write_master_page1(FILE *fp, MasterEntry *master, int master_count, uint32_t next_page) {

Callers 1

write_master_page1Function · 0.85

Calls 2

put_u16Function · 0.85
put_u32Function · 0.85

Tested by

no test coverage detected