diff --git a/calexium_lib/database/db_utils.anubis b/calexium_lib/database/db_utils.anubis new file mode 100644 index 0000000..312cdc4 --- /dev/null +++ b/calexium_lib/database/db_utils.anubis @@ -0,0 +1,93 @@ +/* + * + * User: David RENE + * Date: 11/12/2007 + * Time: 01:16 + * (c) Calexium + * + */ + +read tools/basis.anubis +read system/logger.anubis +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, + Int32 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 + ( + SQLite3DataBase db, + String sql_command, + String message + ) = +// logDebug(debug_log, "Entering into transaction [" + message + "]."); + if db_do_transaction( + db, + (One _) |-> + if sql_query(db, sql_command) is + { + error(err) then logError("DB", db_error(err,message));failure //error in the SQL request + ok(cursor) then success(unique) + }, + success( (SQLite3Error err) |-> logError("DB", db_error(err,message))), + 60000 // max 60s + ) is + { + error(err_and_result) then +// logDebug(debug_log, "Exiting from transaction [" + message + "] with error."); + if err_and_result is (err, mb_result) then + error(err), + ok(_) then +// logDebug(debug_log, "Exiting from transaction [" + message + "]."); + ok(unique) + }. + + public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) + sql_query_timeout + ( + SQLite3DataBase db, //database handle + String sql_query, //sql query itself + String msg //message to be shown if an error occure + ) = + //we try with 30 sec of timeout + sql_query_timeout(db, sql_query, now + 30, msg). + +public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) + sql_query_timeout + ( + SQLite3DataBase db, //database handle + String sql_query, //sql query itself + 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 + { + error(sql_error) then logError("DB", db_error(sql_error,msg));failure, + ok(cursor) then success(cursor) + }. -- libgit2 0.21.4