Commit e8b059592f01f69bb38f5274bf824522f9403a6f
1 parent
9ee1c57d
add get_count_by_full_clause
Showing
1 changed file
with
20 additions
and
6 deletions
Show diff stats
controller/hk_sql_utils.anubis
| ... | ... | @@ -47,7 +47,20 @@ public define Maybe(One) |
| 47 | 47 | error(_) then failure, |
| 48 | 48 | ok(_, _, _) then success(unique) |
| 49 | 49 | }. |
| 50 | - | |
| 50 | + | |
| 51 | +public define Int | |
| 52 | + get_count_by_full_clause | |
| 53 | + ( | |
| 54 | + SQLite3DataBase db, | |
| 55 | + String clause | |
| 56 | + )= | |
| 57 | + if sql_query_timeout(db, clause+";", [], "get_count_by_clause") is | |
| 58 | + { | |
| 59 | + error(_) then 0, | |
| 60 | + ok(_, cursor, _) then db_get_integer(cursor) | |
| 61 | + } | |
| 62 | +. | |
| 63 | + | |
| 51 | 64 | public define Int |
| 52 | 65 | get_count_by_clause |
| 53 | 66 | ( |
| ... | ... | @@ -55,18 +68,19 @@ public define Int |
| 55 | 68 | String table_name, |
| 56 | 69 | String clause |
| 57 | 70 | )= |
| 58 | - with final_clause = if clause = "" then | |
| 59 | - "" | |
| 60 | - else | |
| 61 | - "WHERE "+clause, | |
| 71 | +// with final_clause = if clause = "" then | |
| 72 | +// "" | |
| 73 | +// else | |
| 74 | +// "WHERE "+clause, | |
| 62 | 75 | |
| 63 | - if sql_query_timeout(db, "SELECT COUNT(\"id\") FROM "+table_name+" "+final_clause+";", [], "get_count_by_clause") is | |
| 76 | + if sql_query_timeout(db, "SELECT COUNT(\""+table_name+".id\") FROM "+table_name+" "+clause+";", [], "get_count_by_clause") is | |
| 64 | 77 | { |
| 65 | 78 | error(_) then 0, |
| 66 | 79 | ok(_, cursor, _) then db_get_integer(cursor) |
| 67 | 80 | } |
| 68 | 81 | . |
| 69 | 82 | |
| 83 | + | |
| 70 | 84 | public define Int |
| 71 | 85 | get_count |
| 72 | 86 | ( | ... | ... |