Skip to main content

SqliteValue

Enum SqliteValue 

Source
pub enum SqliteValue {
    Null,
    Integer(i64),
    Float(f64),
    Text(Arc<str>),
    Blob(Arc<[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

A NULL value.

§

Integer(i64)

A signed 64-bit integer.

§

Float(f64)

A 64-bit IEEE floating point number.

§

Text(Arc<str>)

A UTF-8 text string.

Uses Arc<str> so that register copies (SCopy, Copy, ResultRow) are O(1) atomic refcount increments instead of O(n) heap copies.

§

Blob(Arc<[u8]>)

A binary large object.

Uses Arc<[u8]> for the same O(1)-clone benefit as Text.

Implementations§

Source§

impl SqliteValue

Source

pub const fn affinity(&self) -> TypeAffinity

Returns the type affinity that best describes this value.

Source

pub const fn storage_class(&self) -> StorageClass

Returns the storage class of this value.

Source

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.
Source

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.

Source

pub const fn is_null(&self) -> bool

Returns true if this is a NULL value.

Source

pub const fn as_integer(&self) -> Option<i64>

Try to extract an integer value.

Source

pub fn as_float(&self) -> Option<f64>

Try to extract a float value.

Source

pub fn as_text(&self) -> Option<&str>

Try to extract a text reference.

Source

pub fn as_blob(&self) -> Option<&[u8]>

Try to extract a blob reference.

Source

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
Source

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
Source

pub fn as_text_str(&self) -> Option<&str>

Borrow the inner text string without allocating.

Returns Some(&str) for Text values, None otherwise. Use this in comparisons, LIKE patterns, and WHERE clause evaluation to avoid the clone that to_text() incurs.

Source

pub fn as_blob_bytes(&self) -> Option<&[u8]>

Borrow the inner blob bytes without allocating.

Source

pub fn to_text(&self) -> String

Convert to text following SQLite’s CAST(x AS TEXT) coercion rules.

For blobs, this interprets the raw bytes as UTF-8 (with lossy replacement for invalid sequences), matching C SQLite behavior. For the SQL-literal hex format (X'...'), use the Display impl.

Source

pub fn cast_to_numeric(&self) -> Self

Convert to NUMERIC using SQLite CAST semantics rather than affinity.

Unlike NUMERIC affinity, CAST always produces a numeric storage class for text/blob input, using the longest leading numeric prefix or 0 when no numeric prefix exists.

Source

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”.

Source

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
Source

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).

Source

pub fn is_integer_numeric_type(&self) -> bool

Mirrors C SQLite’s numericType() (SQLite VDBE:496): returns true if this value should be treated as an integer for arithmetic purposes.

Integer values are obviously integer-typed. Text/Blob values that parse as i64 are also integer-typed. Float and Null are not.

Source

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).
  • Text/Blob coerced via numericType(): if both parse as integer, integer math is used (SQLite VDBE:1932-1934).
Source

pub fn sql_sub(&self, other: &Self) -> Self

Subtract two values following SQLite’s overflow semantics.

Integer - Integer with overflow promotes to REAL.

Source

pub fn sql_mul(&self, other: &Self) -> Self

Multiply two values following SQLite’s overflow semantics.

Integer * Integer with overflow promotes to REAL.

Trait Implementations§

Source§

impl Clone for SqliteValue

Source§

fn clone(&self) -> SqliteValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SqliteValue

Source§

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

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

impl<'de> Deserialize<'de> for SqliteValue

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for SqliteValue

Source§

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

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

impl From<&[u8]> for SqliteValue

Source§

fn from(b: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for SqliteValue

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<[u8]>> for SqliteValue

Source§

fn from(b: Arc<[u8]>) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<str>> for SqliteValue

Source§

fn from(s: Arc<str>) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>> From<Option<T>> for SqliteValue

Source§

fn from(opt: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for SqliteValue

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for SqliteValue

Source§

fn from(b: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for SqliteValue

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for SqliteValue

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for SqliteValue

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl Ord for SqliteValue

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SqliteValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for SqliteValue

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for SqliteValue

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for SqliteValue

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,