mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
[db] Add cleanup to db_pl_delete(), remove db_pl_purge()
This commit is contained in:
parent
2ee5f6d747
commit
b19314e814
57
src/db.c
57
src/db.c
@ -3632,19 +3632,41 @@ void
|
||||
db_pl_delete(int id)
|
||||
{
|
||||
#define Q_TMPL "DELETE FROM playlists WHERE id = %d;"
|
||||
#define Q_FILES "DELETE FROM files WHERE data_kind = %d AND path in (SELECT filepath FROM playlistitems WHERE playlistid = %d)"
|
||||
char *query;
|
||||
int ret;
|
||||
|
||||
if (id == 1)
|
||||
return;
|
||||
|
||||
db_transaction_begin();
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, id);
|
||||
|
||||
ret = db_query_run(query, 1, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
db_transaction_rollback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
// http items in files must have been added by the playlist
|
||||
// TODO find a cleaner way of identifying tracks added by a playlist
|
||||
query = sqlite3_mprintf(Q_FILES, DATA_KIND_HTTP, id);
|
||||
|
||||
ret = db_query_run(query, 1, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
db_transaction_rollback();
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear playlistitems
|
||||
db_pl_clear_items(id);
|
||||
|
||||
db_transaction_end();
|
||||
#undef Q_TMPL
|
||||
#undef Q_FILES
|
||||
}
|
||||
|
||||
void
|
||||
@ -3680,39 +3702,6 @@ db_pl_delete_bypath(const char *path)
|
||||
free(qp.filter);
|
||||
}
|
||||
|
||||
int
|
||||
db_pl_purge_byid(int id)
|
||||
{
|
||||
#define Q_TMPL "DELETE FROM files WHERE path in (SELECT filepath FROM playlistitems WHERE playlistid = %d)"
|
||||
|
||||
char *query;
|
||||
int ret;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, id);
|
||||
if (!query)
|
||||
{
|
||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
db_transaction_begin();
|
||||
ret = db_query_run(query, 1, LISTENER_DATABASE);
|
||||
if (ret < 0)
|
||||
{
|
||||
db_transaction_rollback();
|
||||
return -1;
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG, L_DB, "Deleted %d pl rows\n", sqlite3_changes(hdl));
|
||||
|
||||
db_pl_delete(id);
|
||||
db_transaction_end();
|
||||
|
||||
return 0;
|
||||
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
void
|
||||
db_pl_disable_bypath(const char *path, enum strip_type strip, uint32_t cookie)
|
||||
{
|
||||
|
7
src/db.h
7
src/db.h
@ -256,8 +256,8 @@ struct playlist_info {
|
||||
char *virtual_path; /* virtual path of underlying playlist */
|
||||
uint32_t parent_id; /* Id of parent playlist if the playlist is nested */
|
||||
uint32_t directory_id; /* Id of directory */
|
||||
char *query_order; /* order by clause if it is a smart playlist */
|
||||
int32_t query_limit; /* limit if it is a smart playlist */
|
||||
char *query_order; /* order by clause, used by e.g. a smart playlists */
|
||||
int32_t query_limit; /* limit, used by e.g. smart playlists */
|
||||
uint32_t media_kind;
|
||||
uint32_t items; /* number of items (mimc) */
|
||||
uint32_t streams; /* number of internet streams */
|
||||
@ -707,9 +707,6 @@ db_pl_delete(int id);
|
||||
void
|
||||
db_pl_delete_bypath(const char *path);
|
||||
|
||||
int
|
||||
db_pl_purge_byid(int id);
|
||||
|
||||
void
|
||||
db_pl_disable_bypath(const char *path, enum strip_type strip, uint32_t cookie);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user