mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 23:55:57 -05:00
Fix problem introduced with commit 475d5db
where genres and composers don't get sorted
This commit is contained in:
parent
79cdfebf34
commit
8dd1e0fde2
36
src/db.c
36
src/db.c
@ -283,6 +283,10 @@ static const char *sort_clause[] =
|
||||
"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.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;
|
||||
@ -1377,13 +1381,12 @@ db_build_query_group_dirs(struct query_params *qp, char **q)
|
||||
}
|
||||
|
||||
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 *count;
|
||||
char *idx;
|
||||
char *sort;
|
||||
int size;
|
||||
const char *sort;
|
||||
int ret;
|
||||
|
||||
if (qp->filter)
|
||||
@ -1411,37 +1414,20 @@ db_build_query_browse(struct query_params *qp, char *field, char *sort_field, ch
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
/* qp->sort does not have an option for sorting genre/composer, so it will then be set to S_NONE */
|
||||
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);
|
||||
}
|
||||
sort = sort_clause[qp->sort];
|
||||
|
||||
if (idx && qp->filter)
|
||||
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)
|
||||
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)
|
||||
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
|
||||
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);
|
||||
|
||||
free(sort);
|
||||
" GROUP BY f.%s %s", field, group_field, field, group_field, sort);
|
||||
|
||||
if (!query)
|
||||
{
|
||||
|
4
src/db.h
4
src/db.h
@ -23,6 +23,10 @@ enum sort_type {
|
||||
S_ARTIST,
|
||||
S_PLAYLIST,
|
||||
S_YEAR,
|
||||
S_GENRE,
|
||||
S_COMPOSER,
|
||||
S_DISC,
|
||||
S_TRACK,
|
||||
};
|
||||
|
||||
#define Q_F_BROWSE (1 << 15)
|
||||
|
@ -2169,11 +2169,13 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
||||
{
|
||||
tag = "abgn";
|
||||
qp.type = Q_BROWSE_GENRES;
|
||||
qp.sort = S_GENRE;
|
||||
}
|
||||
else if (strcmp(uri[3], "composers") == 0)
|
||||
{
|
||||
tag = "abcp";
|
||||
qp.type = Q_BROWSE_COMPOSERS;
|
||||
qp.sort = S_COMPOSER;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2377,19 +2377,19 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
else if (0 == strcasecmp(argv[1], "genre"))
|
||||
{
|
||||
qp.type = Q_BROWSE_GENRES;
|
||||
qp.sort = S_NONE;
|
||||
qp.sort = S_GENRE;
|
||||
type = "Genre: ";
|
||||
}
|
||||
else if (0 == strcasecmp(argv[1], "disc"))
|
||||
{
|
||||
qp.type = Q_BROWSE_DISCS;
|
||||
qp.sort = S_NONE;
|
||||
qp.sort = S_DISC;
|
||||
type = "Disc: ";
|
||||
}
|
||||
else if (0 == strcasecmp(argv[1], "track"))
|
||||
{
|
||||
qp.type = Q_BROWSE_TRACKS;
|
||||
qp.sort = S_NONE;
|
||||
qp.sort = S_TRACK;
|
||||
type = "Track: ";
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user