summaryrefslogtreecommitdiff
path: root/libodbcpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-11-25 19:26:04 +0000
committerrandomdan <randomdan@localhost>2010-11-25 19:26:04 +0000
commitbf8c4b6990a203c28b92ca09e170d0cbea206092 (patch)
tree9591f50c8c39b7b33a4b4659b0c997545aa7c79a /libodbcpp
parentTidy up jam stuff (diff)
downloadlibdbpp-odbc-bf8c4b6990a203c28b92ca09e170d0cbea206092.tar.bz2
libdbpp-odbc-bf8c4b6990a203c28b92ca09e170d0cbea206092.tar.xz
libdbpp-odbc-bf8c4b6990a203c28b92ca09e170d0cbea206092.zip
Use proper ODBC SQL_SUCCEEDED macro, not SQL_SUCCESS comparison
Diffstat (limited to 'libodbcpp')
-rw-r--r--libodbcpp/column.cpp2
-rw-r--r--libodbcpp/command.cpp8
-rw-r--r--libodbcpp/connection.cpp48
-rw-r--r--libodbcpp/modifycommand.cpp10
-rw-r--r--libodbcpp/param.cpp2
-rw-r--r--libodbcpp/selectcommand.cpp24
6 files changed, 48 insertions, 46 deletions
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 5ec1e04..4d071e1 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -63,7 +63,7 @@ void
ODBC::Column::bind()
{
RETCODE rc = SQLBindCol(selectCmd->hStmt, colNo + 1, ctype(), rwDataAddress(), size(), &bindLen);
- if (rc != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(rc)) {
throw Error(rc, SQL_HANDLE_STMT, selectCmd->hStmt, "%s: Bind column %u", __FUNCTION__, colNo);
}
}
diff --git a/libodbcpp/command.cpp b/libodbcpp/command.cpp
index 50dd679..db6a51c 100644
--- a/libodbcpp/command.cpp
+++ b/libodbcpp/command.cpp
@@ -8,21 +8,21 @@ ODBC::Command::Command(const Connection & c, const std::string & s) :
connection(c)
{
RETCODE rc = SQLAllocHandle(SQL_HANDLE_STMT, c.conn, &hStmt);
- if (rc != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(rc)) {
throw Error(rc, SQL_HANDLE_STMT, hStmt, "Allocate statement handle");
}
rc = SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_DYNAMIC, 0);
- if ((rc != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(rc)) {
throw ConnectionError(rc, SQL_HANDLE_STMT, hStmt, "Set scrollable cursor");
}
rc = SQLPrepare(hStmt, (SQLCHAR*)sql.c_str(), sql.length());
- if (rc != SQL_SUCCESS) {
+ 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 (rc != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(rc)) {
SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
throw Error(rc, SQL_HANDLE_STMT, hStmt, "Parameter count");
}
diff --git a/libodbcpp/connection.cpp b/libodbcpp/connection.cpp
index 79c0f9d..2624d98 100644
--- a/libodbcpp/connection.cpp
+++ b/libodbcpp/connection.cpp
@@ -14,7 +14,7 @@ ODBC::Connection::Connection(const DSN& d) :
connectPre();
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 ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Connect");
}
connectPost();
@@ -24,22 +24,22 @@ void
ODBC::Connection::connectPre()
{
SQLRETURN dberr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Allocate handle");
}
dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Set ODBC version");
}
dberr = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Allocate DBC handle");
}
dberr = SQLSetConnectAttr(conn, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_ENV, env, "Set connection attributes");
}
}
@@ -48,7 +48,7 @@ void
ODBC::Connection::connectPost()
{
RETCODE dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Set default auto commit");
}
}
@@ -61,7 +61,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 ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Connect");
}
connectPost();
@@ -70,15 +70,15 @@ ODBC::Connection::Connection(const std::string & s) :
ODBC::Connection::~Connection()
{
if (conn) {
- if (SQLDisconnect(conn) != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(SQLDisconnect(conn))) {
syslog(LOG_WARNING, "%s: Disconnect error", __FUNCTION__);
}
- if (SQLFreeHandle(SQL_HANDLE_DBC, conn) != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_DBC, conn))) {
syslog(LOG_WARNING, "%s: Free connection handle error", __FUNCTION__);
}
}
if (env) {
- if (SQLFreeHandle(SQL_HANDLE_ENV, env) != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_ENV, env))) {
syslog(LOG_WARNING, "%s: Free connection handle error", __FUNCTION__);
}
}
@@ -89,7 +89,7 @@ ODBC::Connection::beginTx() const
{
if (txDepth == 0) {
SQLRETURN dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw Error(dberr, SQL_HANDLE_DBC, conn, "Set default auto commit");
}
}
@@ -107,11 +107,11 @@ ODBC::Connection::commitTx() const
txDepth -= 1;
if (txDepth == 0) {
SQLRETURN dberr = SQLEndTran(SQL_HANDLE_DBC, conn, SQL_COMMIT);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw Error(dberr, SQL_HANDLE_DBC, conn, "SQLEndTran (SQL_COMMIT)");
}
dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw Error(dberr, SQL_HANDLE_DBC, conn, "Enable auto commit");
}
txAborted = false;
@@ -128,11 +128,11 @@ ODBC::Connection::rollbackTx() const
txDepth -= 1;
if (txDepth == 0) {
SQLRETURN dberr = SQLEndTran(SQL_HANDLE_DBC, conn, SQL_ROLLBACK);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw Error(dberr, SQL_HANDLE_DBC, conn, "SQLEndTran (SQL_ROLLBACK)");
}
dberr = SQLSetConnectOption(conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
- if ((dberr != SQL_SUCCESS)) {
+ if (!SQL_SUCCEEDED(dberr)) {
throw Error(dberr, SQL_HANDLE_DBC, conn, "Enable auto commit");
}
txAborted = false;
@@ -163,22 +163,24 @@ ODBC::Connection::inTx() const
std::string
ODBC::Connection::getAttrStr(SQLINTEGER attr) const
{
- unsigned char buf[BUFSIZ];
+ std::string rtn;
+ rtn.resize(BUFSIZ);
SQLINTEGER size = 0;
- SQLINTEGER rc = SQLGetConnectAttr(conn, attr, buf, BUFSIZ, &size);
- if (rc != SQL_SUCCESS) {
- throw ODBC::Error(rc, SQL_HANDLE_DBC, conn, "%s", __FUNCTION__);
+ SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, (unsigned char *)rtn.c_str(), BUFSIZ, &size);
+ if (!SQL_SUCCEEDED(dberr)) {
+ throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn, "%s", __FUNCTION__);
}
- return std::string((const char *)buf, size);
+ rtn.resize(size);
+ return rtn;
}
SQLINTEGER
ODBC::Connection::getAttrInt(SQLINTEGER attr) const
{
SQLINTEGER result;
- SQLINTEGER rc = SQLGetConnectAttr(conn, attr, &result, sizeof(result), 0);
- if (rc != SQL_SUCCESS) {
- throw ODBC::Error(rc, SQL_HANDLE_DBC, conn, "%s", __FUNCTION__);
+ SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, &result, sizeof(result), 0);
+ if (!SQL_SUCCEEDED(dberr)) {
+ throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn, "%s", __FUNCTION__);
}
return result;
}
diff --git a/libodbcpp/modifycommand.cpp b/libodbcpp/modifycommand.cpp
index 45022b0..84979e2 100644
--- a/libodbcpp/modifycommand.cpp
+++ b/libodbcpp/modifycommand.cpp
@@ -17,18 +17,16 @@ ODBC::ModifyCommand::execute(bool anc)
throw Error("Transaction has been aborted, not issuing any more commands");
}
RETCODE rc = SQLExecute(hStmt);
- if (rc != SQL_SUCCESS) {
- if (rc == SQL_SUCCESS_WITH_INFO) {
- // Log info
- }
- else if (rc != SQL_NO_DATA || !anc) {
+ if (!SQL_SUCCEEDED(rc)) {
+ if (rc != SQL_NO_DATA || !anc) {
connection.abortTx();
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLExecute",
__FUNCTION__);
}
}
SQLINTEGER rows;
- if ((rc = SQLRowCount(hStmt, &rows)) != SQL_SUCCESS) {
+ rc = SQLRowCount(hStmt, &rows);
+ if (!SQL_SUCCEEDED(rc)) {
connection.abortTx();
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLRowCount",
__FUNCTION__);
diff --git a/libodbcpp/param.cpp b/libodbcpp/param.cpp
index 3761516..9ccb7c9 100644
--- a/libodbcpp/param.cpp
+++ b/libodbcpp/param.cpp
@@ -47,7 +47,7 @@ ODBC::Param::bind() const
if (!paramBound) {
RETCODE rc = SQLBindParameter(paramCmd->hStmt, paramIdx + 1, SQL_PARAM_INPUT, ctype(), stype(),
size(), dp(), const_cast<void *>(dataAddress()), size(), &bindLen);
- if (rc != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(rc)) {
throw Error(rc, SQL_HANDLE_STMT, paramCmd->hStmt, "%s: Bind for parameter %u",
__FUNCTION__, paramIdx);
}
diff --git a/libodbcpp/selectcommand.cpp b/libodbcpp/selectcommand.cpp
index 177a84e..9df0046 100644
--- a/libodbcpp/selectcommand.cpp
+++ b/libodbcpp/selectcommand.cpp
@@ -18,8 +18,8 @@ ODBC::SelectCommand::~SelectCommand()
}
}
if (columns.size()) {
- RETCODE rc;
- if ((rc = SQLCloseCursor(hStmt)) != SQL_SUCCESS) {
+ RETCODE rc = SQLCloseCursor(hStmt);
+ if (!SQL_SUCCEEDED(rc)) {
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLCloseCursor",
__FUNCTION__);
}
@@ -35,6 +35,7 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
RETCODE rc = SQLFetchScroll(hStmt, orientation, offset);
switch (rc) {
case SQL_SUCCESS:
+ case SQL_SUCCESS_WITH_INFO:
for (Columns::iterator i = columns.begin(); i != columns.end(); i++) {
(*i)->onScroll();
}
@@ -63,15 +64,15 @@ void
ODBC::SelectCommand::execute()
{
RETCODE rc = SQLExecute(hStmt);
- if (rc != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(rc)) {
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLExecute",
__FUNCTION__);
- }
- SQLSMALLINT colCount;
- if ((rc = SQLNumResultCols(hStmt, &colCount)) != SQL_SUCCESS) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLNumResultCols",
- __FUNCTION__);
- }
+ }
+ SQLSMALLINT colCount;
+ if (!SQL_SUCCEEDED(rc = SQLNumResultCols(hStmt, &colCount))) {
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLNumResultCols",
+ __FUNCTION__);
+ }
if (colCount < 1) {
throw Error("%s: No result columns", __FUNCTION__);
}
@@ -81,14 +82,15 @@ ODBC::SelectCommand::execute()
SQLSMALLINT nameLen, dp, nullable, bindType;
SQLUINTEGER bindSize;
int sqlcol = col + 1;
- if ((rc = SQLDescribeCol(hStmt, sqlcol, _colName, sizeof(_colName), &nameLen, &bindType,
- &bindSize, &dp, &nullable)) != SQL_SUCCESS) {
+ if (!SQL_SUCCEEDED(rc = SQLDescribeCol(hStmt, sqlcol, _colName, sizeof(_colName), &nameLen, &bindType,
+ &bindSize, &dp, &nullable))) {
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLDescribeCol for %d",
__FUNCTION__, col);
}
Glib::ustring colName((const char *)_colName, nameLen);
switch (bindType) {
case -9:
+ case -10:
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_LONGVARCHAR: