aboutsummaryrefslogtreecommitdiffstats
path: root/src/sticker.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-04-28 20:23:27 +0200
committerMax Kellermann <max@duempel.org>2009-04-28 20:23:27 +0200
commit610940a06dc09fc14581cffc2829358e926ec9c3 (patch)
treed625b3f12f3cdc7221dd63876a783cbae20ecae2 /src/sticker.c
parent7d9316a52d935ce6c9f4ae3030c975d660a02db6 (diff)
downloadmpd-610940a06dc09fc14581cffc2829358e926ec9c3.tar.gz
mpd-610940a06dc09fc14581cffc2829358e926ec9c3.tar.xz
mpd-610940a06dc09fc14581cffc2829358e926ec9c3.zip
sticker: added sticker_delete_value()
sticker_delete_value() deletes only one value in a sticker, while the old function sticker_delete() deletes all values.
Diffstat (limited to '')
-rw-r--r--src/sticker.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/sticker.c b/src/sticker.c
index e2d774f3d..0d30fbb70 100644
--- a/src/sticker.c
+++ b/src/sticker.c
@@ -37,6 +37,7 @@ enum sticker_sql {
STICKER_SQL_UPDATE,
STICKER_SQL_INSERT,
STICKER_SQL_DELETE,
+ STICKER_SQL_DELETE_VALUE,
STICKER_SQL_FIND,
};
@@ -51,6 +52,8 @@ static const char *const sticker_sql[] = {
"INSERT INTO sticker(type,uri,name,value) VALUES(?, ?, ?, ?)",
[STICKER_SQL_DELETE] =
"DELETE FROM sticker WHERE type=? AND uri=?",
+ [STICKER_SQL_DELETE_VALUE] =
+ "DELETE FROM sticker WHERE type=? AND uri=? AND name=?",
[STICKER_SQL_FIND] =
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=?",
};
@@ -439,6 +442,58 @@ sticker_delete(const char *type, const char *uri)
return true;
}
+bool
+sticker_delete_value(const char *type, const char *uri, const char *name)
+{
+ sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_DELETE_VALUE];
+ int ret;
+
+ assert(sticker_enabled());
+ assert(type != NULL);
+ assert(uri != NULL);
+
+ sqlite3_reset(stmt);
+
+ ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
+ if (ret != SQLITE_OK) {
+ g_warning("sqlite3_bind_text() failed: %s",
+ sqlite3_errmsg(sticker_db));
+ return false;
+ }
+
+ ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
+ if (ret != SQLITE_OK) {
+ g_warning("sqlite3_bind_text() failed: %s",
+ sqlite3_errmsg(sticker_db));
+ return false;
+ }
+
+ ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
+ if (ret != SQLITE_OK) {
+ g_warning("sqlite3_bind_text() failed: %s",
+ sqlite3_errmsg(sticker_db));
+ return false;
+ }
+
+ do {
+ ret = sqlite3_step(stmt);
+ } while (ret == SQLITE_BUSY);
+
+ if (ret != SQLITE_DONE) {
+ g_warning("sqlite3_step() failed: %s",
+ sqlite3_errmsg(sticker_db));
+ return false;
+ }
+
+ ret = sqlite3_changes(sticker_db);
+
+ sqlite3_reset(stmt);
+ sqlite3_clear_bindings(stmt);
+
+ idle_add(IDLE_STICKER);
+ return ret > 0;
+}
+
static struct sticker *
sticker_new(void)
{