|
1 | 1 | use super::{
|
2 | 2 | ffi::{
|
3 |
| - duckdb_bind_add_result_column, duckdb_bind_get_extra_info, duckdb_bind_get_parameter, |
4 |
| - duckdb_bind_get_parameter_count, duckdb_bind_info, duckdb_bind_set_bind_data, duckdb_bind_set_cardinality, |
5 |
| - duckdb_bind_set_error, duckdb_create_table_function, duckdb_data_chunk, duckdb_delete_callback_t, |
6 |
| - duckdb_destroy_table_function, duckdb_table_function, duckdb_table_function_add_parameter, |
7 |
| - duckdb_table_function_init_t, duckdb_table_function_set_bind, duckdb_table_function_set_extra_info, |
8 |
| - duckdb_table_function_set_function, duckdb_table_function_set_init, duckdb_table_function_set_local_init, |
9 |
| - duckdb_table_function_set_name, duckdb_table_function_supports_projection_pushdown, idx_t, |
| 3 | + duckdb_bind_add_result_column, duckdb_bind_get_extra_info, duckdb_bind_get_named_parameter, |
| 4 | + duckdb_bind_get_parameter, duckdb_bind_get_parameter_count, duckdb_bind_info, duckdb_bind_set_bind_data, |
| 5 | + duckdb_bind_set_cardinality, duckdb_bind_set_error, duckdb_create_table_function, duckdb_data_chunk, |
| 6 | + duckdb_delete_callback_t, duckdb_destroy_table_function, duckdb_table_function, |
| 7 | + duckdb_table_function_add_named_parameter, duckdb_table_function_add_parameter, duckdb_table_function_init_t, |
| 8 | + duckdb_table_function_set_bind, duckdb_table_function_set_extra_info, duckdb_table_function_set_function, |
| 9 | + duckdb_table_function_set_init, duckdb_table_function_set_local_init, duckdb_table_function_set_name, |
| 10 | + duckdb_table_function_supports_projection_pushdown, idx_t, |
10 | 11 | },
|
11 | 12 | LogicalType, Value,
|
12 | 13 | };
|
@@ -64,8 +65,36 @@ impl BindInfo {
|
64 | 65 | /// * `index`: The index of the parameter to get
|
65 | 66 | ///
|
66 | 67 | /// returns: The value of the parameter
|
| 68 | + /// |
| 69 | + /// # Panics |
| 70 | + /// If requested parameter is out of range for function definition |
67 | 71 | pub fn get_parameter(&self, param_index: u64) -> Value {
|
68 |
| - unsafe { Value::from(duckdb_bind_get_parameter(self.ptr, param_index)) } |
| 72 | + unsafe { |
| 73 | + let ptr = duckdb_bind_get_parameter(self.ptr, param_index); |
| 74 | + if ptr.is_null() { |
| 75 | + panic!("{} is out of range for function definition", param_index); |
| 76 | + } else { |
| 77 | + Value::from(ptr) |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + /// Retrieves the named parameter with the given name. |
| 83 | + /// |
| 84 | + /// # Arguments |
| 85 | + /// * `name`: The name of the parameter to get |
| 86 | + /// |
| 87 | + /// returns: The value of the parameter |
| 88 | + pub fn get_named_parameter(&self, name: &str) -> Option<Value> { |
| 89 | + unsafe { |
| 90 | + let name = &CString::new(name).unwrap(); |
| 91 | + let ptr = duckdb_bind_get_named_parameter(self.ptr, name.as_ptr()); |
| 92 | + if ptr.is_null() { |
| 93 | + None |
| 94 | + } else { |
| 95 | + Some(Value::from(ptr)) |
| 96 | + } |
| 97 | + } |
69 | 98 | }
|
70 | 99 |
|
71 | 100 | /// Sets the cardinality estimate for the table function, used for optimization.
|
@@ -204,6 +233,19 @@ impl TableFunction {
|
204 | 233 | self
|
205 | 234 | }
|
206 | 235 |
|
| 236 | + /// Adds a named parameter to the table function. |
| 237 | + /// |
| 238 | + /// # Arguments |
| 239 | + /// * `name`: The name of the parameter to add. |
| 240 | + /// * `logical_type`: The type of the parameter to add. |
| 241 | + pub fn add_named_parameter(&self, name: &str, logical_type: &LogicalType) -> &Self { |
| 242 | + unsafe { |
| 243 | + let string = CString::new(name).unwrap(); |
| 244 | + duckdb_table_function_add_named_parameter(self.ptr, string.as_ptr(), logical_type.ptr); |
| 245 | + } |
| 246 | + self |
| 247 | + } |
| 248 | + |
207 | 249 | /// Sets the main function of the table function
|
208 | 250 | ///
|
209 | 251 | /// # Arguments
|
|
0 commit comments