mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 16:15:57 -05:00
Add optional sorting clause to Q_ITEMS
This commit is contained in:
parent
4dc8f11887
commit
dc95a04562
24
src/db.c
24
src/db.c
@ -618,6 +618,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;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (qp->filter)
|
if (qp->filter)
|
||||||
@ -643,14 +644,29 @@ db_build_query_items(struct query_params *qp, char **q)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
switch (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;", qp->filter, idx);
|
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s %s %s;", qp->filter, sort, idx);
|
||||||
else if (idx)
|
else if (idx)
|
||||||
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 %s;", idx);
|
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 %s %s;", sort, idx);
|
||||||
else if (qp->filter)
|
else if (qp->filter)
|
||||||
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s;", qp->filter);
|
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 AND %s %s;", qp->filter, sort);
|
||||||
else
|
else
|
||||||
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0;");
|
query = sqlite3_mprintf("SELECT * FROM files WHERE disabled = 0 %s;", sort);
|
||||||
|
|
||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
|
7
src/db.h
7
src/db.h
@ -16,6 +16,12 @@ enum index_type {
|
|||||||
I_SUB
|
I_SUB
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum sort_type {
|
||||||
|
S_NONE = 0,
|
||||||
|
S_NAME,
|
||||||
|
S_ALBUM,
|
||||||
|
};
|
||||||
|
|
||||||
#define Q_F_BROWSE (1 << 15)
|
#define Q_F_BROWSE (1 << 15)
|
||||||
|
|
||||||
enum query_type {
|
enum query_type {
|
||||||
@ -35,6 +41,7 @@ struct query_params {
|
|||||||
/* Query parameters, filled in by caller */
|
/* Query parameters, filled in by caller */
|
||||||
enum query_type type;
|
enum query_type type;
|
||||||
enum index_type idx_type;
|
enum index_type idx_type;
|
||||||
|
enum sort_type sort;
|
||||||
int id;
|
int id;
|
||||||
int offset;
|
int offset;
|
||||||
int limit;
|
int limit;
|
||||||
|
@ -891,6 +891,8 @@ get_query_params(struct evkeyvalq *query, struct query_params *qp)
|
|||||||
|
|
||||||
qp->idx_type = I_SUB;
|
qp->idx_type = I_SUB;
|
||||||
|
|
||||||
|
qp->sort = S_NONE;
|
||||||
|
|
||||||
param = evhttp_find_header(query, "query");
|
param = evhttp_find_header(query, "query");
|
||||||
if (!param)
|
if (!param)
|
||||||
param = evhttp_find_header(query, "filter");
|
param = evhttp_find_header(query, "filter");
|
||||||
|
@ -202,6 +202,8 @@ get_query_params(struct evhttp_request *req, struct evkeyvalq *query, struct que
|
|||||||
else
|
else
|
||||||
qp->idx_type = I_NONE;
|
qp->idx_type = I_NONE;
|
||||||
|
|
||||||
|
qp->sort = S_NONE;
|
||||||
|
|
||||||
param = evhttp_find_header(query, "query");
|
param = evhttp_find_header(query, "query");
|
||||||
if (param)
|
if (param)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user