From e8b059592f01f69bb38f5274bf824522f9403a6f Mon Sep 17 00:00:00 2001 From: totoro Date: Mon, 14 Aug 2017 13:02:34 +0200 Subject: [PATCH] add get_count_by_full_clause --- controller/hk_sql_utils.anubis | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/controller/hk_sql_utils.anubis b/controller/hk_sql_utils.anubis index 3ce21f5..7ccf95a 100644 --- a/controller/hk_sql_utils.anubis +++ b/controller/hk_sql_utils.anubis @@ -47,7 +47,20 @@ public define Maybe(One) error(_) then failure, ok(_, _, _) then success(unique) }. - + +public define Int + get_count_by_full_clause + ( + SQLite3DataBase db, + String clause + )= + if sql_query_timeout(db, clause+";", [], "get_count_by_clause") is + { + error(_) then 0, + ok(_, cursor, _) then db_get_integer(cursor) + } +. + public define Int get_count_by_clause ( @@ -55,18 +68,19 @@ public define Int String table_name, String clause )= - with final_clause = if clause = "" then - "" - else - "WHERE "+clause, +// with final_clause = if clause = "" then +// "" +// else +// "WHERE "+clause, - if sql_query_timeout(db, "SELECT COUNT(\"id\") FROM "+table_name+" "+final_clause+";", [], "get_count_by_clause") is + if sql_query_timeout(db, "SELECT COUNT(\""+table_name+".id\") FROM "+table_name+" "+clause+";", [], "get_count_by_clause") is { error(_) then 0, ok(_, cursor, _) then db_get_integer(cursor) } . + public define Int get_count ( -- libgit2 0.21.4