Introduce db_pl_add_item_byid()

This commit is contained in:
Julien BLACHE 2009-11-22 12:17:28 +01:00
parent 1a397ca79b
commit a45f46f3eb
2 changed files with 38 additions and 0 deletions

View File

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

View File

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