From e226c38d4f14581f3d8d1721cc36be68043cb214 Mon Sep 17 00:00:00 2001 From: Kai Elwert Date: Sun, 5 Dec 2010 16:27:06 +0100 Subject: [PATCH] Add db_query_fetch_string_sort() to fetch string+sortstring results --- src/db.c | 38 ++++++++++++++++++++++++++++++++++++++ src/db.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/src/db.c b/src/db.c index 5c30d64e..6501193a 100644 --- a/src/db.c +++ b/src/db.c @@ -1434,6 +1434,44 @@ db_query_fetch_string(struct query_params *qp, char **string) return 0; } +int +db_query_fetch_string_sort(struct query_params *qp, char **string, char **sortstring) +{ + int ret; + + *string = NULL; + + if (!qp->stmt) + { + DPRINTF(E_LOG, L_DB, "Query not started!\n"); + return -1; + } + + if (!(qp->type & Q_F_BROWSE)) + { + DPRINTF(E_LOG, L_DB, "Not a browse query!\n"); + return -1; + } + + ret = db_blocking_step(qp->stmt); + if (ret == SQLITE_DONE) + { + DPRINTF(E_INFO, L_DB, "End of query results\n"); + *string = NULL; + return 0; + } + else if (ret != SQLITE_ROW) + { + DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl)); + return -1; + } + + *string = (char *)sqlite3_column_text(qp->stmt, 0); + *sortstring = (char *)sqlite3_column_text(qp->stmt, 1); + + return 0; +} + /* Files */ int diff --git a/src/db.h b/src/db.h index a02f9f62..b3468a3b 100644 --- a/src/db.h +++ b/src/db.h @@ -308,6 +308,9 @@ db_query_fetch_group(struct query_params *qp, struct db_group_info *dbgri); int db_query_fetch_string(struct query_params *qp, char **string); +int +db_query_fetch_string_sort(struct query_params *qp, char **string, char **sortstring); + /* Files */ int db_files_get_count(void);