From 6d7c18f1119de8941c7055910e55c13c411eeb92 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 9 Feb 2011 01:33:33 +0000 Subject: 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 --- libodbcpp/connection.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'libodbcpp/connection.cpp') 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 #include #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) { } -- cgit v1.2.3