Expose sqlite3_changes (or sqlite3_changes64 if available)

This commit is contained in:
Thom Chiovoloni 2022-04-03 08:13:27 -07:00
parent f8b9ad8907
commit 899784379b
No known key found for this signature in database
GPG Key ID: E2EFD4309E11C8A8
3 changed files with 13 additions and 7 deletions

View File

@ -277,14 +277,14 @@ impl InnerConnection {
} }
#[inline] #[inline]
pub fn changes(&self) -> usize { pub fn changes(&self) -> u64 {
#[cfg(not(feature = "modern_sqlite"))] #[cfg(not(feature = "modern_sqlite"))]
unsafe { unsafe {
ffi::sqlite3_changes(self.db()) as usize ffi::sqlite3_changes(self.db()) as u64
} }
#[cfg(feature = "modern_sqlite")] // 3.37.0 #[cfg(feature = "modern_sqlite")] // 3.37.0
unsafe { unsafe {
ffi::sqlite3_changes64(self.db()) as usize ffi::sqlite3_changes64(self.db()) as u64
} }
} }

View File

@ -1,5 +1,9 @@
//! Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to //! Rusqlite is an ergonomic wrapper for using SQLite from Rust.
//! expose an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres). //!
//! Historically, the API was based on the one from
//! [`rust-postgres`](https://github.com/sfackler/rust-postgres). However, the
//! two have diverged in many ways, and no compatibility between the two is
//! intended.
//! //!
//! ```rust //! ```rust
//! use rusqlite::{params, Connection, Result}; //! use rusqlite::{params, Connection, Result};
@ -901,8 +905,10 @@ impl Connection {
/// Return the number of rows modified, inserted or deleted by the most /// Return the number of rows modified, inserted or deleted by the most
/// recently completed INSERT, UPDATE or DELETE statement on the database /// recently completed INSERT, UPDATE or DELETE statement on the database
/// connection. /// connection.
///
/// See <https://www.sqlite.org/c3ref/changes.html>
#[inline] #[inline]
fn changes(&self) -> usize { pub fn changes(&self) -> u64 {
self.db.borrow().changes() self.db.borrow().changes()
} }

View File

@ -778,7 +778,7 @@ impl Statement<'_> {
let r = self.stmt.step(); let r = self.stmt.step();
self.stmt.reset(); self.stmt.reset();
match r { match r {
ffi::SQLITE_DONE => Ok(self.conn.changes()), ffi::SQLITE_DONE => Ok(self.conn.changes() as usize),
ffi::SQLITE_ROW => Err(Error::ExecuteReturnedResults), ffi::SQLITE_ROW => Err(Error::ExecuteReturnedResults),
_ => Err(self.conn.decode_result(r).unwrap_err()), _ => Err(self.conn.decode_result(r).unwrap_err()),
} }