From a45f46f3eb27438fe31a591bcb0ce6d81e6d2690 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sun, 22 Nov 2009 12:17:28 +0100 Subject: [PATCH] Introduce db_pl_add_item_byid() --- src/db.c | 35 +++++++++++++++++++++++++++++++++++ src/db.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/db.c b/src/db.c index 00c848ea..1f5f5526 100644 --- a/src/db.c +++ b/src/db.c @@ -1789,6 +1789,41 @@ db_pl_add_item(int plid, char *path) #undef Q_TMPL } +int +db_pl_add_item_byid(int plid, int fileid) +{ +#define Q_TMPL "INSERT INTO playlistitems (playlistid, filepath) VALUES (%d, (SELECT path FROM files WHERE id = %d));" + char *query; + char *errmsg; + int ret; + + query = sqlite3_mprintf(Q_TMPL, plid, fileid); + if (!query) + { + DPRINTF(E_LOG, L_DB, "Out of memory for query string\n"); + return -1; + } + + DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query); + + errmsg = NULL; + ret = sqlite3_exec(hdl, query, NULL, NULL, &errmsg); + if (ret != SQLITE_OK) + { + DPRINTF(E_LOG, L_DB, "Query error: %s\n", errmsg); + + sqlite3_free(errmsg); + sqlite3_free(query); + return -1; + } + + sqlite3_free(query); + + return 0; + +#undef Q_TMPL +} + void db_pl_clear_items(int id) { diff --git a/src/db.h b/src/db.h index 1187304a..5581492e 100644 --- a/src/db.h +++ b/src/db.h @@ -281,6 +281,9 @@ db_pl_add(char *title, char *path, int *id); int db_pl_add_item(int plid, char *path); +int +db_pl_add_item_byid(int plid, int fileid); + void db_pl_clear_items(int id);