Commit 09d474fb32645cc4ff6ebf07d49f5fcb60acd547

Authored by David RENÉ
2 parents be9ff1bd f929f8f4

Merge branch '1.19' of ssh://gitlab.anubis-lang.com:33000/totoro/hayamiki_lib into 1.19

Showing 1 changed file with 82 additions and 7 deletions   Show diff stats
controller/hk_sql_utils.anubis
... ... @@ -82,6 +82,29 @@ public define Int
82 82 }
83 83 .
84 84  
  85 +public define Int
  86 + db_get_Int
  87 + (
  88 + SQLite3DataBase db,
  89 + String clause,
  90 + List(SQLite3Bind) binds
  91 + )=
  92 + if sql_query_timeout(db, clause+";", binds, "db_get_Int") is
  93 + {
  94 + error(sql_error) then println("db_get_Int SQL ERROR '"+ sql_error.text + "'\n clause ["+clause+";]");0,
  95 + ok(_, cursor, _) then db_get_Int(cursor)
  96 + }
  97 +.
  98 +
  99 +public define Int
  100 + db_get_Int
  101 + (
  102 + SQLite3DataBase db,
  103 + String clause
  104 + )=
  105 + db_get_Int(db, clause, [])
  106 +.
  107 +
85 108 public define Float
86 109 get_count_float_by_full_clause
87 110 (
... ... @@ -95,6 +118,29 @@ public define Float
95 118 }
96 119 .
97 120  
  121 +public define Float
  122 + db_get_Float
  123 + (
  124 + SQLite3DataBase db,
  125 + String clause,
  126 + List(SQLite3Bind) binds
  127 + )=
  128 + if sql_query_timeout(db, clause+";", binds, "db_get_Float") is
  129 + {
  130 + error(sql_error) then println("db_get_Float SQL ERROR '"+ sql_error.text + "'\n clause ["+clause+";]");0.0,
  131 + ok(_, cursor, _) then db_get_Float(cursor)
  132 + }
  133 +.
  134 +
  135 +public define Float
  136 + db_get_Float
  137 + (
  138 + SQLite3DataBase db,
  139 + String clause
  140 + )=
  141 + db_get_Float(db, clause, [])
  142 +.
  143 +
98 144 public define Int
99 145 get_count_by_clause
100 146 (
... ... @@ -209,16 +255,28 @@ public define List(DB_id)
209 255 SQLite3DataBase db,
210 256 String table_name,
211 257 String id_col,
212   - String full_clause
  258 + String full_clause,
  259 + List(SQLite3Bind) binds
213 260 )=
214 261  
215   - if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+full_clause+";", [], "get_db_ids_by_full_clause") is
  262 + if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+full_clause+";", binds, "get_db_ids_by_full_clause") is
216 263 {
217 264 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+";]");[],
218 265 ok(_, cursor, _) then db_get_List_DB_id(cursor)
219 266 }
220 267 .
221 268  
  269 +public define List(DB_id)
  270 + get_db_ids_by_full_clause
  271 + (
  272 + SQLite3DataBase db,
  273 + String table_name,
  274 + String id_col,
  275 + String full_clause
  276 + )=
  277 + get_db_ids_by_full_clause(db, table_name, id_col, full_clause, [])
  278 +.
  279 +
222 280 public define Maybe(Int)
223 281 get_mb_id_by_clause
224 282 (
... ... @@ -381,14 +439,28 @@ public define List($T)
381 439 (
382 440 SQLite3DataBase db,
383 441 String table_name,
384   - String id_col,
385 442 String full_clause,
386 443 (One -> SQLite3Row table_cursor) -> Maybe($T) extractor
387 444 )=
388 445  
389 446 if sql_query_timeout(db, "SELECT * FROM "+table_name+" "+full_clause+";", [], "get_all_by_full_clause") is
390 447 {
391   - 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+";]");[],
  448 + error(sql_error) then println("get_all_by_full_clause SQL ERROR '"+ sql_error.text + "'\n table_name ["+table_name+"]\n full_clause ["+full_clause+";]");[],
  449 + ok(_, cursor, _) then _get_all(extractor)(cursor, [])
  450 + }
  451 +.
  452 +
  453 +public define List($T)
  454 + get_all_by_full_clause
  455 + (
  456 + SQLite3DataBase db,
  457 + String full_clause,
  458 + (One -> SQLite3Row table_cursor) -> Maybe($T) extractor
  459 + )=
  460 +
  461 + if sql_query_timeout(db, full_clause+";", [], "get_all_by_full_clause") is
  462 + {
  463 + error(sql_error) then println("get_all_by_full_clause SQL ERROR '"+ sql_error.text + "'\n full_clause ["+full_clause+";]");[],
392 464 ok(_, cursor, _) then _get_all(extractor)(cursor, [])
393 465 }
394 466 .
... ... @@ -601,10 +673,11 @@ public define Maybe(Int)
601 673 {
602 674 none then
603 675 since make_insert_clause_and_binds(fields) is (binds, insert_columns, insert_values),
604   - if sql_query_timeout(db, "INSERT INTO "+table_name+" "+insert_columns+" VALUES "+insert_values+";", binds, table_name+" (INSERT)") is
  676 + with insert_query = "INSERT INTO "+table_name+" "+insert_columns+" VALUES "+insert_values+";",
  677 + if sql_query_timeout(db, insert_query, binds, table_name+" (INSERT)") is
605 678 {
606 679 error(sql_error) then
607   - //logError(debug_log, db_error(sql_error, table_name));
  680 + println("insert on table '"+table_name+"' SQL ERROR '"+ sql_error.text + "'\n sql_insert ["+insert_query+"]\n binds "+dump_Binds(binds));
608 681 failure,
609 682 ok(_, cursor, _) then
610 683 if sql_query_scalar(db, "SELECT last_insert_rowid()") is
... ... @@ -622,9 +695,11 @@ public define Maybe(Int)
622 695 },
623 696 db_id(idx) then
624 697 since make_update_clause_and_binds(fields) is (binds, set_string),
625   - if sql_query_timeout(db, "UPDATE "+table_name+" SET "+set_string +" WHERE id = "+idx+";", binds, table_name+" (UPDATE)") is
  698 + with update_query = "UPDATE "+table_name+" SET "+set_string +" WHERE id = "+idx+";",
  699 + if sql_query_timeout(db, update_query, binds, table_name+" (UPDATE)") is
626 700 {
627 701 error(sql_error) then
  702 + println("update on table '"+table_name+"' id ["+idx+"] SQL ERROR '"+ sql_error.text + "'\n sql_insert ["+update_query+"]\n binds "+dump_Binds(binds));
628 703 //logError(debug_log, db_error(sql_error, table_name));
629 704 failure,
630 705 ok(_, _, _) then success(idx)
... ...