From 937d1e3f5ffce00d176f004592beb8f66c6429ef Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 22 Sep 2018 09:32:05 +0200 Subject: [PATCH] [db] Add "group" attribute to query_params and allow grouping files --- src/db.c | 12 ++++++++---- src/db.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/db.c b/src/db.c index a77cd6ea..bb286472 100644 --- a/src/db.c +++ b/src/db.c @@ -1616,6 +1616,10 @@ db_build_query_clause(struct query_params *qp) if (qp->type & Q_F_BROWSE) qc->group = sqlite3_mprintf("GROUP BY %s", browse_clause[qp->type & ~Q_F_BROWSE].group); + else if (qp->group) + qc->group = sqlite3_mprintf("GROUP BY %s", qp->group); + else + qc->group = sqlite3_mprintf(""); if (qp->filter) qc->where = sqlite3_mprintf("WHERE f.disabled = 0 AND %s", qp->filter); @@ -1623,9 +1627,9 @@ db_build_query_clause(struct query_params *qp) qc->where = sqlite3_mprintf("WHERE f.disabled = 0"); if (qp->having && (qp->type & (Q_GROUP_ALBUMS | Q_GROUP_ARTISTS))) - qc->having = sqlite3_mprintf("HAVING %s", qp->having); - else - qc->having = sqlite3_mprintf(""); + qc->having = sqlite3_mprintf("HAVING %s", qp->having); + else + qc->having = sqlite3_mprintf(""); if (qp->order) qc->order = sqlite3_mprintf("ORDER BY %s", qp->order); @@ -1707,7 +1711,7 @@ db_build_query_items(struct query_params *qp) return NULL; count = sqlite3_mprintf("SELECT COUNT(*) FROM files f %s;", qc->where); - query = sqlite3_mprintf("SELECT f.* FROM files f %s %s %s;", qc->where, qc->order, qc->index); + query = sqlite3_mprintf("SELECT f.* FROM files f %s %s %s %s;", qc->where, qc->group, qc->order, qc->index); db_free_query_clause(qc); diff --git a/src/db.h b/src/db.h index afaa938b..75646ee1 100644 --- a/src/db.h +++ b/src/db.h @@ -93,6 +93,7 @@ struct query_params { char *having; char *order; + char *group; char *filter;