summaryrefslogtreecommitdiff
path: root/libodbcpp
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
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')
-rw-r--r--libodbcpp/odbc-column.cpp2
-rw-r--r--libodbcpp/odbc-command.cpp24
-rw-r--r--libodbcpp/odbc-connection.cpp67
-rw-r--r--libodbcpp/odbc-connection.h10
-rw-r--r--libodbcpp/odbc-error.cpp105
-rw-r--r--libodbcpp/odbc-error.h15
-rw-r--r--libodbcpp/odbc-modifycommand.cpp14
-rw-r--r--libodbcpp/odbc-param.cpp4
-rw-r--r--libodbcpp/odbc-selectcommand.cpp15
-rw-r--r--libodbcpp/unittests/testodbc.cpp8
10 files changed, 95 insertions, 169 deletions
diff --git a/libodbcpp/odbc-column.cpp b/libodbcpp/odbc-column.cpp
index ef734b9..18926f5 100644
--- a/libodbcpp/odbc-column.cpp
+++ b/libodbcpp/odbc-column.cpp
@@ -49,7 +49,7 @@ ODBC::Column::bind()
{
RETCODE rc = SQLBindCol(selectCmd->hStmt, colNo + 1, ctype(), rwDataAddress(), size(), &bindLen);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, selectCmd->hStmt, "ODBC::Column::bind");
+ throw Error(rc, SQL_HANDLE_STMT, selectCmd->hStmt);
}
}
diff --git a/libodbcpp/odbc-command.cpp b/libodbcpp/odbc-command.cpp
index d96234d..43572c8 100644
--- a/libodbcpp/odbc-command.cpp
+++ b/libodbcpp/odbc-command.cpp
@@ -9,23 +9,23 @@ ODBC::Command::Command(const Connection & c, const std::string & s) :
{
RETCODE rc = SQLAllocHandle(SQL_HANDLE_STMT, c.conn, &hStmt);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "Allocate statement handle");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
rc = SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_DYNAMIC, 0);
if (!SQL_SUCCEEDED(rc)) {
- throw ConnectionError(rc, SQL_HANDLE_STMT, hStmt, "Set scrollable cursor");
+ throw ConnectionError(rc, SQL_HANDLE_STMT, hStmt);
+ }
+ rc = SQLPrepare(hStmt, (SQLCHAR*)sql.c_str(), sql.length());
+ if (!SQL_SUCCEEDED(rc)) {
+ SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
- rc = SQLPrepare(hStmt, (SQLCHAR*)sql.c_str(), sql.length());
- if (!SQL_SUCCEEDED(rc)) {
- SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "Prepare statement");
- }
SQLSMALLINT pcount;
- rc = SQLNumParams(hStmt, &pcount);
- if (!SQL_SUCCEEDED(rc)) {
- SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "Parameter count");
- }
+ rc = SQLNumParams(hStmt, &pcount);
+ if (!SQL_SUCCEEDED(rc)) {
+ SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
+ }
params.resize(pcount);
}
diff --git a/libodbcpp/odbc-connection.cpp b/libodbcpp/odbc-connection.cpp
index a6fa2bd..1788a4a 100644
--- a/libodbcpp/odbc-connection.cpp
+++ b/libodbcpp/odbc-connection.cpp
@@ -1,6 +1,5 @@
#include <sqlext.h>
#include <stdexcept>
-#include <syslog.h>
#include <stdio.h>
#include <string.h>
#include "odbc-connection.h"
@@ -22,7 +21,7 @@ ODBC::Connection::Connection(const DSN& d) :
RETCODE dberr = SQLConnect(conn, (SQLCHAR*)d.dsn.c_str(), SQL_NTS,
(SQLCHAR*)d.username.c_str(), SQL_NTS, (SQLCHAR*)d.password.c_str(), SQL_NTS);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Connect");
+ throw ConnectionError(dberr, SQL_HANDLE_DBC, conn);
}
connectPost();
}
@@ -32,22 +31,22 @@ ODBC::Connection::connectPre()
{
SQLRETURN dberr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Allocate handle");
+ throw ConnectionError(dberr, SQL_HANDLE_ENV, env);
}
dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Set ODBC version");
+ throw ConnectionError(dberr, SQL_HANDLE_ENV, env);
}
dberr = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Allocate DBC handle");
+ throw ConnectionError(dberr, SQL_HANDLE_ENV, env);
}
dberr = SQLSetConnectAttr(conn, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Set connection attributes");
+ throw ConnectionError(dberr, SQL_HANDLE_ENV, env);
}
}
@@ -56,12 +55,12 @@ ODBC::Connection::connectPost()
{
RETCODE dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Set default auto commit");
+ throw ConnectionError(dberr, SQL_HANDLE_DBC, conn);
}
char info[1024];
dberr = SQLGetInfo(conn, SQL_DRIVER_NAME, (SQLCHAR*)info, sizeof(info), NULL);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Get info");
+ throw ConnectionError(dberr, SQL_HANDLE_DBC, conn);
}
// Apply known DB specific tweaks
if (strstr(info, "myodbc") != NULL) {
@@ -81,7 +80,7 @@ ODBC::Connection::Connection(const std::string & s) :
connectPre();
RETCODE dberr = SQLDriverConnect(conn, NULL, (SQLCHAR*)s.c_str(), s.length(), NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
if (!SQL_SUCCEEDED(dberr)) {
- throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Connect");
+ throw ConnectionError(dberr, SQL_HANDLE_DBC, conn);
}
connectPost();
}
@@ -89,17 +88,11 @@ ODBC::Connection::Connection(const std::string & s) :
ODBC::Connection::~Connection()
{
if (conn) {
- if (!SQL_SUCCEEDED(SQLDisconnect(conn))) {
- syslog(LOG_WARNING, "%s: Disconnect error", __FUNCTION__);
- }
- if (!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_DBC, conn))) {
- syslog(LOG_WARNING, "%s: Free connection handle error", __FUNCTION__);
- }
+ SQL_SUCCEEDED(SQLDisconnect(conn));
+ SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_DBC, conn));
}
if (env) {
- if (!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_ENV, env))) {
- syslog(LOG_WARNING, "%s: Free connection handle error", __FUNCTION__);
- }
+ SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_ENV, env));
}
}
@@ -108,7 +101,7 @@ ODBC::Connection::finish() const
{
if (txDepth != 0) {
rollbackTx();
- throw Error("Transaction still open");
+ throw DB::TransactionStillOpen();
}
}
@@ -118,7 +111,7 @@ ODBC::Connection::beginTx() const
if (txDepth == 0) {
SQLRETURN dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
if (!SQL_SUCCEEDED(dberr)) {
- throw Error(dberr, SQL_HANDLE_DBC, conn, "Set default auto commit");
+ throw Error(dberr, SQL_HANDLE_DBC, conn);
}
}
txDepth += 1;
@@ -136,17 +129,17 @@ ODBC::Connection::commitTx() const
if (txDepth == 0) {
SQLRETURN dberr = SQLEndTran(SQL_HANDLE_DBC, conn, SQL_COMMIT);
if (!SQL_SUCCEEDED(dberr)) {
- throw Error(dberr, SQL_HANDLE_DBC, conn, "SQLEndTran (SQL_COMMIT)");
+ throw Error(dberr, SQL_HANDLE_DBC, conn);
}
dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
if (!SQL_SUCCEEDED(dberr)) {
- throw Error(dberr, SQL_HANDLE_DBC, conn, "Enable auto commit");
+ throw Error(dberr, SQL_HANDLE_DBC, conn);
}
txAborted = false;
}
return txDepth;
}
- throw Error("Attempt to commit none existant transaction");
+ throw DB::TransactionRequired();
}
int
@@ -157,17 +150,17 @@ ODBC::Connection::rollbackTx() const
if (txDepth == 0) {
SQLRETURN dberr = SQLEndTran(SQL_HANDLE_DBC, conn, SQL_ROLLBACK);
if (!SQL_SUCCEEDED(dberr)) {
- throw Error(dberr, SQL_HANDLE_DBC, conn, "SQLEndTran (SQL_ROLLBACK)");
+ throw Error(dberr, SQL_HANDLE_DBC, conn);
}
dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
if (!SQL_SUCCEEDED(dberr)) {
- throw Error(dberr, SQL_HANDLE_DBC, conn, "Enable auto commit");
+ throw Error(dberr, SQL_HANDLE_DBC, conn);
}
txAborted = false;
}
return txDepth;
}
- throw Error("Attempt to rollback none existant transaction");
+ throw DB::TransactionRequired();
}
void
@@ -220,7 +213,7 @@ ODBC::Connection::getAttrStr(SQLINTEGER attr) const
SQLINTEGER size = 0;
SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, (unsigned char *)rtn.c_str(), BUFSIZ, &size);
if (!SQL_SUCCEEDED(dberr)) {
- throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn, "ODBC::Connection::getAttrStr SQLGetConnectAttr");
+ throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn);
}
rtn.resize(size);
return rtn;
@@ -232,7 +225,7 @@ ODBC::Connection::getAttrInt(SQLINTEGER attr) const
SQLINTEGER result;
SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, &result, sizeof(result), 0);
if (!SQL_SUCCEEDED(dberr)) {
- throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn, "ODBC::Connection::getAttrInt SQLGetConnectAttr");
+ throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn);
}
return result;
}
@@ -242,32 +235,26 @@ ODBC::Connection::ping() const
{
SQLINTEGER dead = getAttrInt(SQL_ATTR_CONNECTION_DEAD);
if (dead != SQL_CD_FALSE) {
- throw ODBC::Error("Connection is dead");
+ throw ODBC::ConnectionError(0, SQL_HANDLE_DBC, conn);
}
}
-ODBC::ConnectionError::ConnectionError(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * stage) :
- ODBC::Error(err, handletype, handle, stage),
+ODBC::ConnectionError::ConnectionError(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle) :
+ ODBC::Error(err, handletype, handle),
DB::ConnectionError()
{
}
-ODBC::ConnectionError::ConnectionError(const ConnectionError & e) :
- ODBC::Error(strdup(e.what())),
- DB::ConnectionError(e.FailureTime)
-{
-}
-
void ODBC::Connection::beginBulkUpload(const char *, const char *) const
{
- throw std::runtime_error("Not implemented");
+ throw DB::BulkUploadNotSupported();
}
void ODBC::Connection::endBulkUpload(const char *) const
{
- throw std::runtime_error("Not implemented");
+ throw DB::BulkUploadNotSupported();
}
size_t ODBC::Connection::bulkUploadData(const char *, size_t) const
{
- throw std::runtime_error("Not implemented");
+ throw DB::BulkUploadNotSupported();
}
diff --git a/libodbcpp/odbc-connection.h b/libodbcpp/odbc-connection.h
index d927b70..c2f4791 100644
--- a/libodbcpp/odbc-connection.h
+++ b/libodbcpp/odbc-connection.h
@@ -8,6 +8,11 @@
#include <sql.h>
namespace ODBC {
+ class ConnectionError : public virtual Error, public virtual DB::ConnectionError {
+ public:
+ ConnectionError(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle);
+ };
+
class Connection : public DB::Connection {
public:
Connection(const DSN& d);
@@ -45,11 +50,6 @@ namespace ODBC {
mutable unsigned int txDepth;
mutable bool txAborted;
};
- class ConnectionError : public DB::ConnectionError, public virtual Error {
- public:
- ConnectionError(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * stage);
- ConnectionError(const ConnectionError &);
- };
}
#endif
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;
}
diff --git a/libodbcpp/odbc-error.h b/libodbcpp/odbc-error.h
index 0348980..fb9412c 100644
--- a/libodbcpp/odbc-error.h
+++ b/libodbcpp/odbc-error.h
@@ -3,21 +3,18 @@
#include <sql.h>
#include <stdlib.h>
-#include <exception>
+#include <exception.h>
#include <error.h>
namespace ODBC {
- class Error : public DB::Error {
+ class Error : public AdHoc::Exception<DB::Error> {
public:
- Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action);
- Error(char const * action);
- ~Error() throw();
+ Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle);
+
+ std::string message() const throw() override;
- const char * what() const throw();
- protected:
- Error(char * msg);
private:
- char * msg;
+ std::string msg;
};
}
diff --git a/libodbcpp/odbc-modifycommand.cpp b/libodbcpp/odbc-modifycommand.cpp
index 5d483c5..cb6d3c0 100644
--- a/libodbcpp/odbc-modifycommand.cpp
+++ b/libodbcpp/odbc-modifycommand.cpp
@@ -15,26 +15,20 @@ ODBC::ModifyCommand::~ModifyCommand()
unsigned int
ODBC::ModifyCommand::execute(bool anc)
{
- if (connection.txIsAborted()) {
- throw Error("Transaction has been aborted, not issuing any more commands");
- }
RETCODE rc = SQLExecute(hStmt);
if (!SQL_SUCCEEDED(rc)) {
if (rc != SQL_NO_DATA || !anc) {
- connection.abortTx();
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::ModifyCommand::execute SQLExecute");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
}
SQLLEN rows;
rc = SQLRowCount(hStmt, &rows);
- if (!SQL_SUCCEEDED(rc)) {
- connection.abortTx();
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::ModifyCommand::execute SQLRowCount");
+ if (!SQL_SUCCEEDED(rc)) {
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
if (rows > 0 || anc) {
return rows;
}
- connection.abortTx();
- throw Error("No rows affected");
+ throw DB::NoRowsAffected();
}
diff --git a/libodbcpp/odbc-param.cpp b/libodbcpp/odbc-param.cpp
index cd78940..f165d60 100644
--- a/libodbcpp/odbc-param.cpp
+++ b/libodbcpp/odbc-param.cpp
@@ -26,7 +26,7 @@ ParamType *
ODBC::Command::makeParam(unsigned int idx)
{
if (idx >= params.size()) {
- throw Error("ODBC::Command::makeParam Bind out of bounds");
+ throw DB::ParameterOutOfRange();
}
Param * & p = params[idx];
if (p) {
@@ -48,7 +48,7 @@ ODBC::Param::bind() const
RETCODE rc = SQLBindParameter(paramCmd->hStmt, paramIdx + 1, SQL_PARAM_INPUT, ctype(), stype(),
size(), dp(), const_cast<void *>(dataAddress()), size(), &bindLen);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, paramCmd->hStmt, "ODBC::Param::bind Bind parameter");
+ throw Error(rc, SQL_HANDLE_STMT, paramCmd->hStmt);
}
paramBound = true;
}
diff --git a/libodbcpp/odbc-selectcommand.cpp b/libodbcpp/odbc-selectcommand.cpp
index 52a45ad..6418501 100644
--- a/libodbcpp/odbc-selectcommand.cpp
+++ b/libodbcpp/odbc-selectcommand.cpp
@@ -19,7 +19,7 @@ ODBC::SelectCommand::~SelectCommand()
if (!columns->empty()) {
RETCODE rc = SQLCloseCursor(hStmt);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::~SelectCommand SQLCloseCursor");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
}
}
@@ -52,7 +52,7 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
}
}
if (rc != SQL_SUCCESS_WITH_INFO) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::fetch SQLFetch");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
}
case SQL_SUCCESS:
@@ -76,14 +76,11 @@ ODBC::SelectCommand::execute()
{
RETCODE rc = SQLExecute(hStmt);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::execute SQLExecute");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
SQLSMALLINT colCount;
if (!SQL_SUCCEEDED(rc = SQLNumResultCols(hStmt, &colCount))) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::execute SQLNumResultCols");
- }
- if (colCount < 1) {
- throw Error("ODBC::SelectCommand::execute No result columns");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
for (int col = 0; col < colCount; col++) {
SQLCHAR _colName[300];
@@ -92,7 +89,7 @@ ODBC::SelectCommand::execute()
int sqlcol = col + 1;
if (!SQL_SUCCEEDED(rc = SQLDescribeCol(hStmt, sqlcol, _colName, sizeof(_colName), &nameLen, &bindType,
&bindSize, &dp, &nullable))) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::execute SQLDescribeCol for %d");
+ throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
Glib::ustring colName((const char *)_colName, nameLen);
DB::ColumnPtr ncol;
@@ -133,7 +130,7 @@ ODBC::SelectCommand::execute()
ncol = insertColumn(DB::ColumnPtr(new TimeStampColumn(this, colName, col)));
break;
case SQL_UNKNOWN_TYPE:
- throw Error("Unknown column type");
+ throw DB::ColumnTypeNotSupported();
default:
ncol = insertColumn(DB::ColumnPtr(new CharArrayColumn(this, colName, col, bindSize)));
break;
diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp
index aa36460..f288bf8 100644
--- a/libodbcpp/unittests/testodbc.cpp
+++ b/libodbcpp/unittests/testodbc.cpp
@@ -2,10 +2,10 @@
#include <boost/test/unit_test.hpp>
#include <definedDirs.h>
-#include <dbpp/modifycommand.h>
-#include <dbpp/selectcommand.h>
-#include <dbpp/column.h>
-#include <dbpp/error.h>
+#include <modifycommand.h>
+#include <selectcommand.h>
+#include <column.h>
+#include <error.h>
#include <odbc-mock.h>
#include <testCore.h>
#include <definedDirs.h>