diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2011-01-10 00:39:49 +0100 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2011-12-19 11:05:35 +0100 |
| commit | f0434a3ad51bf1159a78003a020eeb82a26dfc7f (patch) | |
| tree | 905c7b9a18c80757822a2026746f4114d07df7e8 /database/sqlite/sqlite.h | |
| parent | 13834c822bc5763d2df1683ed81add55cf919729 (diff) | |
| download | eurephia-f0434a3ad51bf1159a78003a020eeb82a26dfc7f.tar.gz eurephia-f0434a3ad51bf1159a78003a020eeb82a26dfc7f.tar.xz eurephia-f0434a3ad51bf1159a78003a020eeb82a26dfc7f.zip | |
Implemented better error handling in the SQLite3 framework
The core sqlite_query() function will now always return a pointer to a
dbresult structure. This structure now contains a query status and
the error message from the sqlite3 backend if something went wrong.
This means that error checking from now on should use the
sqlite_query_status() macro and not to check if sqlite_query() returns
NULL.
Another fundamental change is that sqlite_free_results() must always be
called on the dbresult structure now, to free the memory used by either
data from the query or the error message.
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Diffstat (limited to 'database/sqlite/sqlite.h')
| -rw-r--r-- | database/sqlite/sqlite.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/database/sqlite/sqlite.h b/database/sqlite/sqlite.h index ba4cac5..5a7c5fd 100644 --- a/database/sqlite/sqlite.h +++ b/database/sqlite/sqlite.h @@ -81,6 +81,24 @@ typedef struct __sqlite_tuples { /** + * Defines dbresult status types + */ +typedef enum _QueryStatus { dbEMPTY, /**< No SQL query has been performed */ + dbSUCCESS, /**< SQL query was successful */ + dbERROR, /**< SQL query failed */ + dbINVALID /**< Invalid dbresult (NULL value) */ +} QueryStatus; + +/** + * Defines error severities + */ +typedef enum _ErrorSeverity { sevWARNING, /**< Query returns some data, but with errors in completeing it */ + sevERROR, /**< Query could not complete, but may try again */ + sevCRITICAL, /**< Query failed and there is no point of trying again */ + sevPANIC /**< Query failed and eurephia should shutdown */ +} ErrorSeverity; + +/** * The main definition of the dbresult strucutre. This structure keeps the * complete information about both fields and values of all records from a query. * @@ -91,6 +109,9 @@ typedef struct __sqlite_tuples { * as possible. */ typedef struct __sqlite_dbresult { + QueryStatus status; /**< Indicates if the query was successful or not */ + char *query; /**< Copy of the parsed SQL query */ + // Query results _sqlite_tuples *tuples; /**< Pointer to the chains which contains field values */ _sqlite_header *headerrec; /**< Pointer to the chains with info about the field/columns */ @@ -102,6 +123,10 @@ typedef struct __sqlite_dbresult { // "Search" pointers _sqlite_tuples *srch_tuples; /**< "Cache" of the last record being looked up */ _sqlite_header *srch_headerrec; /**< "Cache" of the last header record being looked up */ + + // Error handling + ErrorSeverity errSeverity; /**< Severity of the error */ + char *errMsg; /**< If status == dbERROR, a error message can be found here */ } dbresult; @@ -110,6 +135,7 @@ typedef struct __sqlite_dbresult { */ typedef enum _SQLqueryType { SQL_SELECT, SQL_INSERT, SQL_UPDATE, SQL_DELETE } SQLqueryType; + /** * Free up a dbresult structure. This is the public interface for the * internal function _sqlite_free_results() @@ -118,9 +144,16 @@ typedef enum _SQLqueryType { SQL_SELECT, SQL_INSERT, SQL_UPDATE, SQL_DELETE } SQ */ #define sqlite_free_results(r) { _sqlite_free_results(r); r = NULL; } void _sqlite_free_results(dbresult *); + +void sqlite_log_error(eurephiaCTX *ctx, dbresult *dbres ); +#ifdef HAVE_LIBXML2 +xmlNode *sqlite_log_error_xml(eurephiaCTX *ctx, dbresult *dbres ); +#endif + dbresult *sqlite_query(eurephiaCTX *ctx, const char *, ...); dbresult *sqlite_query_mapped(eurephiaCTX *ctx, SQLqueryType type, const char *sqlstub, eDBfieldMap *valMap, eDBfieldMap *whereMap, const char *sortkeys); +#define sqlite_query_status(res) (QueryStatus) (res != NULL ? res->status : dbINVALID) char *sqlite_get_value(dbresult *res, int, int); #ifdef HAVE_LIBXML2 xmlNodePtr sqlite_xml_value(xmlNodePtr node, xmlFieldType xmltyp, char *name, dbresult *res, int row, int col); |
