summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-07-05 15:13:40 +0000
committerrandomdan <randomdan@localhost>2010-07-05 15:13:40 +0000
commit033b3a170b6007e2b954940fb4f4779e50cee012 (patch)
tree3a120822928c3230cca52dea5922cc26a29c2ea5
parentUse cgicc, add checks, tasks, dynamic loader, atom feed, login page (diff)
downloadlibdbpp-odbc-033b3a170b6007e2b954940fb4f4779e50cee012.tar.bz2
libdbpp-odbc-033b3a170b6007e2b954940fb4f4779e50cee012.tar.xz
libdbpp-odbc-033b3a170b6007e2b954940fb4f4779e50cee012.zip
Implement connection caching and checking (requires ODBCv3 driver)
Implement preferLocal DB access
-rw-r--r--libodbcpp/connection.cpp26
-rw-r--r--libodbcpp/connection.h3
2 files changed, 28 insertions, 1 deletions
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 <sqlext.h>
#include <syslog.h>
+#include <pcap.h>
#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;