Skip to main content

DatabaseHeader

Struct DatabaseHeader 

Source
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: PageSize

Page size in bytes (stored as big-endian u16 at offset 16; value 1 means 65536).

§write_version: u8

File format write version (1 = legacy, 2 = WAL).

§read_version: u8

File format read version (1 = legacy, 2 = WAL).

§reserved_per_page: u8

Reserved bytes per page (at offset 20).

§change_counter: u32

File change counter (at offset 24).

§page_count: u32

Total number of pages in the database file.

§freelist_trunk: u32

Page number of the first freelist trunk page (0 if none).

§freelist_count: u32

Total number of freelist pages.

§schema_cookie: u32

Schema cookie (incremented on schema changes).

§schema_format: u32

Schema format number (currently 4).

§default_cache_size: i32

Default page cache size (from PRAGMA default_cache_size).

§largest_root_page: u32

Largest root page number for auto-vacuum/incremental-vacuum (0 if not auto-vacuum).

§text_encoding: TextEncoding

Database text encoding (1=UTF8, 2=UTF16le, 3=UTF16be).

§user_version: u32

User version (from PRAGMA user_version).

§incremental_vacuum: u32

Non-zero for incremental vacuum mode.

§application_id: u32

Application ID (from PRAGMA application_id).

§version_valid_for: u32

Version-valid-for number (the change counter value when the version number was stored).

§sqlite_version: u32

SQLite version number that created the database.

Implementations§

Source§

impl DatabaseHeader

Source

pub fn from_bytes(buf: &[u8; 100]) -> Result<Self, DatabaseHeaderError>

Parse and validate a 100-byte database header.

Source

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.

Source

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.

Source

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.

Source

pub fn write_to_bytes( &self, out: &mut [u8; 100], ) -> Result<(), DatabaseHeaderError>

Serialize this header into a 100-byte buffer.

Source

pub fn to_bytes(&self) -> Result<[u8; 100], DatabaseHeaderError>

Serialize this header to bytes.

Trait Implementations§

Source§

impl Clone for DatabaseHeader

Source§

fn clone(&self) -> DatabaseHeader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DatabaseHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DatabaseHeader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DatabaseHeader

Source§

impl PartialEq for DatabaseHeader

Source§

fn eq(&self, other: &DatabaseHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DatabaseHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more