diff options
author | randomdan <randomdan@localhost> | 2006-07-08 16:32:05 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2006-07-08 16:32:05 +0000 |
commit | 2a1fa15d8baa4eda37e17b2e9362f8bde17a939d (patch) | |
tree | 09386e52320b7c52a521ab56fc7553896e639dcd /libodbcpp/error.cpp | |
download | libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.tar.bz2 libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.tar.xz libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.zip |
libcodbcpp initial release
Diffstat (limited to 'libodbcpp/error.cpp')
-rw-r--r-- | libodbcpp/error.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/libodbcpp/error.cpp b/libodbcpp/error.cpp new file mode 100644 index 0000000..c7f16c7 --- /dev/null +++ b/libodbcpp/error.cpp @@ -0,0 +1,62 @@ +#include <stdarg.h> +#include <stdio.h> +#include <syslog.h> +#include <malloc.h> +#include "error.h" + +static +void +odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * actionfmt, va_list ap) +{ + SQLCHAR sqlstatus[6]; + SQLINTEGER sqlerr; + SQLCHAR sqlerrmsg[12800]; + + char * action; + vasprintf(&action, actionfmt, ap); + + SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, + sizeof(sqlerrmsg), NULL); + switch (rc) { + case SQL_SUCCESS: + case SQL_SUCCESS_WITH_INFO: + syslog(LOG_WARNING, "%s: %d: %ld: %5.5s: \"%s\" while attempting to %s", + __FUNCTION__, err, sqlerr, sqlstatus, sqlerrmsg, action); + break; + + case SQL_INVALID_HANDLE: + syslog(LOG_ERR, "%s: (%d) Invalid handle passed into function trying to %s.", + __FUNCTION__, err, action); + break; + + case SQL_NO_DATA: + syslog(LOG_ERR, "%s: (%d) No error data available for record trying to %s.", + __FUNCTION__, err, action); + break; + + case SQL_ERROR: + default: + syslog(LOG_ERR, "%s: Unexpected error!!", __FUNCTION__); + break; + } + free(action); +} + +ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action, ...) +{ + va_list ap; + + va_start(ap, action); + odbc_verror(err, handletype, handle, action, ap); + va_end(ap); +} + +ODBC::Error::Error(char const * action, ...) +{ + va_list ap; + + va_start(ap, action); + vsyslog(LOG_ERR, action, ap); + va_end(ap); +} + |