Commit 0ebe8ade1fead3f4315229ea5a395661dacd59d3
1 parent
77ea06e9
[+] 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.
Showing
1 changed file
with
39 additions
and
6 deletions
Show diff stats
controller/hk_sql_utils.anubis
| ... | ... | @@ -105,7 +105,7 @@ public define Int |
| 105 | 105 | |
| 106 | 106 | if sql_query_timeout(db, "SELECT COUNT(\""+table_name+".id\") FROM "+table_name+" "+clause+";", [], "get_count_by_clause") is |
| 107 | 107 | { |
| 108 | - error(_) then 0, | |
| 108 | + error(sql_error) then println("get_count_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n clause ["+clause+";]");0, | |
| 109 | 109 | ok(_, cursor, _) then db_get_Int(cursor) |
| 110 | 110 | } |
| 111 | 111 | . |
| ... | ... | @@ -135,7 +135,7 @@ public define List(Int) |
| 135 | 135 | |
| 136 | 136 | if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is |
| 137 | 137 | { |
| 138 | - error(_) then [], | |
| 138 | + error(sql_error) then println("get_ids_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n clause ["+clause+";]");[], | |
| 139 | 139 | ok(_, cursor, _) then db_get_List_Int(cursor) |
| 140 | 140 | } |
| 141 | 141 | . |
| ... | ... | @@ -152,9 +152,9 @@ public define List(DB_id) |
| 152 | 152 | else |
| 153 | 153 | "WHERE "+clause, |
| 154 | 154 | |
| 155 | - if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is | |
| 155 | + if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_db_ids_by_clause") is | |
| 156 | 156 | { |
| 157 | - error(_) then [], | |
| 157 | + error(sql_error) then println("get_db_ids_by_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n clause ["+clause+";]");[], | |
| 158 | 158 | ok(_, cursor, _) then db_get_List_DB_id(cursor) |
| 159 | 159 | } |
| 160 | 160 | . |
| ... | ... | @@ -174,7 +174,7 @@ public define List(Int) |
| 174 | 174 | |
| 175 | 175 | if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is |
| 176 | 176 | { |
| 177 | - error(_) then [], | |
| 177 | + 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+";]");[], | |
| 178 | 178 | ok(_, cursor, _) then db_get_List_Int(cursor) |
| 179 | 179 | } |
| 180 | 180 | . |
| ... | ... | @@ -194,7 +194,23 @@ public define List(DB_id) |
| 194 | 194 | |
| 195 | 195 | if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is |
| 196 | 196 | { |
| 197 | - error(_) then [], | |
| 197 | + 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+";]");[], | |
| 198 | + ok(_, cursor, _) then db_get_List_DB_id(cursor) | |
| 199 | + } | |
| 200 | +. | |
| 201 | + | |
| 202 | +public define List(DB_id) | |
| 203 | + get_db_ids_by_full_clause | |
| 204 | + ( | |
| 205 | + SQLite3DataBase db, | |
| 206 | + String table_name, | |
| 207 | + String id_col, | |
| 208 | + String full_clause | |
| 209 | + )= | |
| 210 | + | |
| 211 | + if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+full_clause+";", [], "get_db_ids_by_full_clause") is | |
| 212 | + { | |
| 213 | + 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+";]");[], | |
| 198 | 214 | ok(_, cursor, _) then db_get_List_DB_id(cursor) |
| 199 | 215 | } |
| 200 | 216 | . |
| ... | ... | @@ -356,6 +372,23 @@ public define (One -> SQLite3Row table_cursor) -> List($T) |
| 356 | 372 | real_get(cursor, []) |
| 357 | 373 | . |
| 358 | 374 | |
| 375 | +public define List($T) | |
| 376 | + get_all_by_full_clause | |
| 377 | + ( | |
| 378 | + SQLite3DataBase db, | |
| 379 | + String table_name, | |
| 380 | + String id_col, | |
| 381 | + String full_clause, | |
| 382 | + (One -> SQLite3Row table_cursor) -> Maybe($T) extractor | |
| 383 | + )= | |
| 384 | + | |
| 385 | + if sql_query_timeout(db, "SELECT * FROM "+table_name+" "+full_clause+";", [], "get_all_by_full_clause") is | |
| 386 | + { | |
| 387 | + 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+";]");[], | |
| 388 | + ok(_, cursor, _) then _get_all(extractor)(cursor, []) | |
| 389 | + } | |
| 390 | +. | |
| 391 | + | |
| 359 | 392 | public define (String, String, String, String) -> List($T) |
| 360 | 393 | call_back_get_all_by_clause |
| 361 | 394 | ( | ... | ... |