Merge pull request #1152 from thomcc/expose-changes

Expose `sqlite3_changes` (or `sqlite3_changes64` if available)
This commit is contained in:
gwenn 2022-04-04 06:36:10 +02:00 committed by GitHub
commit af8cd1caec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View File

@ -277,14 +277,14 @@ impl InnerConnection {
}
#[inline]
pub fn changes(&self) -> usize {
pub fn changes(&self) -> u64 {
#[cfg(not(feature = "modern_sqlite"))]
unsafe {
ffi::sqlite3_changes(self.db()) as usize
ffi::sqlite3_changes(self.db()) as u64
}
#[cfg(feature = "modern_sqlite")] // 3.37.0
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
//! expose an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres).
//! Rusqlite is an ergonomic wrapper for using SQLite from Rust.
//!
//! 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
//! use rusqlite::{params, Connection, Result};
@ -901,8 +905,10 @@ impl Connection {
/// Return the number of rows modified, inserted or deleted by the most
/// recently completed INSERT, UPDATE or DELETE statement on the database
/// connection.
///
/// See <https://www.sqlite.org/c3ref/changes.html>
#[inline]
fn changes(&self) -> usize {
pub fn changes(&self) -> u64 {
self.db.borrow().changes()
}

View File

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