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
//! Utilities for working with SQLite's "sqlite3_extension_init"-style
//! entrypoints.
use crate::{
errors::Result,
ext::{faux_sqlite_extension_init2, sqlite3, sqlite3_api_routines},
};
use sqlite3ext_sys::SQLITE_OK;
use std::os::raw::{c_char, c_uint};
/// Low-level wrapper around a typical entrypoint to a SQLite extension.
/// You shouldn't have to use this directly - the sqlite_entrypoint
/// macro will do this for you.
pub fn register_entrypoint<F>(
db: *mut sqlite3,
_pz_err_msg: *mut *mut c_char,
p_api: *mut sqlite3_api_routines,
callback: F,
) -> c_uint
where
F: Fn(*mut sqlite3) -> Result<()>,
{
unsafe {
faux_sqlite_extension_init2(p_api);
}
match callback(db) {
Ok(()) => SQLITE_OK,
Err(err) => err.code_extended(),
}
}
/// Low-level wrapper around an entrypoint to a SQLite extension that loads permanently. You
/// shouldn't have to use this directly - the sqlite_entrypoint_permanent macro will do this
/// for you.
pub fn register_entrypoint_load_permanently<F>(
db: *mut sqlite3,
_pz_err_msg: *mut *mut c_char,
p_api: *mut sqlite3_api_routines,
callback: F,
) -> c_uint
where
F: Fn(*mut sqlite3) -> Result<()>,
{
unsafe {
faux_sqlite_extension_init2(p_api);
}
match callback(db) {
Ok(()) => 256, // https://www.sqlite.org/rescode.html#ok_load_permanently
Err(err) => err.code_extended(),
}
}