Skip to content

Commit 0ccf25c

Browse files
committed
expose sqlite_changes function
1 parent 533037e commit 0ccf25c

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub unsafe extern "C" fn sqlite3_open_v2(
8989
connection: connection.unwrap(),
9090
transaction_baton: Mutex::new(None),
9191
last_insert_rowid: Mutex::new(None),
92+
rows_written: Mutex::new(None),
9293
transaction_has_began: Mutex::new(false),
9394
delete_hook: Mutex::new(None),
9495
insert_hook: Mutex::new(None),
@@ -383,6 +384,22 @@ pub unsafe extern "C" fn sqlite3_extended_errcode(_: *mut SQLite3) -> c_int {
383384
SQLITE_OK
384385
}
385386

387+
#[no_mangle]
388+
pub unsafe extern "C" fn sqlite3_changes(db: *mut SQLite3) -> c_int {
389+
if !is_aligned(db) {
390+
return SQLITE_OK;
391+
}
392+
let db = &mut *db;
393+
394+
if let Ok(rows_written) = db.rows_written.lock() {
395+
if rows_written.is_some() {
396+
return rows_written.unwrap() as c_int;
397+
}
398+
}
399+
400+
0
401+
}
402+
386403
#[no_mangle]
387404
pub unsafe extern "C" fn sqlite3_errmsg(_: *mut SQLite3) -> *const c_char {
388405
if let Some(error_entry) = sqlite::get_latest_error() {

src/sqlite.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ lazy_static! {
8686
pub struct SQLite3 {
8787
pub connection: transport::DatabaseConnection, // Connection to the database
8888
pub last_insert_rowid: Mutex<Option<i64>>, // Last inserted row ID
89+
pub rows_written: Mutex<Option<u64>>, // Number of rows written
8990
pub transaction_baton: Mutex<Option<String>>, // Baton for transaction management
9091
pub transaction_has_began: Mutex<bool>, // Flag to check if a transaction has started
9192
pub update_hook: Mutex<Option<(SqliteHook, *mut c_void)>>, // Update hook callback

src/transport/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub struct RemoteRow {
5151
pub struct QueryResult {
5252
pub cols: Vec<RemoteCol>,
5353
pub rows: Vec<Vec<RemoteRow>>,
54+
pub rows_read: Option<u64>,
55+
pub rows_written: Option<u64>,
5456
pub last_insert_rowid: Option<String>,
5557
}
5658

src/utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,10 @@ pub fn get_execution_result<'a>(
144144
*last_insert_rowid_lock = Some(last_insert_rowid.parse::<i64>().unwrap_or(0));
145145
}
146146

147+
if let Some(rows_written) = &first_execution_result.rows_written {
148+
let mut rows_written_lock = db.rows_written.lock().unwrap();
149+
*rows_written_lock = Some(*rows_written);
150+
}
151+
147152
Ok(first_execution_result)
148153
}

0 commit comments

Comments
 (0)