From 788cff0cd1ffe950a8ec4c5529a9ed113cc1a0ba Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 6 May 2017 09:21:38 +0900 Subject: [PATCH] add get_count and get_count_by_clause in hk_sql_utils which is better than to have same function with different name for all table. In the future the get_count of each table will use that function instead of make almost same function. --- controller/hk_sql_utils.anubis | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+), 0 deletions(-) diff --git a/controller/hk_sql_utils.anubis b/controller/hk_sql_utils.anubis index 9320946..6de0419 100644 --- a/controller/hk_sql_utils.anubis +++ b/controller/hk_sql_utils.anubis @@ -6,6 +6,7 @@ * © Calexium */ +read calexium_lib/database/db_utils.anubis read hayamiki_lib/types/hayamiki.anubis public define String @@ -27,3 +28,31 @@ public define String " (1 = 1) ", } . + +public define Int + get_count_by_clause + ( + SQLite3DataBase db, + String table_name, + String 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 + { + error(_) then 0, + ok(_, cursor, _) then db_get_integer(cursor) + } +. + +public define Int + get_count + ( + SQLite3DataBase db, + String table_name + )= + get_count_by_clause(db, table_name, "") +. -- libgit2 0.21.4