diff options
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); |