pub struct CopyGlobalInitInfo { /* private fields */ }Expand description
Wrapper around the duckdb_copy_function_global_init_info handle provided
to a copy function global init callback.
Implementations§
Source§impl CopyGlobalInitInfo
impl CopyGlobalInitInfo
Sourcepub const unsafe fn new(info: duckdb_copy_function_global_init_info) -> Self
pub const unsafe fn new(info: duckdb_copy_function_global_init_info) -> Self
Wraps a raw duckdb_copy_function_global_init_info handle.
§Safety
info must be a valid handle passed by DuckDB to a copy function
global init callback.
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 set during the bind phase.
§Safety
The returned pointer must be cast back to the original type.
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 unsafe fn get_file_path(&self) -> Result<String, ExtensionError>
pub unsafe fn get_file_path(&self) -> Result<String, ExtensionError>
Returns the destination path for the copy operation.
The returned String is a copy. DuckDB keeps ownership of its own
buffer — duckdb_copy_function_global_init_get_file_path returns
info_ref.file_path.c_str(), the interior pointer of a live C++
std::string, so it must not be freed. Doing so corrupts the heap.
§Errors
Returns an error if the path is not valid UTF-8, which a path on Linux
need not be (COPY t TO '~/out.x' with a non-UTF-8 home directory, for
one). A lossy conversion would name a different file, so use
get_file_path_bytes to open such a path.
§Safety
self.info must be a valid handle from an active callback invocation.
Sourcepub unsafe fn get_file_path_bytes(&self) -> Vec<u8> ⓘ
pub unsafe fn get_file_path_bytes(&self) -> Vec<u8> ⓘ
Returns the destination path for the copy operation as the exact bytes
DuckDB holds, whatever their encoding (empty if DuckDB has none).
On Unix, std::ffi::OsStr::from_bytes turns them into a path that
opens the same file. See get_file_path for the
ownership of DuckDB’s buffer.
§Safety
self.info must be a valid handle from an active callback invocation.
Sourcepub unsafe fn set_global_state(
&self,
state: *mut c_void,
destroy: duckdb_delete_callback_t,
)
pub unsafe fn set_global_state( &self, state: *mut c_void, destroy: duckdb_delete_callback_t, )
Sets the global state pointer and its destructor.
§Safety
state must remain valid until DuckDB calls destroy, or for the
lifetime of the query if destroy is None.
Sourcepub fn set_global_state_typed<T: Send + Sync + 'static>(&self, state: T)
pub fn set_global_state_typed<T: Send + Sync + 'static>(&self, state: T)
Stores state as this statement’s global state: the safe, typed form
of set_global_state. Read it with
global_state_ref in the sink and finalize callbacks.
The destructor is generated and panic-safe, as for
CopyBindInfo::set_bind_data_typed, and DuckDB runs it once when
the statement ends, also after a sink or finalize error. T is
Send + Sync because the sink can run on several threads at once:
state they change needs a Mutex or atomics inside T. A
FileHandle kept here belongs in a
Mutex (see its docs on keeping a file open across callbacks). Call
this at most once per global init.
Sourcepub unsafe fn bind_data_ref<T: 'static>(&self) -> Option<&T>
pub unsafe fn bind_data_ref<T: 'static>(&self) -> Option<&T>
Borrows the bind data set with
CopyBindInfo::set_bind_data_typed as a T; None when none was
set or it holds another type.
§Safety
The bind data, if any, was set through set_bind_data_typed, not the
raw set_bind_data, whose pointer carries no type tag.
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 as a T; see
CopyBindInfo::extra_info_ref.
§Safety
As for CopyBindInfo::extra_info_ref.
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.
§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.