Set sort headers from sort fields in db

This commit is contained in:
ejurgensen 2013-12-05 21:56:02 +01:00
parent 34a5fdb2ab
commit a102d3f138

View File

@ -1233,7 +1233,7 @@ 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 **q) db_build_query_browse(struct query_params *qp, char *field, char *sort_field, char **q)
{ {
char *query; char *query;
char *count; char *count;
@ -1281,16 +1281,16 @@ db_build_query_browse(struct query_params *qp, char *field, char **q)
if (idx && qp->filter) if (idx && qp->filter)
query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != ''"
" AND %s %s %s;", field, field, field, qp->filter, sort, idx); " AND %s %s %s;", field, sort_field, field, qp->filter, sort, idx);
else if (idx) else if (idx)
query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != ''"
" %s %s;", field, field, field, sort, idx); " %s %s;", field, sort_field, field, sort, idx);
else if (qp->filter) else if (qp->filter)
query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != ''" query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != ''"
" AND %s %s;", field, field, field, qp->filter, sort); " AND %s %s;", field, sort_field, field, qp->filter, sort);
else else
query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != '' %s", query = sqlite3_mprintf("SELECT DISTINCT f.%s, f.%s FROM files f WHERE f.data_kind = 0 AND f.disabled = 0 AND f.%s != '' %s",
field, field, field, sort); field, sort_field, field, sort);
free(sort); free(sort);
@ -1344,19 +1344,19 @@ db_query_start(struct query_params *qp)
break; break;
case Q_BROWSE_ALBUMS: case Q_BROWSE_ALBUMS:
ret = db_build_query_browse(qp, "album", &query); ret = db_build_query_browse(qp, "album", "album_sort", &query);
break; break;
case Q_BROWSE_ARTISTS: case Q_BROWSE_ARTISTS:
ret = db_build_query_browse(qp, "album_artist", &query); ret = db_build_query_browse(qp, "album_artist", "album_artist_sort", &query);
break; break;
case Q_BROWSE_GENRES: case Q_BROWSE_GENRES:
ret = db_build_query_browse(qp, "genre", &query); ret = db_build_query_browse(qp, "genre", "genre", &query);
break; break;
case Q_BROWSE_COMPOSERS: case Q_BROWSE_COMPOSERS:
ret = db_build_query_browse(qp, "composer", &query); ret = db_build_query_browse(qp, "composer", "composer", &query);
break; break;
default: default: