From 033b3a170b6007e2b954940fb4f4779e50cee012 Mon Sep 17 00:00:00 2001 From: randomdan Date: Mon, 5 Jul 2010 15:13:40 +0000 Subject: Implement connection caching and checking (requires ODBCv3 driver) Implement preferLocal DB access --- libodbcpp/connection.cpp | 26 +++++++++++++++++++++++++- libodbcpp/connection.h | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libodbcpp/connection.cpp b/libodbcpp/connection.cpp index 6adcf09..03bf813 100644 --- a/libodbcpp/connection.cpp +++ b/libodbcpp/connection.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "connection.h" #include "error.h" @@ -52,7 +53,7 @@ ODBC::Connection::Connection(const std::string & s) : throw Error(dberr, SQL_HANDLE_ENV, env, "Allocate handle"); } - dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC2, 0); + dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); if ((dberr != SQL_SUCCESS)) { throw Error(dberr, SQL_HANDLE_ENV, env, "Set ODBC version"); } @@ -171,3 +172,26 @@ ODBC::Connection::inTx() const return (txDepth > 0); } +std::string +ODBC::Connection::getAttrStr(SQLINTEGER attr) const +{ + unsigned char buf[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__); + } + return std::string((const char *)buf, size); +} + +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__); + } + return result; +} + diff --git a/libodbcpp/connection.h b/libodbcpp/connection.h index b89a5f9..82caf22 100644 --- a/libodbcpp/connection.h +++ b/libodbcpp/connection.h @@ -19,6 +19,9 @@ namespace ODBC { void abortTx() const; bool txIsAborted() const; bool inTx() const; + std::string getAttrStr(SQLINTEGER) const; + SQLINTEGER getAttrInt(SQLINTEGER) const; + private: mutable unsigned int txDepth; mutable bool txAborted; -- cgit v1.2.3