pub enum SqliteValue {
Null,
Integer(i64),
Float(f64),
Text(String),
Blob(Vec<u8>),
}Expand description
A dynamically-typed SQLite value.
Corresponds to C SQLite’s sqlite3_value / Mem type. SQLite has five
fundamental storage classes: NULL, INTEGER, REAL, TEXT, and BLOB.
Variants§
Null
SQL NULL.
Integer(i64)
A 64-bit signed integer.
Float(f64)
A 64-bit IEEE 754 floating-point number.
Text(String)
A UTF-8 text string.
Blob(Vec<u8>)
A binary large object.
Implementations§
Source§impl SqliteValue
impl SqliteValue
Sourcepub const fn affinity(&self) -> TypeAffinity
pub const fn affinity(&self) -> TypeAffinity
Returns the type affinity that best describes this value.
Sourcepub const fn storage_class(&self) -> StorageClass
pub const fn storage_class(&self) -> StorageClass
Returns the storage class of this value.
Sourcepub fn apply_affinity(self, affinity: TypeAffinity) -> Self
pub fn apply_affinity(self, affinity: TypeAffinity) -> Self
Apply column type affinity coercion (advisory mode).
In non-STRICT tables, affinity is advisory: values are coerced when possible but never rejected. Follows SQLite §3.4 rules from https://www.sqlite.org/datatype3.html#type_affinity_of_a_column.
- TEXT affinity: numeric values converted to text before storing.
- NUMERIC affinity: text parsed as integer/real if well-formed.
- INTEGER affinity: like NUMERIC, plus exact-integer reals become integer.
- REAL affinity: like NUMERIC, plus integers forced to float.
- BLOB affinity: no conversion.
Sourcepub fn validate_strict(
self,
col_type: StrictColumnType,
) -> Result<Self, StrictTypeError>
pub fn validate_strict( self, col_type: StrictColumnType, ) -> Result<Self, StrictTypeError>
Validate a value against a STRICT table column type.
NULL is always accepted (nullability is enforced separately via NOT NULL).
Returns Ok(value) with possible implicit coercion (REAL columns accept
integers, converting them to float), or Err if the storage class is
incompatible.
Sourcepub const fn as_integer(&self) -> Option<i64>
pub const fn as_integer(&self) -> Option<i64>
Try to extract an integer value.
Sourcepub fn to_integer(&self) -> i64
pub fn to_integer(&self) -> i64
Convert to an integer following SQLite’s type coercion rules.
- NULL -> 0
- Integer -> itself
- Float -> truncated to i64
- Text -> attempt to parse, 0 on failure
- Blob -> 0
Sourcepub fn to_float(&self) -> f64
pub fn to_float(&self) -> f64
Convert to a float following SQLite’s type coercion rules.
- NULL -> 0.0
- Integer -> as f64
- Float -> itself
- Text -> attempt to parse, 0.0 on failure
- Blob -> 0.0
Sourcepub const fn typeof_str(&self) -> &'static str
pub const fn typeof_str(&self) -> &'static str
Returns the SQLite typeof() string for this value.
Matches C sqlite3: “null”, “integer”, “real”, “text”, or “blob”.
Sourcepub fn sql_length(&self) -> Option<i64>
pub fn sql_length(&self) -> Option<i64>
Returns the SQLite length() result for this value.
- NULL → NULL (represented as None)
- TEXT → character count
- BLOB → byte count
- INTEGER/REAL → character count of text representation
Sourcepub fn unique_eq(&self, other: &Self) -> bool
pub fn unique_eq(&self, other: &Self) -> bool
Check equality for UNIQUE constraint purposes.
In SQLite, NULL != NULL for uniqueness: if either value is NULL, the
result is false (they are never considered duplicates). Non-NULL values
compare by storage class ordering (same as PartialEq).
Sourcepub fn sql_add(&self, other: &Self) -> Self
pub fn sql_add(&self, other: &Self) -> Self
Add two values following SQLite’s overflow semantics.
- Integer + Integer: checked add; overflows promote to REAL.
- Any REAL operand: float addition.
- NULL propagates (NULL + x = NULL).
- Non-numeric types coerced to numeric first.
Trait Implementations§
Source§impl Clone for SqliteValue
impl Clone for SqliteValue
Source§fn clone(&self) -> SqliteValue
fn clone(&self) -> SqliteValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more