Fix problem introduced with commit 475d5db where genres and composers don't get sorted

This commit is contained in:
ejurgensen 2015-05-26 21:10:28 +02:00
parent 79cdfebf34
commit 8dd1e0fde2
4 changed files with 20 additions and 28 deletions

View File

@ -283,6 +283,10 @@ static const char *sort_clause[] =
"ORDER BY f.album_artist_sort ASC", "ORDER BY f.album_artist_sort ASC",
"ORDER BY f.type ASC, f.parent_id ASC, f.special_id ASC, f.title ASC", "ORDER BY f.type ASC, f.parent_id ASC, f.special_id ASC, f.title ASC",
"ORDER BY f.year ASC", "ORDER BY f.year ASC",
"ORDER BY f.genre ASC",
"ORDER BY f.composer_sort ASC",
"ORDER BY f.disc ASC",
"ORDER BY f.track ASC",
}; };
static char *db_path; static char *db_path;
@ -1377,13 +1381,12 @@ db_build_query_group_dirs(struct query_params *qp, char **q)
} }
static int static int
db_build_query_browse(struct query_params *qp, char *field, char *sort_field, char **q) db_build_query_browse(struct query_params *qp, const char *field, const char *group_field, char **q)
{ {
char *query; char *query;
char *count; char *count;
char *idx; char *idx;
char *sort; const char *sort;
int size;
int ret; int ret;
if (qp->filter) if (qp->filter)
@ -1411,37 +1414,20 @@ db_build_query_browse(struct query_params *qp, char *field, char *sort_field, ch
if (ret < 0) if (ret < 0)
return -1; return -1;
/* qp->sort does not have an option for sorting genre/composer, so it will then be set to S_NONE */ sort = sort_clause[qp->sort];
if (qp->sort != S_NONE)
{
sort = strdup(sort_clause[qp->sort]);
}
else
{
size = strlen("ORDER BY f.") + strlen(sort_field) + 1;
sort = malloc(size);
if (!sort)
{
DPRINTF(E_LOG, L_DB, "Out of memory for sort string\n");
return -1;
}
snprintf(sort, size, "ORDER BY f.%s", sort_field);
}
if (idx && qp->filter) if (idx && qp->filter)
query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''"
" AND %s GROUP BY f.%s %s %s;", field, sort_field, field, qp->filter, sort_field, sort, idx); " AND %s GROUP BY f.%s %s %s;", field, group_field, field, qp->filter, group_field, sort, idx);
else if (idx) else if (idx)
query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''"
" GROUP BY f.%s %s %s;", field, sort_field, field, sort_field, sort, idx); " GROUP BY f.%s %s %s;", field, group_field, field, group_field, sort, idx);
else if (qp->filter) else if (qp->filter)
query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''"
" AND %s GROUP BY f.%s %s;", field, sort_field, field, qp->filter, sort_field, sort); " AND %s GROUP BY f.%s %s;", field, group_field, field, qp->filter, group_field, sort);
else else
query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT f.%s, f.%s FROM files f WHERE f.disabled = 0 AND f.%s != ''"
" GROUP BY f.%s %s", field, sort_field, field, sort_field, sort); " GROUP BY f.%s %s", field, group_field, field, group_field, sort);
free(sort);
if (!query) if (!query)
{ {

View File

@ -23,6 +23,10 @@ enum sort_type {
S_ARTIST, S_ARTIST,
S_PLAYLIST, S_PLAYLIST,
S_YEAR, S_YEAR,
S_GENRE,
S_COMPOSER,
S_DISC,
S_TRACK,
}; };
#define Q_F_BROWSE (1 << 15) #define Q_F_BROWSE (1 << 15)

View File

@ -2169,11 +2169,13 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
{ {
tag = "abgn"; tag = "abgn";
qp.type = Q_BROWSE_GENRES; qp.type = Q_BROWSE_GENRES;
qp.sort = S_GENRE;
} }
else if (strcmp(uri[3], "composers") == 0) else if (strcmp(uri[3], "composers") == 0)
{ {
tag = "abcp"; tag = "abcp";
qp.type = Q_BROWSE_COMPOSERS; qp.type = Q_BROWSE_COMPOSERS;
qp.sort = S_COMPOSER;
} }
else else
{ {

View File

@ -2377,19 +2377,19 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
else if (0 == strcasecmp(argv[1], "genre")) else if (0 == strcasecmp(argv[1], "genre"))
{ {
qp.type = Q_BROWSE_GENRES; qp.type = Q_BROWSE_GENRES;
qp.sort = S_NONE; qp.sort = S_GENRE;
type = "Genre: "; type = "Genre: ";
} }
else if (0 == strcasecmp(argv[1], "disc")) else if (0 == strcasecmp(argv[1], "disc"))
{ {
qp.type = Q_BROWSE_DISCS; qp.type = Q_BROWSE_DISCS;
qp.sort = S_NONE; qp.sort = S_DISC;
type = "Disc: "; type = "Disc: ";
} }
else if (0 == strcasecmp(argv[1], "track")) else if (0 == strcasecmp(argv[1], "track"))
{ {
qp.type = Q_BROWSE_TRACKS; qp.type = Q_BROWSE_TRACKS;
qp.sort = S_NONE; qp.sort = S_TRACK;
type = "Track: "; type = "Track: ";
} }
else else