diff --git a/calexium_lib/database/db_utils.anubis b/calexium_lib/database/db_utils.anubis index 17b7e25..eb576db 100644 --- a/calexium_lib/database/db_utils.anubis +++ b/calexium_lib/database/db_utils.anubis @@ -13,32 +13,6 @@ read data_base/sqlite.anubis read calexium_lib/net_services_protocols/logger_service.anubis - -define Result(SQLite3Error, SQLite3HeadersOrRow -> SQLite3Row) - sql_query_timeout - ( - SQLite3DataBase db, - String sql_command, - Int timeout - ) = - - if sql_query(db, sql_command) is - { - error(sql_error) then ( - if (sql_error.code /= 1 & sql_error.code /= 5 & sql_error.code /= 6) | now > timeout then - error(sql_error) - else - ( - if sql_error.code = 5 then - unique - else - print_db_error(sql_error) - ); - sleep(100); - sql_query_timeout(db, sql_command, timeout)), - ok(cursor) then ok(cursor) - }. - public define Result(SQLite3Error, One) sql_transaction ( @@ -70,6 +44,23 @@ public define Result(SQLite3Error, One) }. + +public define SQLite3QueryResult + sql_query_timeout + ( + SQLite3DataBase db, //database handle + String sql_query, //sql query itself + List(SQLite3Bind) initial_bindings, + String msg //message to be shown if an error occure + ) = + //we try with 30 sec of timeout + if sql_query_timeout(db, sql_query, initial_bindings, 60, 100) is + { + error(sql_error) then logError("DB", db_error(sql_error,msg)); error(sql_error), + ok(headers, cursor, reset) then ok(headers, cursor, reset) + }. + +// deprecated. Use one of the previous ones. public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) sql_query_timeout ( @@ -78,10 +69,17 @@ public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) String msg //message to be shown if an error occure ) = //we try with 30 sec of timeout - if sql_query_timeout(db, sql_query, now + 60) is + if sql_query_timeout(db, sql_query, [], 60, 100) is { error(sql_error) then logError("DB", db_error(sql_error,msg));failure, - ok(cursor) then success(cursor) + ok(headers, cursor, reset) then + success((SQLite3HeadersOrRow h_or_r) |-> if h_or_r is + { + headers then + with cols = map((String c) |-> (SQLite3Datum)text(c), headers(unique)), + row((Int n) |-> force(nth(n, cols), no_such_column)), + next_row then cursor(unique) + }) }. // -- Extractors HELPERS --------------- -- libgit2 0.21.4