mirror of
https://github.com/isar/rusqlite.git
synced 2025-03-31 19:12:58 +08:00
Merge pull request #1461 from francois-random/expose-total-changes
expose total_changes()
This commit is contained in:
commit
def8e9460d
@ -288,6 +288,18 @@ impl InnerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn total_changes(&self) -> u64 {
|
||||||
|
#[cfg(not(feature = "modern_sqlite"))]
|
||||||
|
unsafe {
|
||||||
|
ffi::sqlite3_total_changes(self.db()) as u64
|
||||||
|
}
|
||||||
|
#[cfg(feature = "modern_sqlite")] // 3.37.0
|
||||||
|
unsafe {
|
||||||
|
ffi::sqlite3_total_changes64(self.db()) as u64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_autocommit(&self) -> bool {
|
pub fn is_autocommit(&self) -> bool {
|
||||||
unsafe { ffi::sqlite3_get_autocommit(self.db()) != 0 }
|
unsafe { ffi::sqlite3_get_autocommit(self.db()) != 0 }
|
||||||
|
33
src/lib.rs
33
src/lib.rs
@ -1005,6 +1005,16 @@ impl Connection {
|
|||||||
self.db.borrow().changes()
|
self.db.borrow().changes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the total number of rows modified, inserted or deleted by all
|
||||||
|
/// completed INSERT, UPDATE or DELETE statements since the database
|
||||||
|
/// connection was opened, including those executed as part of trigger programs.
|
||||||
|
///
|
||||||
|
/// See <https://www.sqlite.org/c3ref/total_changes.html>
|
||||||
|
#[inline]
|
||||||
|
pub fn total_changes(&self) -> u64 {
|
||||||
|
self.db.borrow().total_changes()
|
||||||
|
}
|
||||||
|
|
||||||
/// Test for auto-commit mode.
|
/// Test for auto-commit mode.
|
||||||
/// Autocommit mode is on by default.
|
/// Autocommit mode is on by default.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1693,6 +1703,29 @@ mod test {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_total_changes() -> Result<()> {
|
||||||
|
let db = Connection::open_in_memory()?;
|
||||||
|
let sql = "CREATE TABLE foo(x INTEGER PRIMARY KEY, value TEXT default '' NOT NULL,
|
||||||
|
desc TEXT default '');
|
||||||
|
CREATE VIEW foo_bar AS SELECT x, desc FROM foo WHERE value = 'bar';
|
||||||
|
CREATE TRIGGER INSERT_FOOBAR
|
||||||
|
INSTEAD OF INSERT
|
||||||
|
ON foo_bar
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO foo VALUES(new.x, 'bar', new.desc);
|
||||||
|
END;";
|
||||||
|
db.execute_batch(sql)?;
|
||||||
|
let total_changes_before = db.total_changes();
|
||||||
|
let changes = db
|
||||||
|
.prepare("INSERT INTO foo_bar VALUES(null, 'baz');")?
|
||||||
|
.execute([])?;
|
||||||
|
let total_changes_after = db.total_changes();
|
||||||
|
assert_eq!(changes, 0);
|
||||||
|
assert_eq!(total_changes_after - total_changes_before, 1);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_autocommit() -> Result<()> {
|
fn test_is_autocommit() -> Result<()> {
|
||||||
let db = Connection::open_in_memory()?;
|
let db = Connection::open_in_memory()?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user