Commit 788cff0cd1ffe950a8ec4c5529a9ed113cc1a0ba

Authored by totoro
1 parent d5159c4a

add get_count and get_count_by_clause in hk_sql_utils which is better than to ha…

…ve 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.
Showing 1 changed file with 29 additions and 0 deletions   Show diff stats
controller/hk_sql_utils.anubis
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 * © Calexium 6 * © Calexium
7 */ 7 */
8 8
  9 +read calexium_lib/database/db_utils.anubis
9 read hayamiki_lib/types/hayamiki.anubis 10 read hayamiki_lib/types/hayamiki.anubis
10 11
11 public define String 12 public define String
@@ -27,3 +28,31 @@ public define String @@ -27,3 +28,31 @@ public define String
27 " (1 = 1) ", 28 " (1 = 1) ",
28 } 29 }
29 . 30 .
  31 +
  32 +public define Int
  33 + get_count_by_clause
  34 + (
  35 + SQLite3DataBase db,
  36 + String table_name,
  37 + String clause
  38 + )=
  39 + with final_clause = if clause = "" then
  40 + ""
  41 + else
  42 + "WHERE "+clause,
  43 +
  44 + if sql_query_timeout(db, "SELECT COUNT(\"id\") FROM "+table_name+" "+final_clause+";", [], "get_count_by_clause") is
  45 + {
  46 + error(_) then 0,
  47 + ok(_, cursor, _) then db_get_integer(cursor)
  48 + }
  49 +.
  50 +
  51 +public define Int
  52 + get_count
  53 + (
  54 + SQLite3DataBase db,
  55 + String table_name
  56 + )=
  57 + get_count_by_clause(db, table_name, "")
  58 +.