mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 18:36:02 -05:00
Revert "Remove default playlist & special case"
This reverts commit af95cee79b09fce8f708e4128141aaea7a0ea2c4. The default playlist is actually used by iTunes, so revert its removal. I misremembered it being there for RSP.
This commit is contained in:
parent
af95cee79b
commit
bf2c2b68c0
49
src/db.c
49
src/db.c
@ -339,8 +339,8 @@ db_purge_cruft(time_t ref)
|
||||
char *queries[3] = { NULL, NULL, NULL };
|
||||
char *queries_tmpl[3] =
|
||||
{
|
||||
"DELETE FROM playlistitems WHERE playlistid IN (SELECT id FROM playlists WHERE db_timestamp < %" PRIi64 ");",
|
||||
"DELETE FROM playlists WHERE db_timestamp < %" PRIi64 ";",
|
||||
"DELETE FROM playlistitems WHERE playlistid IN (SELECT id FROM playlists WHERE id <> 1 AND db_timestamp < %" PRIi64 ");",
|
||||
"DELETE FROM playlists WHERE id <> 1 AND db_timestamp < %" PRIi64 ";",
|
||||
"DELETE FROM files WHERE db_timestamp < %" PRIi64 ";"
|
||||
};
|
||||
|
||||
@ -556,12 +556,22 @@ db_build_query_plitems(struct query_params *qp, char **q)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qp->filter)
|
||||
count = sqlite3_mprintf("SELECT COUNT(*) FROM files JOIN playlistitems ON files.path = playlistitems.filepath"
|
||||
" WHERE playlistitems.playlistid = %d AND files.disabled = 0 AND %s;", qp->pl_id, qp->filter);
|
||||
if (qp->pl_id == 1)
|
||||
{
|
||||
if (qp->filter)
|
||||
count = sqlite3_mprintf("SELECT COUNT(*) FROM files WHERE disabled = 0 AND %s;", qp->filter);
|
||||
else
|
||||
count = sqlite3_mprintf("SELECT COUNT(*) FROM files WHERE disabled = 0;");
|
||||
}
|
||||
else
|
||||
count = sqlite3_mprintf("SELECT COUNT(*) FROM files JOIN playlistitems ON files.path = playlistitems.filepath"
|
||||
" WHERE playlistitems.playlistid = %d AND files.disabled = 0;", qp->pl_id);
|
||||
{
|
||||
if (qp->filter)
|
||||
count = sqlite3_mprintf("SELECT COUNT(*) FROM files JOIN playlistitems ON files.path = playlistitems.filepath"
|
||||
" WHERE playlistitems.playlistid = %d AND files.disabled = 0 AND %s;", qp->pl_id, qp->filter);
|
||||
else
|
||||
count = sqlite3_mprintf("SELECT COUNT(*) FROM files JOIN playlistitems ON files.path = playlistitems.filepath"
|
||||
" WHERE playlistitems.playlistid = %d AND files.disabled = 0;", qp->pl_id);
|
||||
}
|
||||
|
||||
if (!count)
|
||||
{
|
||||
@ -1869,7 +1879,11 @@ db_pl_fetch_byquery(char *query)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pli->items = db_pl_count_items(pli->id);
|
||||
/* Playlist 1: all files */
|
||||
if (pli->id == 1)
|
||||
pli->items = db_files_get_count();
|
||||
else
|
||||
pli->items = db_pl_count_items(pli->id);
|
||||
|
||||
return pli;
|
||||
}
|
||||
@ -2876,6 +2890,10 @@ db_perthread_deinit(void)
|
||||
" libidx INTEGER NOT NULL" \
|
||||
");"
|
||||
|
||||
#define Q_PL1 \
|
||||
"INSERT INTO playlists (id, title, type, query, db_timestamp, path, idx)" \
|
||||
" VALUES(1, 'Library', 1, '1', 0, '', 0);"
|
||||
|
||||
#define I_PATH \
|
||||
"CREATE INDEX IF NOT EXISTS idx_path ON files(path, idx);"
|
||||
|
||||
@ -2929,6 +2947,21 @@ db_create_tables(void)
|
||||
}
|
||||
}
|
||||
|
||||
ret = db_get_count("SELECT COUNT(*) FROM playlists WHERE id = 1;");
|
||||
if (ret != 1)
|
||||
{
|
||||
DPRINTF(E_DBG, L_DB, "Creating default playlist\n");
|
||||
|
||||
ret = sqlite3_exec(hdl, Q_PL1, NULL, NULL, &errmsg);
|
||||
if (ret != SQLITE_OK)
|
||||
{
|
||||
DPRINTF(E_FATAL, L_DB, "Could not add default playlist: %s\n", errmsg);
|
||||
|
||||
sqlite3_free(errmsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = db_get_count("SELECT COUNT(*) FROM admin WHERE key = 'schema_version';");
|
||||
if (ret != 1)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user