From accc7490a42d73a0666e87883bf9170dfd85be8b Mon Sep 17 00:00:00 2001 From: totoro Date: Mon, 13 Mar 2023 14:40:40 +0100 Subject: [PATCH] [+] db_get_float(db, clause), db_get_float(db, clause, binds). [+] db_get_Int(db, clause, binds). [+] db_get_ids_by_full_clause(db, table_name, id_col, full_clause, binds). --- controller/hk_sql_utils.anubis | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/controller/hk_sql_utils.anubis b/controller/hk_sql_utils.anubis index a3cc7ca..2e51511 100644 --- a/controller/hk_sql_utils.anubis +++ b/controller/hk_sql_utils.anubis @@ -78,6 +78,29 @@ public define Int } . +public define Int + db_get_Int + ( + SQLite3DataBase db, + String clause, + List(SQLite3Bind) binds + )= + if sql_query_timeout(db, clause+";", binds, "db_get_Int") is + { + error(sql_error) then println("db_get_Int SQL ERROR '"+ sql_error.text + "'\n clause ["+clause+";]");0, + ok(_, cursor, _) then db_get_Int(cursor) + } +. + +public define Int + db_get_Int + ( + SQLite3DataBase db, + String clause + )= + db_get_Int(db, clause, []) +. + public define Float get_count_float_by_full_clause ( @@ -91,6 +114,29 @@ public define Float } . +public define Float + db_get_Float + ( + SQLite3DataBase db, + String clause, + List(SQLite3Bind) binds + )= + if sql_query_timeout(db, clause+";", binds, "db_get_Float") is + { + error(sql_error) then println("db_get_Float SQL ERROR '"+ sql_error.text + "'\n clause ["+clause+";]");0.0, + ok(_, cursor, _) then db_get_Float(cursor) + } +. + +public define Float + db_get_Float + ( + SQLite3DataBase db, + String clause + )= + db_get_Float(db, clause, []) +. + public define Int get_count_by_clause ( @@ -205,16 +251,28 @@ public define List(DB_id) SQLite3DataBase db, String table_name, String id_col, - String full_clause + String full_clause, + List(SQLite3Bind) binds )= - if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+full_clause+";", [], "get_db_ids_by_full_clause") is + if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+full_clause+";", binds, "get_db_ids_by_full_clause") is { error(sql_error) then println("get_db_ids_by_full_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n id_col["+id_col+"]\nfull_clause ["+full_clause+";]");[], ok(_, cursor, _) then db_get_List_DB_id(cursor) } . +public define List(DB_id) + get_db_ids_by_full_clause + ( + SQLite3DataBase db, + String table_name, + String id_col, + String full_clause + )= + get_db_ids_by_full_clause(db, table_name, id_col, full_clause, []) +. + public define Maybe(Int) get_mb_id_by_clause ( -- libgit2 0.21.4