mirror of
https://github.com/isar/rusqlite.git
synced 2025-08-20 21:09:31 +08:00
Merge branch 'limits' of https://github.com/gwenn/rusqlite into gwenn-limits
This commit is contained in:
@@ -108,6 +108,7 @@ mod raw_statement;
|
||||
#[cfg(feature = "backup")]pub mod backup;
|
||||
#[cfg(feature = "functions")]pub mod functions;
|
||||
#[cfg(feature = "blob")]pub mod blob;
|
||||
#[cfg(feature = "limits")]pub mod limits;
|
||||
|
||||
// Number of cached prepared statements we'll hold on to.
|
||||
const STATEMENT_CACHE_DEFAULT_CAPACITY: usize = 16;
|
||||
|
68
src/limits.rs
Normal file
68
src/limits.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
//! Run-Time Limits
|
||||
|
||||
use libc::c_int;
|
||||
|
||||
use ffi;
|
||||
pub use ffi::Limit;
|
||||
|
||||
use Connection;
|
||||
|
||||
impl Connection {
|
||||
/// Returns the current value of a limit.
|
||||
pub fn limit(&self, limit: Limit) -> i32 {
|
||||
let c = self.db.borrow();
|
||||
unsafe { ffi::sqlite3_limit(c.db(), limit as c_int, -1) }
|
||||
}
|
||||
/// Changes the limit to `new_val`.
|
||||
/// And returns the prior value of the limit.
|
||||
pub fn set_limit(&self, limit: Limit, new_val: i32) -> i32 {
|
||||
let c = self.db.borrow_mut();
|
||||
unsafe { ffi::sqlite3_limit(c.db(), limit as c_int, new_val) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use ffi::{self, Limit};
|
||||
use Connection;
|
||||
|
||||
#[test]
|
||||
fn test_limit() {
|
||||
let db = Connection::open_in_memory().unwrap();
|
||||
db.set_limit(Limit::SQLITE_LIMIT_LENGTH, 1024);
|
||||
assert_eq!(1024, db.limit(Limit::SQLITE_LIMIT_LENGTH));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_SQL_LENGTH, 1024);
|
||||
assert_eq!(1024, db.limit(Limit::SQLITE_LIMIT_SQL_LENGTH));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_COLUMN, 64);
|
||||
assert_eq!(64, db.limit(Limit::SQLITE_LIMIT_COLUMN));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_EXPR_DEPTH, 256);
|
||||
assert_eq!(256, db.limit(Limit::SQLITE_LIMIT_EXPR_DEPTH));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_COMPOUND_SELECT, 32);
|
||||
assert_eq!(32, db.limit(Limit::SQLITE_LIMIT_COMPOUND_SELECT));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_FUNCTION_ARG, 32);
|
||||
assert_eq!(32, db.limit(Limit::SQLITE_LIMIT_FUNCTION_ARG));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_ATTACHED, 2);
|
||||
assert_eq!(2, db.limit(Limit::SQLITE_LIMIT_ATTACHED));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_LIKE_PATTERN_LENGTH, 128);
|
||||
assert_eq!(128, db.limit(Limit::SQLITE_LIMIT_LIKE_PATTERN_LENGTH));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_VARIABLE_NUMBER, 99);
|
||||
assert_eq!(99, db.limit(Limit::SQLITE_LIMIT_VARIABLE_NUMBER));
|
||||
|
||||
db.set_limit(Limit::SQLITE_LIMIT_TRIGGER_DEPTH, 32);
|
||||
assert_eq!(32, db.limit(Limit::SQLITE_LIMIT_TRIGGER_DEPTH));
|
||||
|
||||
let version = unsafe { ffi::sqlite3_libversion_number() };
|
||||
if version >= 3008007 {
|
||||
db.set_limit(Limit::SQLITE_LIMIT_WORKER_THREADS, 2);
|
||||
assert_eq!(2, db.limit(Limit::SQLITE_LIMIT_WORKER_THREADS));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user