Add Connection::release_memory method

This is behind a new `release_memory` feature flag. It simply calls
`sqlite3_db_release_memory` on the raw handle.
This commit is contained in:
Nikolai Vazquez 2022-04-17 06:00:15 -04:00 committed by Thom Chiovoloni
parent 7fb2d378af
commit 4d06d2222f
2 changed files with 17 additions and 0 deletions

View File

@ -43,6 +43,8 @@ collation = []
functions = ["libsqlite3-sys/min_sqlite_version_3_7_7"]
# sqlite3_log: 3.6.23 (2010-03-09)
trace = ["libsqlite3-sys/min_sqlite_version_3_6_23"]
# sqlite3_db_release_memory: 3.7.10 (2012-01-16)
release_memory = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
bundled = ["libsqlite3-sys/bundled", "modern_sqlite"]
bundled-sqlcipher = ["libsqlite3-sys/bundled-sqlcipher", "bundled"]
bundled-sqlcipher-vendored-openssl = ["libsqlite3-sys/bundled-sqlcipher-vendored-openssl", "bundled-sqlcipher"]

View File

@ -595,6 +595,21 @@ impl Connection {
self.path.as_deref()
}
/// Attempts to free as much heap memory as possible from the database
/// connection.
///
/// This calls [`sqlite3_db_release_memory`](https://www.sqlite.org/c3ref/db_release_memory.html).
#[inline]
#[cfg(feature = "release_memory")]
pub fn release_memory(&self) -> Result<()> {
unsafe {
match crate::ffi::sqlite3_db_release_memory(self.handle()) {
ffi::SQLITE_OK => Ok(()),
error => Err(error_from_sqlite_code(error)),
}
}
}
/// Convenience method to prepare and execute a single SQL statement with
/// named parameter(s).
///