mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
sqlite3: Add sqlite3_wal_checkpoint_*() API
This wires up checkpointing to the SQLite C API. We don't respect the checkpointing mode because core does not have that nor do we report back some stats. Refs: #478
This commit is contained in:
parent
636b78d4ff
commit
f1937ee47f
1 changed files with 38 additions and 0 deletions
|
@ -28,6 +28,11 @@ pub const SQLITE_STATE_OPEN: u8 = 0x76;
|
|||
pub const SQLITE_STATE_SICK: u8 = 0xba;
|
||||
pub const SQLITE_STATE_BUSY: u8 = 0x6d;
|
||||
|
||||
pub const SQLITE_CHECKPOINT_PASSIVE: ffi::c_int = 0;
|
||||
pub const SQLITE_CHECKPOINT_FULL: ffi::c_int = 1;
|
||||
pub const SQLITE_CHECKPOINT_RESTART: ffi::c_int = 2;
|
||||
pub const SQLITE_CHECKPOINT_TRUNCATE: ffi::c_int = 3;
|
||||
|
||||
pub mod util;
|
||||
|
||||
use util::sqlite3_safety_check_sick_or_ok;
|
||||
|
@ -918,3 +923,36 @@ fn sqlite3_errstr_impl(rc: i32) -> *const std::ffi::c_char {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sqlite3_wal_checkpoint(
|
||||
_db: *mut sqlite3,
|
||||
_db_name: *const std::ffi::c_char,
|
||||
) -> ffi::c_int {
|
||||
sqlite3_wal_checkpoint_v2(
|
||||
_db,
|
||||
_db_name,
|
||||
SQLITE_CHECKPOINT_PASSIVE,
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sqlite3_wal_checkpoint_v2(
|
||||
db: *mut sqlite3,
|
||||
_db_name: *const std::ffi::c_char,
|
||||
_mode: ffi::c_int,
|
||||
_log_size: *mut ffi::c_int,
|
||||
_checkpoint_count: *mut ffi::c_int,
|
||||
) -> ffi::c_int {
|
||||
if db.is_null() {
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
let db: &mut sqlite3 = &mut *db;
|
||||
// TODO: Checkpointing modes and reporting back log size and checkpoint count to caller.
|
||||
if let Err(e) = db.conn.checkpoint() {
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
SQLITE_OK
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue