pub struct CopyBindInfo { /* private fields */ }Expand description
Wrapper around the duckdb_copy_function_bind_info handle provided to a
copy function bind callback.
Implementations§
Source§impl CopyBindInfo
impl CopyBindInfo
Sourcepub const unsafe fn new(info: duckdb_copy_function_bind_info) -> Self
pub const unsafe fn new(info: duckdb_copy_function_bind_info) -> Self
Wraps a raw duckdb_copy_function_bind_info handle.
§Safety
info must be a valid handle passed by DuckDB to a copy function bind
callback.
Sourcepub fn column_count(&self) -> u64
pub fn column_count(&self) -> u64
Returns the number of columns in the output.
Sourcepub unsafe fn column_type(&self, index: u64) -> Option<LogicalType>
pub unsafe fn column_type(&self, index: u64) -> Option<LogicalType>
Returns the logical type of the column at index, or None if
index is not less than column_count.
duckdb_copy_function_bind_get_column_type returns a null handle for
an out-of-range index; wrapping that in a LogicalType would hand
DuckDB a null pointer on the first use. This mirrors
BindInfo::result_column_type.
§Safety
Must be called during the bind callback, while self.info is live.
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 on the copy function.
§Safety
The returned pointer is only valid as long as the copy function is
registered and DuckDB has not yet called the destructor.
Sourcepub fn options(&self) -> Option<Value>
pub fn options(&self) -> Option<Value>
The options given to the COPY … TO statement, as a STRUCT value.
COPY t TO 'f' (FORMAT my_format, COMPRESSION 'zstd', LEVEL 3) arrives
here as a STRUCT whose fields are the option names. Read them with
Value::struct_field_names
and Value::struct_child.
How DuckDB 1.5.5 builds it (MakeValueFromCopyOptions,
src/main/capi/copy_function-c.cpp):
- Field names are upper-cased:
compressionarrives asCOMPRESSION, whatever case the user typed.FORMATitself is not among them. - No options at all gives a SQL
NULL, not an emptySTRUCT: the returnedValueis non-null as a handle butis_sql_null, and has no fields. - An option with no value (
(FORMAT f, HEADER)) is aNULLfield. - An option with several values (
LST (1, 2)) is aLISTwhen they share a type and an unnamedSTRUCTotherwise; one value is that value. - An explicit
NULLvalue ((FORMAT f, X NULL)) never gets here: the binder rejects it (“NULL is not supported as a valid option”).
Returns None only when DuckDB hands back a null handle.
§Example
use quack_rs::copy_function::CopyBindInfo;
let options = bind.options()?;
if options.is_sql_null() {
return None; // COPY ... (FORMAT my_format) with no other options
}
let names = options.struct_field_names();
// Option names arrive upper-cased.
let idx = names.iter().position(|n| n == "COMPRESSION")?;
options.struct_child(idx)?.as_str().ok()Sourcepub unsafe fn set_bind_data(
&self,
data: *mut c_void,
destroy: duckdb_delete_callback_t,
)
pub unsafe fn set_bind_data( &self, data: *mut c_void, destroy: duckdb_delete_callback_t, )
Sets the bind data pointer and its destructor.
§Safety
data must remain valid until DuckDB calls destroy, or for the
lifetime of the query if destroy is None.
Sourcepub fn set_bind_data_typed<T: Send + Sync + 'static>(&self, data: T)
pub fn set_bind_data_typed<T: Send + Sync + 'static>(&self, data: T)
Stores data as this statement’s bind data: the safe, typed form of
set_bind_data. Read it with bind_data_ref
in the global init, sink and finalize callbacks.
quack-rs boxes data behind a type tag and generates its destructor,
which contains a panic in T::drop. DuckDB runs it once, when the
statement’s bind result is released — also when a later callback
reports an error (copy_function-c.cpp hands the pointer to its bind
result before it checks for one). T is Send + Sync because every
sink thread reads it. Call this at most once per bind: a second call
replaces the first value, which is then never dropped.
Sourcepub unsafe fn extra_info_ref<T: 'static>(&self) -> Option<&T>
pub unsafe fn extra_info_ref<T: 'static>(&self) -> Option<&T>
Borrows the copy function’s extra info, set with
CopyFunctionBuilder::extra_info_typed,
as a T; None when none was set or it holds another type.
§Safety
The extra info, if any, was set through extra_info_typed, not the
raw extra_info, whose pointer carries no type tag.
Sourcepub fn set_error(&self, message: &str)
pub fn set_error(&self, message: &str)
Reports a fatal error, causing DuckDB to abort the current query.
An interior null byte in message is replaced by ?, and an empty
message by EMPTY_ERROR_PLACEHOLDER.
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.