expose heap limits as global functions

This commit is contained in:
vms 2023-03-01 14:02:25 +03:00
parent 7852fed264
commit 36291cd6e8
2 changed files with 22 additions and 4 deletions

View File

@ -55,10 +55,6 @@ impl Connection {
}
}
pub fn set_memory_limit(limit: i64) -> i64 {
unsafe { ffi::sqlite3_hard_heap_limit64(limit) }
}
/// Execute a statement without processing the resulting rows if any.
#[inline]
pub fn execute<T: AsRef<str>>(&self, statement: T) -> Result<()> {
@ -93,6 +89,7 @@ impl Connection {
/// Create a prepared statement.
#[inline]
pub fn prepare<T: AsRef<str>>(&self, statement: T) -> Result<Statement> {
pub fn prepare<T: AsRef<str>>(&self, statement: T) -> Result<Statement> {
crate::statement::new(self.raw, statement)
}

View File

@ -304,3 +304,24 @@ fn last_error(raw: ffi::Sqlite3DbHandle) -> Option<Error> {
})
}
}
/// From the SQLite docs:
///
/// The sqlite3_soft_heap_limit64() interface sets and/or queries the soft limit on the amount of
/// heap memory that may be allocated by SQLite. SQLite strives to keep heap memory utilization
/// below the soft heap limit by reducing the number of pages held in the page cache as heap memory
/// usages approaches the limit. The soft heap limit is "soft" because even though SQLite strives
/// to stay below the limit, it will exceed the limit rather than generate an SQLITE_NOMEM error.
/// In other words, the soft heap limit is advisory only.
pub fn soft_heap_limit64(limit: i64) -> i64 {
unsafe { ffi::sqlite3_hard_heap_limit64(limit) }
}
/// From the SQLite docs:
///
/// This interface sets a hard upper bound of N bytes on the amount of memory that will be
/// allocated. The set_hard_heap_limit64 interface is similar to soft_heap_limit64
/// except that memory allocations will fail when the hard heap limit is reached.
pub fn set_hard_heap_limit64(limit: i64) -> i64 {
unsafe { ffi::sqlite3_hard_heap_limit64(limit) }
}