summaryrefslogtreecommitdiff
path: root/libodbcpp/connection.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-02-09 01:33:33 +0000
committerrandomdan <randomdan@localhost>2011-02-09 01:33:33 +0000
commit6d7c18f1119de8941c7055910e55c13c411eeb92 (patch)
tree9468662e07280c26e29de53f7fdfa228eb62ecde /libodbcpp/connection.cpp
parentAdd missing conversion in generic visitor (diff)
downloadlibdbpp-odbc-6d7c18f1119de8941c7055910e55c13c411eeb92.tar.bz2
libdbpp-odbc-6d7c18f1119de8941c7055910e55c13c411eeb92.tar.xz
libdbpp-odbc-6d7c18f1119de8941c7055910e55c13c411eeb92.zip
Fix the build system to do dependencies properly
Break down libodbcpp into a set of base classes; libdbpp Add a native PostgreSQL implementation of libdbpp; libpqpp Extend project2 rdbms stuff to work with generic connectors Update datasources to specify connector type Build libmisc as .so
Diffstat (limited to 'libodbcpp/connection.cpp')
-rw-r--r--libodbcpp/connection.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/libodbcpp/connection.cpp b/libodbcpp/connection.cpp
index 2624d98..0c2dcc8 100644
--- a/libodbcpp/connection.cpp
+++ b/libodbcpp/connection.cpp
@@ -3,6 +3,8 @@
#include <stdio.h>
#include <string.h>
#include "connection.h"
+#include "selectcommand.h"
+#include "modifycommand.h"
#include "error.h"
ODBC::Connection::Connection(const DSN& d) :
@@ -160,6 +162,18 @@ ODBC::Connection::inTx() const
return (txDepth > 0);
}
+DB::SelectCommand *
+ODBC::Connection::newSelectCommand(const std::string & sql) const
+{
+ return new ODBC::SelectCommand(*this, sql);
+}
+
+DB::ModifyCommand *
+ODBC::Connection::newModifyCommand(const std::string & sql) const
+{
+ return new ODBC::ModifyCommand(*this, sql);
+}
+
std::string
ODBC::Connection::getAttrStr(SQLINTEGER attr) const
{
@@ -168,7 +182,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, "%s", __FUNCTION__);
+ throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn, "ODBC::Connection::getAttrStr SQLGetConnectAttr");
}
rtn.resize(size);
return rtn;
@@ -180,20 +194,29 @@ 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, "%s", __FUNCTION__);
+ throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn, "ODBC::Connection::getAttrInt SQLGetConnectAttr");
}
return result;
}
+void
+ODBC::Connection::ping() const
+{
+ SQLINTEGER dead = getAttrInt(SQL_ATTR_CONNECTION_DEAD);
+ if (dead != SQL_CD_FALSE) {
+ throw ODBC::Error("Connection is dead");
+ }
+}
+
ODBC::ConnectionError::ConnectionError(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * stage) :
- ODBC::Error(err, handletype, handle, "%s", stage),
- FailureTime(time(NULL))
+ ODBC::Error(err, handletype, handle, stage),
+ DB::ConnectionError()
{
}
ODBC::ConnectionError::ConnectionError(const ConnectionError & e) :
ODBC::Error(strdup(e.what())),
- FailureTime(e.FailureTime)
+ DB::ConnectionError(e.FailureTime)
{
}