Merge pull request #985 from gwenn/cache_flush

Access to sqlite3_db_cacheflush via Connection
This commit is contained in:
gwenn 2021-07-03 18:02:34 +02:00 committed by GitHub
commit 10da56788c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -302,6 +302,12 @@ impl InnerConnection {
false
}
#[cfg(feature = "modern_sqlite")] // 3.10.0
pub fn cache_flush(&mut self) -> Result<()> {
check!(unsafe { ffi::sqlite3_db_cacheflush(self.db()) });
Ok(())
}
#[cfg(not(feature = "hooks"))]
#[inline]
fn remove_hooks(&mut self) {}

View File

@ -868,6 +868,13 @@ impl Connection {
pub fn is_busy(&self) -> bool {
self.db.borrow().is_busy()
}
/// Flush caches to disk mid-transaction
#[cfg(feature = "modern_sqlite")] // 3.10.0
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
pub fn cache_flush(&self) -> Result<()> {
self.db.borrow_mut().cache_flush()
}
}
impl fmt::Debug for Connection {
@ -1956,4 +1963,11 @@ mod test {
assert_eq!(row_id, 1);
Ok(())
}
#[test]
#[cfg(feature = "modern_sqlite")]
fn test_cache_flush() -> Result<()> {
let db = checked_memory_handle();
db.cache_flush()
}
}