From 8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Sun, 9 Jan 2011 23:39:08 +0100 Subject: Modified the whole edb-sqlite driver to use a better error handling This will change the driver to use the new error routines made available in the SQLite3 framework. Some of the code is also restructured a little bit to simplify the code with these changes. The functionality should be the same as for, but better error messages are now sent back to the caller on the functions supporting XML. Signed-off-by: David Sommerseth --- database/sqlite/administration/attempts.c | 32 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'database/sqlite/administration/attempts.c') diff --git a/database/sqlite/administration/attempts.c b/database/sqlite/administration/attempts.c index 0085f08..d296172 100644 --- a/database/sqlite/administration/attempts.c +++ b/database/sqlite/administration/attempts.c @@ -70,8 +70,10 @@ xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap) { " registered, last_attempt, atpid" " FROM openvpn_attempts", NULL, fmap, "atpid"); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_ERROR, 0, "Error querying the attempts log"); + sqlite_log_error(ctx, res); + sqlite_free_results(res); return NULL; } @@ -141,13 +143,17 @@ xmlDoc *attempts_reset(eurephiaCTX *ctx, eDBfieldMap *fmap) { } res = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_attempts", update_vals, fmap, NULL); - if( res == NULL ) { - eurephia_log(ctx, LOG_FATAL, 0, "Could not reset the attempts count"); - ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not reset the attempts count"); - } else { + if( sqlite_query_status(res) == dbSUCCESS ) { ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Attempts count reset"); - sqlite_free_results(res); + } else { + xmlNode *err_n = NULL; + + eurephia_log(ctx, LOG_FATAL, 0, "Could not reset the attempts count"); + err_n = sqlite_log_error_xml(ctx, res); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not reset the attempts count"); + xmlFreeNode(err_n); } + sqlite_free_results(res); return ret; } @@ -172,13 +178,17 @@ xmlDoc *attempts_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { } res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_attempts", NULL, fmap, NULL); - if( res == NULL ) { - eurephia_log(ctx, LOG_FATAL, 0, "Could not remove attempts record"); - ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the attempts record"); - } else { + if( sqlite_query_status(res) == dbSUCCESS ) { ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Attempts record removed"); - sqlite_free_results(res); + } else { + xmlNode *err_n = NULL; + + eurephia_log(ctx, LOG_FATAL, 0, "Could not remove attempts record"); + err_n = sqlite_log_error_xml(ctx, res); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not delete the attempts record"); + xmlFreeNode(err_n); } + sqlite_free_results(res); return ret; } -- cgit