Merge remote-tracking branch 'jgallagher/master' into vtab

This commit is contained in:
gwenn
2018-06-10 18:49:40 +02:00
2 changed files with 60 additions and 0 deletions

View File

@@ -577,6 +577,18 @@ impl Connection {
fn changes(&self) -> c_int {
self.db.borrow_mut().changes()
}
/// Test for auto-commit mode.
/// Autocommit mode is on by default.
pub fn is_autocommit(&self) -> bool {
self.db.borrow().is_autocommit()
}
/// Determine if all associated prepared statements have been reset.
#[cfg(feature = "bundled")]
pub fn is_busy(&self) -> bool {
self.db.borrow().is_busy()
}
}
impl fmt::Debug for Connection {
@@ -907,6 +919,25 @@ impl InnerConnection {
unsafe { ffi::sqlite3_changes(self.db()) }
}
fn is_autocommit(&self) -> bool {
unsafe { ffi::sqlite3_get_autocommit(self.db()) != 0 }
}
#[cfg(feature = "bundled")] // 3.8.6
fn is_busy(&self) -> bool {
let db = self.db();
unsafe {
let mut stmt = ffi::sqlite3_next_stmt(db, ptr::null_mut());
while !stmt.is_null() {
if ffi::sqlite3_stmt_busy(stmt) != 0 {
return true;
}
stmt = ffi::sqlite3_next_stmt(db, stmt);
}
}
return false;
}
#[cfg(not(feature = "hooks"))]
fn remove_hooks(&mut self) {
}
@@ -1227,6 +1258,30 @@ mod test {
assert_eq!(db.last_insert_rowid(), 10);
}
#[test]
fn test_is_autocommit() {
let db = checked_memory_handle();
assert!(db.is_autocommit(),
"autocommit expected to be active by default");
}
#[test]
#[cfg(feature = "bundled")]
fn test_is_busy() {
let db = checked_memory_handle();
assert!(!db.is_busy());
let mut stmt = db.prepare("PRAGMA schema_version").unwrap();
assert!(!db.is_busy());
{
let mut rows = stmt.query(&[]).unwrap();
assert!(!db.is_busy());
let row = rows.next();
assert!(db.is_busy());
assert!(row.is_some());
}
assert!(!db.is_busy());
}
#[test]
fn test_statement_debugging() {
let db = checked_memory_handle();