aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-12 21:21:56 +0100
committerMax Kellermann <max@duempel.org>2014-12-12 21:43:54 +0100
commit12b4a666bc730cb46ba5da6b576905166d249eff (patch)
tree1369bb5ea30f5ef84826bd1ed64d7a0519990242 /src
parentcfdbaf331e46f304fc705784967b5aadc4325103 (diff)
downloadmpd-12b4a666bc730cb46ba5da6b576905166d249eff.tar.gz
mpd-12b4a666bc730cb46ba5da6b576905166d249eff.tar.xz
mpd-12b4a666bc730cb46ba5da6b576905166d249eff.zip
lib/sqlite/Util: add ExecuteModified()
Diffstat (limited to 'src')
-rw-r--r--src/lib/sqlite/Util.hxx11
-rw-r--r--src/sticker/StickerDatabase.cxx26
2 files changed, 23 insertions, 14 deletions
diff --git a/src/lib/sqlite/Util.hxx b/src/lib/sqlite/Util.hxx
index 3a7d34a13..fbc773ed4 100644
--- a/src/lib/sqlite/Util.hxx
+++ b/src/lib/sqlite/Util.hxx
@@ -137,6 +137,17 @@ ExecuteChanges(sqlite3_stmt *stmt)
return sqlite3_changes(sqlite3_db_handle(stmt));
}
+/**
+ * Wrapper for ExecuteChanges() that returns true if at least one row
+ * was modified. Returns false if nothing was modified or if an error
+ * occurred.
+ */
+static inline bool
+ExecuteModified(sqlite3_stmt *stmt)
+{
+ return ExecuteChanges(stmt) > 0;
+}
+
template<typename F>
static inline bool
ExecuteForEach(sqlite3_stmt *stmt, F &&f)
diff --git a/src/sticker/StickerDatabase.cxx b/src/sticker/StickerDatabase.cxx
index 049750608..fd5cbd3ae 100644
--- a/src/sticker/StickerDatabase.cxx
+++ b/src/sticker/StickerDatabase.cxx
@@ -224,15 +224,14 @@ sticker_update_value(const char *type, const char *uri,
if (!BindAll(stmt, value, type, uri, name))
return false;
- int ret = ExecuteChanges(stmt);
- if (ret < 0)
- return false;
+ bool modified = ExecuteModified(stmt);
sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt);
- idle_add(IDLE_STICKER);
- return ret > 0;
+ if (modified)
+ idle_add(IDLE_STICKER);
+ return modified;
}
static bool
@@ -291,14 +290,14 @@ sticker_delete(const char *type, const char *uri)
if (!BindAll(stmt, type, uri))
return false;
- if (!ExecuteCommand(stmt))
- return false;
+ bool modified = ExecuteModified(stmt);
sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt);
- idle_add(IDLE_STICKER);
- return true;
+ if (modified)
+ idle_add(IDLE_STICKER);
+ return modified;
}
bool
@@ -313,15 +312,14 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
if (!BindAll(stmt, type, uri, name))
return false;
- int ret = ExecuteChanges(stmt);
- if (ret < 0)
- return false;
+ bool modified = ExecuteModified(stmt);
sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt);
- idle_add(IDLE_STICKER);
- return ret > 0;
+ if (modified)
+ idle_add(IDLE_STICKER);
+ return modified;
}
void