Last active
April 1, 2024 12:57
-
-
Save dvas0004/67e6e77f808862f222577c4ed89f6c86 to your computer and use it in GitHub Desktop.
rusqlite: making a vtab loadable via sqlite3 (https://blog.davidvassallo.me/?p=4083)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[allow(clippy::not_unsafe_ptr_arg_deref)] | |
#[no_mangle] | |
pub extern "C" fn sqlite3_extension_init( | |
db: *mut ffi::sqlite3, | |
pz_err_msg: *mut *mut c_char, | |
p_api: *mut ffi::sqlite3_api_routines, | |
) -> c_int { | |
if p_api.is_null() { | |
return ffi::SQLITE_ERROR; | |
} else if let Err(err) = extension_init(db, p_api) { // we handoff to `extenstion_init` | |
return unsafe { to_sqlite_error(&err, pz_err_msg) }; | |
} | |
ffi::SQLITE_OK | |
} | |
fn extension_init(db: *mut ffi::sqlite3, p_api: *mut ffi::sqlite3_api_routines) -> Result<()> { | |
let db = unsafe { Connection::extension_init2(db, p_api)? }; | |
let module = rusqlite::vtab::eponymous_only_module::<Test>(); | |
db.create_module::<Test>("test", module, None)?; | |
rusqlite::trace::log(ffi::SQLITE_WARNING, "Rusqlite extension initialized"); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment