Skip to main content

CopyBindInfo

Struct CopyBindInfo 

Source
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

Source

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.

Source

pub fn column_count(&self) -> u64

Returns the number of columns in the output.

Source

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.

Source

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.

Source

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: compression arrives as COMPRESSION, whatever case the user typed. FORMAT itself is not among them.
  • No options at all gives a SQL NULL, not an empty STRUCT: the returned Value is non-null as a handle but is_sql_null, and has no fields.
  • An option with no value ((FORMAT f, HEADER)) is a NULL field.
  • An option with several values (LST (1, 2)) is a LIST when they share a type and an unnamed STRUCT otherwise; one value is that value.
  • An explicit NULL value ((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()
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn as_raw(&self) -> duckdb_copy_function_bind_info

Returns the underlying raw handle.

Trait Implementations§

Source§

impl Debug for CopyBindInfo

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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