Commit 12b4a666 authored by Max Kellermann's avatar Max Kellermann

lib/sqlite/Util: add ExecuteModified()

parent cfdbaf33
...@@ -137,6 +137,17 @@ ExecuteChanges(sqlite3_stmt *stmt) ...@@ -137,6 +137,17 @@ ExecuteChanges(sqlite3_stmt *stmt)
return sqlite3_changes(sqlite3_db_handle(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> template<typename F>
static inline bool static inline bool
ExecuteForEach(sqlite3_stmt *stmt, F &&f) ExecuteForEach(sqlite3_stmt *stmt, F &&f)
......
...@@ -224,15 +224,14 @@ sticker_update_value(const char *type, const char *uri, ...@@ -224,15 +224,14 @@ sticker_update_value(const char *type, const char *uri,
if (!BindAll(stmt, value, type, uri, name)) if (!BindAll(stmt, value, type, uri, name))
return false; return false;
int ret = ExecuteChanges(stmt); bool modified = ExecuteModified(stmt);
if (ret < 0)
return false;
sqlite3_reset(stmt); sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt); sqlite3_clear_bindings(stmt);
idle_add(IDLE_STICKER); if (modified)
return ret > 0; idle_add(IDLE_STICKER);
return modified;
} }
static bool static bool
...@@ -291,14 +290,14 @@ sticker_delete(const char *type, const char *uri) ...@@ -291,14 +290,14 @@ sticker_delete(const char *type, const char *uri)
if (!BindAll(stmt, type, uri)) if (!BindAll(stmt, type, uri))
return false; return false;
if (!ExecuteCommand(stmt)) bool modified = ExecuteModified(stmt);
return false;
sqlite3_reset(stmt); sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt); sqlite3_clear_bindings(stmt);
idle_add(IDLE_STICKER); if (modified)
return true; idle_add(IDLE_STICKER);
return modified;
} }
bool bool
...@@ -313,15 +312,14 @@ sticker_delete_value(const char *type, const char *uri, const char *name) ...@@ -313,15 +312,14 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
if (!BindAll(stmt, type, uri, name)) if (!BindAll(stmt, type, uri, name))
return false; return false;
int ret = ExecuteChanges(stmt); bool modified = ExecuteModified(stmt);
if (ret < 0)
return false;
sqlite3_reset(stmt); sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt); sqlite3_clear_bindings(stmt);
idle_add(IDLE_STICKER); if (modified)
return ret > 0; idle_add(IDLE_STICKER);
return modified;
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment