Some cleaning up in group handling in db.c in prep for artist groups

This commit is contained in:
ejurgensen 2013-12-15 21:47:49 +01:00
parent d1a51ef45d
commit b3ea04a047
2 changed files with 12 additions and 11 deletions

View File

@ -237,12 +237,12 @@ static const ssize_t dbpli_cols_map[] =
*/ */
static const ssize_t dbgri_cols_map[] = static const ssize_t dbgri_cols_map[] =
{ {
dbgri_offsetof(itemcount),
dbgri_offsetof(groupalbumcount),
dbgri_offsetof(id), dbgri_offsetof(id),
dbgri_offsetof(persistentid), dbgri_offsetof(persistentid),
dbgri_offsetof(songalbumartist),
dbgri_offsetof(itemname), dbgri_offsetof(itemname),
dbgri_offsetof(itemcount),
dbgri_offsetof(groupalbumcount),
dbgri_offsetof(songalbumartist),
}; };
/* This list must be kept in sync with /* This list must be kept in sync with
@ -1066,13 +1066,13 @@ db_build_query_group_albums(struct query_params *qp, char **q)
sort = sort_clause[qp->sort]; sort = sort_clause[qp->sort];
if (idx && qp->filter) if (idx && qp->filter)
query = sqlite3_mprintf("SELECT COUNT(*), 1, g.id, g.persistentid, f.album_artist, g.name FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 AND %s GROUP BY f.album, g.name %s %s;", G_ALBUMS, qp->filter, sort, idx); query = sqlite3_mprintf("SELECT g.id, g.persistentid, g.name, COUNT(*), 1, f.album_artist FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 AND %s GROUP BY f.album, g.name %s %s;", G_ALBUMS, qp->filter, sort, idx);
else if (idx) else if (idx)
query = sqlite3_mprintf("SELECT COUNT(*), 1, g.id, g.persistentid, f.album_artist, g.name FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 GROUP BY f.album, g.name %s %s;", G_ALBUMS, sort, idx); query = sqlite3_mprintf("SELECT g.id, g.persistentid, g.name, COUNT(*), 1, f.album_artist FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 GROUP BY f.album, g.name %s %s;", G_ALBUMS, sort, idx);
else if (qp->filter) else if (qp->filter)
query = sqlite3_mprintf("SELECT COUNT(*), 1, g.id, g.persistentid, f.album_artist, g.name FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 AND %s GROUP BY f.album, g.name %s;", G_ALBUMS, qp->filter, sort); query = sqlite3_mprintf("SELECT g.id, g.persistentid, g.name, COUNT(*), 1, f.album_artist FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 AND %s GROUP BY f.album, g.name %s;", G_ALBUMS, qp->filter, sort);
else else
query = sqlite3_mprintf("SELECT COUNT(*), 1, g.id, g.persistentid, f.album_artist, g.name FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 GROUP BY f.album, g.name %s;", G_ALBUMS, sort); query = sqlite3_mprintf("SELECT g.id, g.persistentid, g.name, COUNT(*), 1, f.album_artist FROM files f, groups g WHERE f.songalbumid = g.persistentid AND g.type = %d AND f.disabled = 0 GROUP BY f.album, g.name %s;", G_ALBUMS, sort);
if (!query) if (!query)
{ {
@ -1105,13 +1105,13 @@ db_build_query_group_artists(struct query_params *qp, char **q)
sort = sort_clause[qp->sort]; sort = sort_clause[qp->sort];
if (idx && qp->filter) if (idx && qp->filter)
query = sqlite3_mprintf("SELECT COUNT(*), COUNT(DISTINCT f.album), 1, 1, f.album_artist, f.album_artist FROM files f WHERE f.disabled = 0 AND %s GROUP BY f.album_artist %s %s;", qp->filter, sort, idx); query = sqlite3_mprintf("SELECT 1, 1, f.album_artist, COUNT(*), COUNT(DISTINCT f.album), f.album_artist FROM files f WHERE f.disabled = 0 AND %s GROUP BY f.album_artist %s %s;", qp->filter, sort, idx);
else if (idx) else if (idx)
query = sqlite3_mprintf("SELECT COUNT(*), COUNT(DISTINCT f.album), 1, 1, f.album_artist, f.album_artist FROM files f WHERE f.disabled = 0 GROUP BY f.album_artist %s %s;", sort, idx); query = sqlite3_mprintf("SELECT 1, 1, f.album_artist, COUNT(*), COUNT(DISTINCT f.album), f.album_artist FROM files f WHERE f.disabled = 0 GROUP BY f.album_artist %s %s;", sort, idx);
else if (qp->filter) else if (qp->filter)
query = sqlite3_mprintf("SELECT COUNT(*), COUNT(DISTINCT f.album), 1, 1, f.album_artist, f.album_artist FROM files f WHERE f.disabled = 0 AND %s GROUP BY f.album_artist %s;", qp->filter, sort); query = sqlite3_mprintf("SELECT 1, 1, f.album_artist, COUNT(*), COUNT(DISTINCT f.album), f.album_artist FROM files f WHERE f.disabled = 0 AND %s GROUP BY f.album_artist %s;", qp->filter, sort);
else else
query = sqlite3_mprintf("SELECT COUNT(*), COUNT(DISTINCT f.album), 1, 1, f.album_artist, f.album_artist FROM files f WHERE f.disabled = 0 GROUP BY f.album_artist %s;", sort); query = sqlite3_mprintf("SELECT 1, 1, f.album_artist, COUNT(*), COUNT(DISTINCT f.album), f.album_artist FROM files f WHERE f.disabled = 0 GROUP BY f.album_artist %s;", sort);
if (!query) if (!query)
{ {

View File

@ -181,6 +181,7 @@ struct group_info {
uint64_t persistentid; /* ulonglong id (mper) */ uint64_t persistentid; /* ulonglong id (mper) */
char *itemname; /* playlist name as displayed in iTunes (minm) */ char *itemname; /* playlist name as displayed in iTunes (minm) */
uint32_t itemcount; /* number of items (mimc) */ uint32_t itemcount; /* number of items (mimc) */
uint32_t groupalbumcount; /* number of albums (agac) */
char *songalbumartist; /* song album artist (asaa) */ char *songalbumartist; /* song album artist (asaa) */
}; };