mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-14 08:16:17 -04:00
Consolidate sort clauses
This commit is contained in:
parent
20486ee0dd
commit
5d69a8e34c
43
src/db.c
43
src/db.c
@ -238,6 +238,15 @@ static const struct col_type_map wi_cols_map[] =
|
|||||||
{ wi_offsetof(path), DB_TYPE_STRING },
|
{ wi_offsetof(path), DB_TYPE_STRING },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Sort clauses */
|
||||||
|
/* Keep in sync with enum sort_type */
|
||||||
|
static const char *sort_clause[] =
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"ORDER BY title ASC",
|
||||||
|
"ORDER BY track ASC, album ASC",
|
||||||
|
};
|
||||||
|
|
||||||
static char *db_path;
|
static char *db_path;
|
||||||
static __thread sqlite3 *hdl;
|
static __thread sqlite3 *hdl;
|
||||||
|
|
||||||
@ -652,7 +661,7 @@ db_build_query_items(struct query_params *qp, char **q)
|
|||||||
char *query;
|
char *query;
|
||||||
char *count;
|
char *count;
|
||||||
char *idx;
|
char *idx;
|
||||||
char *sort;
|
const char *sort;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (qp->filter)
|
if (qp->filter)
|
||||||
@ -678,20 +687,7 @@ db_build_query_items(struct query_params *qp, char **q)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
switch (qp->sort)
|
sort = sort_clause[qp->sort];
|
||||||
{
|
|
||||||
case S_NONE:
|
|
||||||
sort = "";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_NAME:
|
|
||||||
sort = "ORDER BY title ASC";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_ALBUM:
|
|
||||||
sort = "ORDER BY track ASC, album ASC";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idx && qp->filter)
|
if (idx && qp->filter)
|
||||||
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s %s %s;", qp->filter, sort, idx);
|
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s %s %s;", qp->filter, sort, idx);
|
||||||
@ -817,7 +813,7 @@ db_build_query_plitems_smart(struct query_params *qp, char *smartpl_query, char
|
|||||||
char *count;
|
char *count;
|
||||||
char *filter;
|
char *filter;
|
||||||
char *idx;
|
char *idx;
|
||||||
char *sort;
|
const char *sort;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (qp->filter)
|
if (qp->filter)
|
||||||
@ -847,20 +843,7 @@ db_build_query_plitems_smart(struct query_params *qp, char *smartpl_query, char
|
|||||||
if (!idx)
|
if (!idx)
|
||||||
idx = "";
|
idx = "";
|
||||||
|
|
||||||
switch (qp->sort)
|
sort = sort_clause[qp->sort];
|
||||||
{
|
|
||||||
case S_NONE:
|
|
||||||
sort = "";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_NAME:
|
|
||||||
sort = "ORDER BY title ASC";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_ALBUM:
|
|
||||||
sort = "ORDER BY track ASC, album ASC";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s AND %s %s %s;", smartpl_query, filter, sort, idx);
|
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s AND %s %s %s;", smartpl_query, filter, sort, idx);
|
||||||
if (!query)
|
if (!query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user