pub struct DatabaseHeader {Show 18 fields
pub page_size: PageSize,
pub write_version: u8,
pub read_version: u8,
pub reserved_per_page: u8,
pub change_counter: u32,
pub page_count: u32,
pub freelist_trunk: u32,
pub freelist_count: u32,
pub schema_cookie: u32,
pub schema_format: u32,
pub default_cache_size: i32,
pub largest_root_page: u32,
pub text_encoding: TextEncoding,
pub user_version: u32,
pub incremental_vacuum: u32,
pub application_id: u32,
pub version_valid_for: u32,
pub sqlite_version: u32,
}Expand description
The 100-byte database file header layout.
This struct represents the parsed content of the first 100 bytes of a SQLite database file.
Fields§
§page_size: PageSizePage size in bytes (stored as big-endian u16 at offset 16; value 1 means 65536).
write_version: u8File format write version (1 = legacy, 2 = WAL).
read_version: u8File format read version (1 = legacy, 2 = WAL).
reserved_per_page: u8Reserved bytes per page (at offset 20).
change_counter: u32File change counter (at offset 24).
page_count: u32Total number of pages in the database file.
freelist_trunk: u32Page number of the first freelist trunk page (0 if none).
freelist_count: u32Total number of freelist pages.
Schema cookie (incremented on schema changes).
schema_format: u32Schema format number (currently 4).
default_cache_size: i32Default page cache size (from PRAGMA default_cache_size).
largest_root_page: u32Largest root page number for auto-vacuum/incremental-vacuum (0 if not auto-vacuum).
text_encoding: TextEncodingDatabase text encoding (1=UTF8, 2=UTF16le, 3=UTF16be).
user_version: u32User version (from PRAGMA user_version).
incremental_vacuum: u32Non-zero for incremental vacuum mode.
application_id: u32Application ID (from PRAGMA application_id).
version_valid_for: u32Version-valid-for number (the change counter value when the version number was stored).
sqlite_version: u32SQLite version number that created the database.
Implementations§
Source§impl DatabaseHeader
impl DatabaseHeader
Sourcepub fn from_bytes(buf: &[u8; 100]) -> Result<Self, DatabaseHeaderError>
pub fn from_bytes(buf: &[u8; 100]) -> Result<Self, DatabaseHeaderError>
Parse and validate a 100-byte database header.
Sourcepub const fn open_mode(
&self,
max_supported: u8,
) -> Result<DatabaseOpenMode, DatabaseHeaderError>
pub const fn open_mode( &self, max_supported: u8, ) -> Result<DatabaseOpenMode, DatabaseHeaderError>
Compute the open mode implied by the header’s read/write version bytes.
Sourcepub const fn is_page_count_stale(&self) -> bool
pub const fn is_page_count_stale(&self) -> bool
Check whether the header-derived database size might be stale.
When version_valid_for != change_counter, header-derived fields
like page_count may be stale and should be recomputed from the
actual file size. This protects against partial header writes or
external modification.
Sourcepub const fn page_count_from_file_size(&self, file_size: u64) -> Option<u32>
pub const fn page_count_from_file_size(&self, file_size: u64) -> Option<u32>
Compute the page count from the actual file size.
This should be used when is_page_count_stale() returns true.
Returns None if the file size is not a multiple of the page size
or would exceed u32::MAX pages.
Sourcepub fn write_to_bytes(
&self,
out: &mut [u8; 100],
) -> Result<(), DatabaseHeaderError>
pub fn write_to_bytes( &self, out: &mut [u8; 100], ) -> Result<(), DatabaseHeaderError>
Serialize this header into a 100-byte buffer.
Trait Implementations§
Source§impl Clone for DatabaseHeader
impl Clone for DatabaseHeader
Source§fn clone(&self) -> DatabaseHeader
fn clone(&self) -> DatabaseHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DatabaseHeader
impl Debug for DatabaseHeader
Source§impl Default for DatabaseHeader
impl Default for DatabaseHeader
impl Eq for DatabaseHeader
Source§impl PartialEq for DatabaseHeader
impl PartialEq for DatabaseHeader
Source§fn eq(&self, other: &DatabaseHeader) -> bool
fn eq(&self, other: &DatabaseHeader) -> bool
self and other values to be equal, and is used by ==.