[niepce] library: properly check for the update and delete count



commit 2c506b2cebcb42a8f445234c5e1af5c0836279ec
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Oct 20 00:09:04 2018 -0400

    library: properly check for the update and delete count

 src/engine/db/library.rs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/src/engine/db/library.rs b/src/engine/db/library.rs
index 254222d..d92f23e 100644
--- a/src/engine/db/library.rs
+++ b/src/engine/db/library.rs
@@ -745,7 +745,8 @@ impl Library {
                  WHERE file_id=?1;",
                 &[&file_id],
             )?;
-            // XXX check success.
+            // we don't really know how many rows are supposed to be impacted
+            // even 0 is valid.
             return Ok(());
         }
         Err(Error::NoSqlDb)
@@ -889,11 +890,13 @@ impl Library {
 
     pub fn update_label(&self, label_id: LibraryId, name: &str, colour: &str) -> Result<()> {
         if let Some(ref conn) = self.dbconn {
-            conn.execute(
+            let c = conn.execute(
                 "UPDATE labels SET name=?2, color=?3 FROM labels WHERE id=?1;",
                 &[&label_id, &name, &colour],
             )?;
-            // XXX check success.
+            if c != 1 {
+                return Err(Error::InvalidResult);
+            }
             return Ok(());
         }
         Err(Error::NoSqlDb)
@@ -901,8 +904,10 @@ impl Library {
 
     pub fn delete_label(&self, label_id: LibraryId) -> Result<()> {
         if let Some(ref conn) = self.dbconn {
-            conn.execute("DELETE FROM labels WHERE id=?1;", &[&label_id])?;
-            // XXX check success.
+            let c = conn.execute("DELETE FROM labels WHERE id=?1;", &[&label_id])?;
+            if c != 1 {
+                return Err(Error::InvalidResult);
+            }
             return Ok(());
         }
         Err(Error::NoSqlDb)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]