Struct sqlite3_ext::PassedRef

source ·
#[repr(C)]
pub struct PassedRef<T: 'static> { /* private fields */ }
Expand description

Pass arbitrary values through SQLite.

Values of this type can be passed into SQL queries and returned by SQL functions, and later retrieved using ValueRef::get_ref. SQLite takes ownership of the stored value, and does not provide any mechanism for getting a PassedRef from a query result, so this feature is primarily useful for passing values into SQL, or between application-defined functions.

This mechanism relies on std::any::Any to ensure type safety, which requires that values are 'static. If you want to transfer a reference through a PassedRef, use a shared pointer like std::rc::Rc.

This feature requires SQLite 3.20.0. On earlier versions of SQLite, returning a PassedRef object from an application-defined function has no effect. If supporting older versions of SQLite is required, UnsafePtr can be used instead.

Examples

This example shows produce_ref returning a PassedRef which is later consumed by consume_ref.

use sqlite3_ext::{PassedRef, function::Context, Result, ValueRef};

fn produce_ref(ctx: &Context, args: &mut [&mut ValueRef]) -> PassedRef<String> {
    let val = "owned string".to_owned();
    PassedRef::new(val)
}

fn consume_ref(ctx: &Context, args: &mut [&mut ValueRef]) -> Result<()> {
    let val = args[0].get_ref::<String>().unwrap();
    assert_eq!(val, "owned string");
    Ok(())
}

Implementations§

Create a new PassedRef containing the value.

Trait Implementations§

Formats the value using the given formatter. Read more

Sets the parameter to NULL with this value as an associated pointer.

Bind this value to the prepared Statement at the provided position. Read more

Sets the context result to NULL with this value as an associated pointer.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.