summaryrefslogtreecommitdiff
path: root/libodbcpp/odbc-error.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 02:42:43 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 06:00:07 +0000
commitbe237957454cd7a4e84a5a603bdef6ab3ab8b8e1 (patch)
treebfe7f06152b2d453bcd097d9913918473d8fecd7 /libodbcpp/odbc-error.cpp
parentRemove rebind (diff)
downloadlibdbpp-odbc-be237957454cd7a4e84a5a603bdef6ab3ab8b8e1.tar.bz2
libdbpp-odbc-be237957454cd7a4e84a5a603bdef6ab3ab8b8e1.tar.xz
libdbpp-odbc-be237957454cd7a4e84a5a603bdef6ab3ab8b8e1.zip
Reshuffle and add new exceptions
Diffstat (limited to 'libodbcpp/odbc-error.cpp')
-rw-r--r--libodbcpp/odbc-error.cpp105
1 files changed, 28 insertions, 77 deletions
diff --git a/libodbcpp/odbc-error.cpp b/libodbcpp/odbc-error.cpp
index 182c022..aa22c2b 100644
--- a/libodbcpp/odbc-error.cpp
+++ b/libodbcpp/odbc-error.cpp
@@ -1,85 +1,36 @@
-#include <stdarg.h>
-#include <stdio.h>
-#include <syslog.h>
-#include <malloc.h>
-#include <time.h>
-#include <string.h>
#include "odbc-error.h"
+#include <buffer.h>
-static
-void
-odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action, char ** msg)
+ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle)
{
- SQLCHAR sqlstatus[6];
- SQLINTEGER sqlerr;
- SQLCHAR sqlerrmsg[12800];
-
- SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg,
- sizeof(sqlerrmsg), NULL);
- switch (rc) {
- case SQL_SUCCESS:
- case SQL_SUCCESS_WITH_INFO:
- if (msg) {
- if (asprintf(msg, "%d: %d: %5.5s: \"%s\" while attempting to %s",
- err, (int)sqlerr, sqlstatus, sqlerrmsg, action) < 1) {
- *msg = NULL;
- }
- }
- syslog(LOG_WARNING, "%s: %d: %d: %5.5s: \"%s\" while attempting to %s",
- __FUNCTION__, err, (int)sqlerr, sqlstatus, sqlerrmsg, action);
- break;
-
- case SQL_INVALID_HANDLE:
- if (msg) {
- if (asprintf(msg, "(%d) Invalid handle passed into function trying to %s.",
- err, action) < 1) {
- *msg = NULL;
- }
- }
- syslog(LOG_ERR, "%s: (%d) Invalid handle passed into function trying to %s.",
- __FUNCTION__, err, action);
- break;
-
- case SQL_NO_DATA:
- if (msg) {
- if (asprintf(msg, "(%d) No error data available for record trying to %s.",
- err, action) < 1) {
- *msg = NULL;
- }
- }
- 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;
- }
-}
-
-ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action)
-{
- odbc_verror(err, handletype, handle, action, &msg);
-}
-
-ODBC::Error::Error(char const * action)
-{
- syslog(LOG_ERR, "%s", action);
- msg = strdup(action);
-}
-
-ODBC::Error::Error(char * m) : msg(m)
-{
-}
-
-ODBC::Error::~Error() throw()
-{
- free(msg);
+ SQLCHAR sqlstatus[6];
+ SQLINTEGER sqlerr;
+ SQLCHAR sqlerrmsg[12800];
+
+ SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, sizeof(sqlerrmsg), NULL);
+ switch (rc) {
+ case SQL_SUCCESS:
+ case SQL_SUCCESS_WITH_INFO:
+ msg = stringbf(msg, "%d: %d: %5.5s: \"%s\"", err, (int)sqlerr, sqlstatus, sqlerrmsg);
+ break;
+
+ case SQL_INVALID_HANDLE:
+ msg = stringbf("(%d) Invalid handle passed into function", err);
+ break;
+
+ case SQL_NO_DATA:
+ msg = stringbf("(%d) No error data available for record", err);
+ break;
+
+ case SQL_ERROR:
+ default:
+ msg = stringbf("Failed to get diagnostics for return code %d", err);
+ break;
+ }
}
-const char *
-ODBC::Error::what() const throw()
+std::string
+ODBC::Error::message() const throw()
{
return msg;
}