MCPcopy Create free account
hub / github.com/asg017/sqlite-loadable-rs / define_table_function

Function define_table_function

src/table.rs:320–375  ·  view source on GitHub ↗

Define a table function on the given sqlite3 database. "Table function" is the same as "eponymous-only" virtual table described at

(
    db: *mut sqlite3,
    name: &str,
    aux: Option<T::Aux>,
)

Source from the content-addressed store, hash-verified

318/// "Table function" is the same as "eponymous-only" virtual table
319/// described at <https://www.sqlite.org/vtab.html#eponymous_only_virtual_tables>
320pub fn define_table_function<'vtab, T: VTab<'vtab> + 'vtab>(
321 db: *mut sqlite3,
322 name: &str,
323 aux: Option<T::Aux>,
324) -> Result<()> {
325 let m = &Module {
326 base: sqlite3_module {
327 iVersion: 2,
328 xCreate: None,
329 xConnect: Some(rust_connect::<T>),
330 xBestIndex: Some(rust_best_index::<T>),
331 xDisconnect: Some(rust_disconnect::<T>),
332 xDestroy: Some(rust_destroy::<T>),
333 xOpen: Some(rust_open::<T>),
334 xClose: Some(rust_close::<T::Cursor>),
335 xFilter: Some(rust_filter::<T::Cursor>),
336 xNext: Some(rust_next::<T::Cursor>),
337 xEof: Some(rust_eof::<T::Cursor>),
338 xColumn: Some(rust_column::<T::Cursor>),
339 xRowid: Some(rust_rowid::<T::Cursor>),
340 xUpdate: None,
341 xBegin: None,
342 xSync: None,
343 xCommit: None,
344 xRollback: None,
345 xFindFunction: None,
346 xRename: None,
347 xSavepoint: None,
348 xRelease: None,
349 xRollbackTo: None,
350 xShadowName: None,
351 },
352 phantom: PhantomData::<&'vtab T>,
353 };
354 let cname = CString::new(name)?;
355 let p_app = match aux {
356 Some(aux) => {
357 let boxed_aux: *mut T::Aux = Box::into_raw(Box::new(aux));
358 boxed_aux.cast::<c_void>()
359 }
360 None => ptr::null_mut(),
361 };
362 let result = unsafe {
363 sqlite3ext_create_module_v2(
364 db,
365 cname.as_ptr(),
366 &m.base,
367 p_app,
368 Some(destroy_aux::<T::Aux>),
369 )
370 };
371 if result != SQLITE_OKAY {
372 return Err(Error::new(ErrorKind::TableFunction(result)));
373 }
374 Ok(())
375}
376pub fn define_table_function_with_find<'vtab, T: VTabFind<'vtab> + 'vtab>(
377 db: *mut sqlite3,

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected