sqlite3: API function tracing

This commit is contained in:
Pekka Enberg
2024-07-17 12:33:55 +03:00
parent 8fb50cc9bc
commit 4efa6e5efa
3 changed files with 38 additions and 1 deletions

27
Cargo.lock generated
View File

@@ -526,6 +526,16 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
[[package]]
name = "env_filter"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.10.2"
@@ -539,6 +549,19 @@ dependencies = [
"termcolor",
]
[[package]]
name = "env_logger"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@@ -952,7 +975,7 @@ dependencies = [
"clap 4.5.8",
"cli-table",
"dirs",
"env_logger",
"env_logger 0.10.2",
"limbo_core",
"rustyline",
]
@@ -1006,7 +1029,9 @@ name = "limbo_sqlite3"
version = "0.0.0"
dependencies = [
"cbindgen",
"env_logger 0.11.3",
"limbo_core",
"log",
]
[[package]]

View File

@@ -16,4 +16,6 @@ doc = false
cbindgen = "0.24.0"
[dependencies]
env_logger = "0.11.3"
limbo_core = { path = "../core" }
log = "0.4.22"

View File

@@ -1,6 +1,7 @@
#![allow(clippy::missing_safety_doc)]
#![allow(non_camel_case_types)]
use log::trace;
use std::cell::RefCell;
use std::ffi;
use std::rc::Rc;
@@ -36,8 +37,13 @@ impl<'a> sqlite3_stmt<'a> {
}
}
static INIT_DONE: std::sync::Once = std::sync::Once::new();
#[no_mangle]
pub unsafe extern "C" fn sqlite3_initialize() -> ffi::c_int {
INIT_DONE.call_once(|| {
env_logger::init();
});
SQLITE_OK
}
@@ -51,6 +57,7 @@ pub unsafe extern "C" fn sqlite3_open(
filename: *const ffi::c_char,
db_out: *mut *mut sqlite3,
) -> ffi::c_int {
trace!("sqlite3_open");
let rc = sqlite3_initialize();
if rc != SQLITE_OK {
return rc;
@@ -87,11 +94,13 @@ pub unsafe extern "C" fn sqlite3_open_v2(
_flags: ffi::c_int,
_z_vfs: *const ffi::c_char,
) -> ffi::c_int {
trace!("sqlite3_open_v2");
sqlite3_open(filename, db_out)
}
#[no_mangle]
pub unsafe extern "C" fn sqlite3_close(db: *mut sqlite3) -> ffi::c_int {
trace!("sqlite3_close");
if db.is_null() {
return SQLITE_OK;
}
@@ -101,6 +110,7 @@ pub unsafe extern "C" fn sqlite3_close(db: *mut sqlite3) -> ffi::c_int {
#[no_mangle]
pub unsafe extern "C" fn sqlite3_close_v2(db: *mut sqlite3) -> ffi::c_int {
trace!("sqlite3_close_v2");
sqlite3_close(db)
}