pub struct ScalarInitInfo { /* private fields */ }Expand description
Ergonomic wrapper around the duckdb_init_info handle provided to a
scalar function init callback (DuckDB 1.5.0+).
Provides access to extra info, bind data, per-thread state storage, and error reporting.
Implementations§
Source§impl ScalarInitInfo
impl ScalarInitInfo
Sourcepub const unsafe fn new(info: RawScalarInitInfo) -> Self
pub const unsafe fn new(info: RawScalarInitInfo) -> Self
Wraps the info DuckDB passes to a scalar function init callback.
Breaking in 0.18.0: takes a RawScalarInitInfo, the argument type
of ScalarInitFn, not a bare
duckdb_init_info.
§Safety
info must be the argument DuckDB passed to a scalar function init
callback that is still running.
Sourcepub unsafe fn get_extra_info(&self) -> *mut c_void
pub unsafe fn get_extra_info(&self) -> *mut c_void
Retrieves the extra-info pointer previously set via
ScalarFunctionBuilder::extra_info.
Returns a raw *mut c_void. Cast it back to your concrete type.
§Safety
The returned pointer is only valid as long as the scalar function is
registered and DuckDB has not yet called the destructor.
Sourcepub unsafe fn get_bind_data(&self) -> *mut c_void
pub unsafe fn get_bind_data(&self) -> *mut c_void
Retrieves the bind data pointer previously set via
ScalarBindInfo::set_bind_data during the bind callback.
Returns a raw *mut c_void. Cast it back to your concrete type.
§Safety
The returned pointer is only valid as long as DuckDB has not yet called
the destructor registered with ScalarBindInfo::set_bind_data.
Sourcepub unsafe fn set_state(
&self,
state: *mut c_void,
destroy: duckdb_delete_callback_t,
)
pub unsafe fn set_state( &self, state: *mut c_void, destroy: duckdb_delete_callback_t, )
Stores per-thread state that can later be retrieved during execution
via ScalarFunctionInfo::get_state.
A second call overwrites the pointer and destructor without running the first destructor: the first value is leaked.
§Safety
state must point to valid memory. destroy will be called by DuckDB
to free the state when the thread finishes. The typical pattern is to box
your data: Box::into_raw(Box::new(my_state)).cast().
Sourcepub fn set_error(&self, message: &str)
pub fn set_error(&self, message: &str)
Reports an error from the scalar function init callback, causing
DuckDB to abort the current query.
An interior NUL byte in message is replaced with ?
(see message_to_c_string),
and an empty message by EMPTY_ERROR_PLACEHOLDER, since DuckDB
would otherwise report only an error-type prefix.
Sourcepub unsafe fn get_client_context(&self) -> ClientContext
pub unsafe fn get_client_context(&self) -> ClientContext
Returns the client context for this callback.
The returned ClientContext provides
access to the connection’s catalog, configuration, and connection ID.
§Safety
The inner handle must be valid (requires DuckDB runtime), and the
returned context must not be used after the connection running this
query is closed — see
ClientContext.