From 0ebe8ade1fead3f4315229ea5a395661dacd59d3 Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 24 Jul 2022 08:50:28 +0900 Subject: [PATCH] [+] add println in SQL error case instead of nothing. Next time it must in logging part [+] add get_db_ids_by_full_clause which allow to make query on any table, set the column id, give the full clause. Return a list of DB_id. [+] add get_all_by_full_clause which allow to make query on any table, set the column id, give the full clause and provide the extractor for this column data type. --- controller/hk_sql_utils.anubis | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/controller/hk_sql_utils.anubis b/controller/hk_sql_utils.anubis index 929b68e..a3cc7ca 100644 --- a/controller/hk_sql_utils.anubis +++ b/controller/hk_sql_utils.anubis @@ -105,7 +105,7 @@ public define Int if sql_query_timeout(db, "SELECT COUNT(\""+table_name+".id\") FROM "+table_name+" "+clause+";", [], "get_count_by_clause") is { - error(_) then 0, + error(sql_error) then println("get_count_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n clause ["+clause+";]");0, ok(_, cursor, _) then db_get_Int(cursor) } . @@ -135,7 +135,7 @@ public define List(Int) if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is { - error(_) then [], + error(sql_error) then println("get_ids_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n clause ["+clause+";]");[], ok(_, cursor, _) then db_get_List_Int(cursor) } . @@ -152,9 +152,9 @@ public define List(DB_id) else "WHERE "+clause, - if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is + if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_db_ids_by_clause") is { - error(_) then [], + error(sql_error) then println("get_db_ids_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n clause ["+clause+";]");[], ok(_, cursor, _) then db_get_List_DB_id(cursor) } . @@ -174,7 +174,7 @@ public define List(Int) if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is { - error(_) then [], + error(sql_error) then println("get_ids_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n id_col["+id_col+"]\nclause ["+clause+";]");[], ok(_, cursor, _) then db_get_List_Int(cursor) } . @@ -194,7 +194,23 @@ public define List(DB_id) if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is { - error(_) then [], + error(sql_error) then println("get_db_ids_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n id_col["+id_col+"]\nclause ["+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 + )= + + if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+full_clause+";", [], "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) } . @@ -356,6 +372,23 @@ public define (One -> SQLite3Row table_cursor) -> List($T) real_get(cursor, []) . +public define List($T) + get_all_by_full_clause + ( + SQLite3DataBase db, + String table_name, + String id_col, + String full_clause, + (One -> SQLite3Row table_cursor) -> Maybe($T) extractor + )= + + if sql_query_timeout(db, "SELECT * FROM "+table_name+" "+full_clause+";", [], "get_all_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 _get_all(extractor)(cursor, []) + } +. + public define (String, String, String, String) -> List($T) call_back_get_all_by_clause ( -- libgit2 0.21.4