From b3ea04a04713e40bb608160ad9a712deaed06c77 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sun, 15 Dec 2013 21:47:49 +0100 Subject: [PATCH] Some cleaning up in group handling in db.c in prep for artist groups --- src/db.c | 22 +++++++++++----------- src/db.h | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/db.c b/src/db.c index 7e17549a..bdb44cdf 100644 --- a/src/db.c +++ b/src/db.c @@ -237,12 +237,12 @@ static const ssize_t dbpli_cols_map[] = */ static const ssize_t dbgri_cols_map[] = { - dbgri_offsetof(itemcount), - dbgri_offsetof(groupalbumcount), dbgri_offsetof(id), dbgri_offsetof(persistentid), - dbgri_offsetof(songalbumartist), dbgri_offsetof(itemname), + dbgri_offsetof(itemcount), + dbgri_offsetof(groupalbumcount), + dbgri_offsetof(songalbumartist), }; /* 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]; 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) - 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) - 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 - 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) { @@ -1105,13 +1105,13 @@ db_build_query_group_artists(struct query_params *qp, char **q) sort = sort_clause[qp->sort]; 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) - 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) - 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 - 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) { diff --git a/src/db.h b/src/db.h index 67fc6214..3f557552 100644 --- a/src/db.h +++ b/src/db.h @@ -181,6 +181,7 @@ struct group_info { uint64_t persistentid; /* ulonglong id (mper) */ char *itemname; /* playlist name as displayed in iTunes (minm) */ uint32_t itemcount; /* number of items (mimc) */ + uint32_t groupalbumcount; /* number of albums (agac) */ char *songalbumartist; /* song album artist (asaa) */ };