diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2011-01-09 23:39:08 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2011-12-19 11:05:38 +0100 |
commit | 8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927 (patch) | |
tree | a778cb9ee6f06b41f256a22450af8fd7916a3ed8 /database/sqlite/administration/attempts.c | |
parent | f0434a3ad51bf1159a78003a020eeb82a26dfc7f (diff) | |
download | eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.tar.gz eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.tar.xz eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.zip |
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 <dazo@users.sourceforge.net>
Diffstat (limited to 'database/sqlite/administration/attempts.c')
-rw-r--r-- | database/sqlite/administration/attempts.c | 32 |
1 files changed, 21 insertions, 11 deletions
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; } |