quackdb_internal/handles/table_function/
bind_info.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{
    ffi::{c_void, CStr},
    ops::Deref,
};

use crate::{ffi, handles::LogicalTypeHandle};

pub struct BindInfoHandle {
    handle: ffi::duckdb_bind_info,
}

impl BindInfoHandle {
    pub unsafe fn from_raw(handle: ffi::duckdb_bind_info) -> Self {
        Self { handle }
    }
    pub fn get_extra_info(&self) -> *mut c_void {
        unsafe { ffi::duckdb_bind_get_extra_info(**self) }
    }
    pub fn add_result_column(&self, name: &CStr, type_: &LogicalTypeHandle) {
        unsafe { ffi::duckdb_bind_add_result_column(**self, name.as_ptr(), **type_) }
    }
    pub fn get_parameter_count(&self) -> u64 {
        unsafe { ffi::duckdb_bind_get_parameter_count(**self) }
    }
    /// # Safety
    /// * Index must be in range
    /// * Result must be destroyed
    pub unsafe fn get_parameter(&self, index: u64) -> ffi::duckdb_value {
        ffi::duckdb_bind_get_parameter(**self, index)
    }
    /// # Safety
    /// * Index must be in range
    /// * Result must be destroyed
    pub unsafe fn get_named_parameter(&self, name: &CStr) -> ffi::duckdb_value {
        ffi::duckdb_bind_get_named_parameter(**self, name.as_ptr())
    }
    /// # Safety
    /// * Takes ownership of `bind_data`
    /// * `destroy` must outlive `self`
    /// * `destroy()` frees `bind_data`
    pub unsafe fn set_bind_data(
        &self,
        bind_data: *mut c_void,
        destroy: ffi::duckdb_delete_callback_t,
    ) {
        ffi::duckdb_bind_set_bind_data(**self, bind_data, destroy)
    }
    pub fn set_cardinality(&self, cardinality: u64, is_exact: bool) {
        unsafe { ffi::duckdb_bind_set_cardinality(**self, cardinality, is_exact) }
    }
    pub fn set_error(&self, error: &CStr) {
        unsafe { ffi::duckdb_bind_set_error(**self, error.as_ptr()) }
    }
}

impl Deref for BindInfoHandle {
    type Target = ffi::duckdb_bind_info;

    fn deref(&self) -> &Self::Target {
        &self.handle
    }
}