From 2dea70304d224c666449b8a047b12718359c91cd Mon Sep 17 00:00:00 2001 From: gwenn Date: Sun, 4 Jul 2021 16:53:40 +0200 Subject: [PATCH] Retrieve error message from database connection handle --- src/backup.rs | 8 ++++---- src/blob/pos_io.rs | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/backup.rs b/src/backup.rs index 88677fe..5104f73 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -40,7 +40,7 @@ use std::time::Duration; use crate::ffi; -use crate::error::{error_from_handle, error_from_sqlite_code}; +use crate::error::error_from_handle; use crate::{Connection, DatabaseName, Result}; impl Connection { @@ -169,7 +169,7 @@ pub struct Progress { /// A handle to an online backup. pub struct Backup<'a, 'b> { phantom_from: PhantomData<&'a Connection>, - phantom_to: PhantomData<&'b Connection>, + to: &'b Connection, b: *mut ffi::sqlite3_backup, } @@ -223,7 +223,7 @@ impl Backup<'_, '_> { Ok(Backup { phantom_from: PhantomData, - phantom_to: PhantomData, + to, b, }) } @@ -263,7 +263,7 @@ impl Backup<'_, '_> { ffi::SQLITE_OK => Ok(More), ffi::SQLITE_BUSY => Ok(Busy), ffi::SQLITE_LOCKED => Ok(Locked), - _ => Err(error_from_sqlite_code(rc, None)), + _ => self.to.decode_result(rc).map(|_| More), } } diff --git a/src/blob/pos_io.rs b/src/blob/pos_io.rs index dd6167d..01f9c34 100644 --- a/src/blob/pos_io.rs +++ b/src/blob/pos_io.rs @@ -44,15 +44,14 @@ impl<'conn> Blob<'conn> { // losslessly converted to i32, since `len` came from an i32. // Sanity check the above. debug_assert!(i32::try_from(write_start).is_ok() && i32::try_from(buf.len()).is_ok()); - unsafe { - check!(ffi::sqlite3_blob_write( + self.conn.decode_result(unsafe { + ffi::sqlite3_blob_write( self.blob, buf.as_ptr() as *const _, buf.len() as i32, write_start as i32, - )); - } - Ok(()) + ) + }) } /// An alias for `write_at` provided for compatibility with the conceptually @@ -151,12 +150,12 @@ impl<'conn> Blob<'conn> { debug_assert!(i32::try_from(read_len).is_ok()); unsafe { - check!(ffi::sqlite3_blob_read( + self.conn.decode_result(ffi::sqlite3_blob_read( self.blob, buf.as_mut_ptr() as *mut _, read_len as i32, read_start as i32, - )); + ))?; Ok(from_raw_parts_mut(buf.as_mut_ptr() as *mut u8, read_len)) }