lib/sqlite/Util: add ExecuteModified()

This commit is contained in:
Max Kellermann 2014-12-12 21:21:56 +01:00
parent cfdbaf331e
commit 12b4a666bc
2 changed files with 23 additions and 14 deletions

View File

@ -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)

View File

@ -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)
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)
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