Commit f929f8f4e7f4fa27a4a7051b98887401f6bf812e

Authored by David RENÉ
1 parent accc7490

[+] get_all_by_full_clause

[~] in function insert_or_update() , add print debug info on failure
Showing 1 changed file with 22 additions and 5 deletions   Show diff stats
controller/hk_sql_utils.anubis
... ... @@ -435,14 +435,28 @@ public define List($T)
435 435 (
436 436 SQLite3DataBase db,
437 437 String table_name,
438   - String id_col,
439 438 String full_clause,
440 439 (One -> SQLite3Row table_cursor) -> Maybe($T) extractor
441 440 )=
442 441  
443 442 if sql_query_timeout(db, "SELECT * FROM "+table_name+" "+full_clause+";", [], "get_all_by_full_clause") is
444 443 {
445   - 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+";]");[],
  444 + 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+";]");[],
  445 + ok(_, cursor, _) then _get_all(extractor)(cursor, [])
  446 + }
  447 +.
  448 +
  449 +public define List($T)
  450 + get_all_by_full_clause
  451 + (
  452 + SQLite3DataBase db,
  453 + String full_clause,
  454 + (One -> SQLite3Row table_cursor) -> Maybe($T) extractor
  455 + )=
  456 +
  457 + if sql_query_timeout(db, full_clause+";", [], "get_all_by_full_clause") is
  458 + {
  459 + error(sql_error) then println("get_all_by_full_clause SQL ERROR '"+ sql_error.text + "'\n full_clause ["+full_clause+";]");[],
446 460 ok(_, cursor, _) then _get_all(extractor)(cursor, [])
447 461 }
448 462 .
... ... @@ -655,10 +669,11 @@ public define Maybe(Int)
655 669 {
656 670 none then
657 671 since make_insert_clause_and_binds(fields) is (binds, insert_columns, insert_values),
658   - if sql_query_timeout(db, "INSERT INTO "+table_name+" "+insert_columns+" VALUES "+insert_values+";", binds, table_name+" (INSERT)") is
  672 + with insert_query = "INSERT INTO "+table_name+" "+insert_columns+" VALUES "+insert_values+";",
  673 + if sql_query_timeout(db, insert_query, binds, table_name+" (INSERT)") is
659 674 {
660 675 error(sql_error) then
661   - //logError(debug_log, db_error(sql_error, table_name));
  676 + println("insert on table '"+table_name+"' SQL ERROR '"+ sql_error.text + "'\n sql_insert ["+insert_query+"]\n binds "+dump_Binds(binds));
662 677 failure,
663 678 ok(_, cursor, _) then
664 679 if sql_query_scalar(db, "SELECT last_insert_rowid()") is
... ... @@ -676,9 +691,11 @@ public define Maybe(Int)
676 691 },
677 692 db_id(idx) then
678 693 since make_update_clause_and_binds(fields) is (binds, set_string),
679   - if sql_query_timeout(db, "UPDATE "+table_name+" SET "+set_string +" WHERE id = "+idx+";", binds, table_name+" (UPDATE)") is
  694 + with update_query = "UPDATE "+table_name+" SET "+set_string +" WHERE id = "+idx+";",
  695 + if sql_query_timeout(db, update_query, binds, table_name+" (UPDATE)") is
680 696 {
681 697 error(sql_error) then
  698 + println("update on table '"+table_name+"' id ["+idx+"] SQL ERROR '"+ sql_error.text + "'\n sql_insert ["+update_query+"]\n binds "+dump_Binds(binds));
682 699 //logError(debug_log, db_error(sql_error, table_name));
683 700 failure,
684 701 ok(_, _, _) then success(idx)
... ...