summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libodbcpp/Jamfile.jam15
-rw-r--r--libodbcpp/column.cpp23
-rw-r--r--libodbcpp/column.h31
-rw-r--r--libodbcpp/command.cpp2
-rw-r--r--libodbcpp/command.h4
-rw-r--r--libodbcpp/connection.cpp33
-rw-r--r--libodbcpp/connection.h16
-rw-r--r--libodbcpp/error.cpp31
-rw-r--r--libodbcpp/error.h9
-rw-r--r--libodbcpp/modifycommand.cpp12
-rw-r--r--libodbcpp/modifycommand.h3
-rw-r--r--libodbcpp/param.cpp5
-rw-r--r--libodbcpp/selectcommand.cpp37
-rw-r--r--libodbcpp/selectcommand.h10
14 files changed, 120 insertions, 111 deletions
diff --git a/libodbcpp/Jamfile.jam b/libodbcpp/Jamfile.jam
index a590ca5..983cba5 100644
--- a/libodbcpp/Jamfile.jam
+++ b/libodbcpp/Jamfile.jam
@@ -3,14 +3,15 @@ alias glibmm : : : :
<linkflags>"`pkg-config --libs glibmm-2.4`"
;
-project
- : usage-requirements
- <include>.
- : requirements
- <library>glibmm
- ;
+lib odbc : : <name>odbc ;
lib odbcpp :
[ glob *.cpp ] :
<cflags>-fPIC
- <link>static ;
+ <library>glibmm
+ <library>odbc
+ : :
+ <include>.
+ <library>glibmm
+ <library>../libdbpp
+ ;
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 4101b0f..13c5ee1 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -6,9 +6,8 @@
#include "selectcommand.h"
#include "error.h"
-ODBC::Column::Column(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
- colNo(i),
- name(n),
+ODBC::Column::Column(SelectCommand * sc, const Glib::ustring & s, unsigned int i) :
+ DB::Column(s, i),
selectCmd(sc)
{
bindLen = 0;
@@ -48,9 +47,9 @@ ODBC::Column::isNull() const
}
void
-ODBC::Column::rebind(Command * cmd, unsigned int idx) const
+ODBC::Column::rebind(DB::Command * cmd, unsigned int idx) const
{
- meAsAParam()->paramCmd = cmd;
+ meAsAParam()->paramCmd = dynamic_cast<ODBC::Command *>(cmd);
meAsAParam()->paramIdx = idx;
meAsAParam()->bind();
}
@@ -60,7 +59,7 @@ ODBC::Column::bind()
{
RETCODE rc = SQLBindCol(selectCmd->hStmt, colNo + 1, ctype(), rwDataAddress(), size(), &bindLen);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, selectCmd->hStmt, "%s: Bind column %u", __FUNCTION__, colNo);
+ throw Error(rc, SQL_HANDLE_STMT, selectCmd->hStmt, "ODBC::Column::bind");
}
}
@@ -91,26 +90,26 @@ void operator << (struct tm & target, const SQL_TIMESTAMP_STRUCT & src)
}
void
-ODBC::SignedIntegerColumn::apply(ODBC::HandleField & h) const
+ODBC::SignedIntegerColumn::apply(DB::HandleField & h) const
{
if (isNull()) return h.null();
h.integer(data);
}
void
-ODBC::FloatingPointColumn::apply(ODBC::HandleField & h) const
+ODBC::FloatingPointColumn::apply(DB::HandleField & h) const
{
if (isNull()) return h.null();
h.floatingpoint(data);
}
void
-ODBC::CharArrayColumn::apply(ODBC::HandleField & h) const
+ODBC::CharArrayColumn::apply(DB::HandleField & h) const
{
if (isNull()) return h.null();
- h.string(data, bindLen);
+ h.string(&data.front(), bindLen);
}
void
-ODBC::TimeStampColumn::apply(ODBC::HandleField & h) const
+ODBC::TimeStampColumn::apply(DB::HandleField & h) const
{
if (isNull()) return h.null();
- h.timestamp(data);
+ h.timestamp(*this);
}
diff --git a/libodbcpp/column.h b/libodbcpp/column.h
index 0b2f95f..71118f8 100644
--- a/libodbcpp/column.h
+++ b/libodbcpp/column.h
@@ -1,6 +1,7 @@
#ifndef ODBC_COLUMN_H
#define ODBC_COLUMN_H
+#include "../libdbpp/column.h"
#include <typeinfo>
#include <glibmm/ustring.h>
#include "bind.h"
@@ -8,21 +9,13 @@
namespace ODBC {
class SelectCommand;
- class HandleField {
+ class Column : public virtual Bind, public virtual DB::Column {
public:
- virtual void null() = 0;
- virtual void string(const std::vector<char> &, size_t len) = 0;
- virtual void integer(SQLINTEGER) = 0;
- virtual void floatingpoint(SQLDOUBLE) = 0;
- virtual void timestamp(const SQL_TIMESTAMP_STRUCT &) = 0;
- };
- class Column : public virtual Bind {
- public:
- Column(SelectCommand *, const Glib::ustring &, unsigned int);
+ Column(SelectCommand *, const Glib::ustring & s, unsigned int i);
virtual ~Column() = 0;
void bind();
virtual void * rwDataAddress() = 0;
- void rebind(Command *, unsigned int idx) const;
+ void rebind(DB::Command *, unsigned int idx) const;
virtual void resize(SQLHANDLE);
virtual void onScroll();
@@ -43,10 +36,8 @@ namespace ODBC {
virtual operator SQL_TIMESTAMP_STRUCT () const { throw std::bad_cast(); }
bool isNull() const;
- virtual void apply(HandleField &) const = 0;
+ virtual void apply(DB::HandleField &) const = 0;
- const unsigned int colNo;
- const Glib::ustring name;
const SelectCommand * selectCmd;
protected:
virtual const Param * meAsAParam() const = 0;
@@ -55,6 +46,7 @@ namespace ODBC {
public:
typedef std::vector<char> CharArray;
CharArrayColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
+ DB::Column(n, i),
Column(sc, n, i)
{
data.resize(256);
@@ -69,7 +61,7 @@ namespace ODBC {
void resize(SQLHANDLE);
virtual operator std::string () const { return std::string(&data.front(), bindLen); }
virtual operator Glib::ustring () const { return std::string(&data.front(), bindLen); }
- virtual void apply(HandleField &) const;
+ virtual void apply(DB::HandleField &) const;
protected:
virtual const Param * meAsAParam() const { return this; }
CharArray data;
@@ -77,6 +69,7 @@ namespace ODBC {
class SignedIntegerColumn : public Column, public SignedIntegerParam {
public:
SignedIntegerColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
+ DB::Column(n, i),
Column(sc, n, i) { }
virtual SQLSMALLINT ctype() const { return SignedIntegerParam::ctype(); }
virtual SQLULEN size() const { return SignedIntegerParam::size(); }
@@ -85,7 +78,7 @@ namespace ODBC {
virtual operator long () const { return data; }
virtual operator long long () const { return data; }
virtual const Param * meAsAParam() const { return this; }
- virtual void apply(HandleField &) const;
+ virtual void apply(DB::HandleField &) const;
};
#ifdef COMPLETENESS
class UnsignedIntegerColumn : public Column, public UnsignedIntegerParam {
@@ -98,6 +91,7 @@ namespace ODBC {
class FloatingPointColumn : public Column, public FloatingPointParam {
public:
FloatingPointColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
+ DB::Column(n, i),
Column(sc, n, i) { }
virtual SQLSMALLINT ctype() const { return FloatingPointParam::ctype(); }
virtual SQLULEN size() const { return FloatingPointParam::size(); }
@@ -105,11 +99,12 @@ namespace ODBC {
virtual operator double () const { return data; }
virtual operator float () const { return data; }
virtual const Param * meAsAParam() const { return this; }
- virtual void apply(HandleField &) const;
+ virtual void apply(DB::HandleField &) const;
};
class TimeStampColumn : public Column, public TimeStampParam {
public:
TimeStampColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
+ DB::Column(n, i),
Column(sc, n, i) { }
virtual SQLSMALLINT ctype() const { return TimeStampParam::ctype(); }
virtual SQLULEN size() const { return TimeStampParam::size(); }
@@ -117,7 +112,7 @@ namespace ODBC {
virtual operator struct tm () const;
virtual operator SQL_TIMESTAMP_STRUCT () const { return data; }
virtual const Param * meAsAParam() const { return this; }
- virtual void apply(HandleField &) const;
+ virtual void apply(DB::HandleField &) const;
};
}
diff --git a/libodbcpp/command.cpp b/libodbcpp/command.cpp
index db6a51c..0e100c0 100644
--- a/libodbcpp/command.cpp
+++ b/libodbcpp/command.cpp
@@ -4,7 +4,7 @@
#include <sqlext.h>
ODBC::Command::Command(const Connection & c, const std::string & s) :
- sql(s),
+ DB::Command(s),
connection(c)
{
RETCODE rc = SQLAllocHandle(SQL_HANDLE_STMT, c.conn, &hStmt);
diff --git a/libodbcpp/command.h b/libodbcpp/command.h
index 1bc9f6d..fdabe4a 100644
--- a/libodbcpp/command.h
+++ b/libodbcpp/command.h
@@ -1,13 +1,14 @@
#ifndef ODBC_COMMAND_H
#define ODBC_COMMAND_H
+#include "../libdbpp/command.h"
#include <vector>
#include "connection.h"
#include <glibmm/ustring.h>
namespace ODBC {
class Param;
- class Command {
+ class Command : public virtual DB::Command {
typedef std::vector<Param*> Params;
public:
Command(const Connection &, const std::string & sql);
@@ -31,7 +32,6 @@ namespace ODBC {
void bindNull(unsigned int i);
- const std::string sql;
protected:
friend class Param;
friend class Column;
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)
{
}
diff --git a/libodbcpp/connection.h b/libodbcpp/connection.h
index 86ff7d8..d37b679 100644
--- a/libodbcpp/connection.h
+++ b/libodbcpp/connection.h
@@ -1,12 +1,14 @@
-#ifndef CONNECTION_H
-#define CONNECTION_H
+#ifndef ODBC_CONNECTION_H
+#define ODBC_CONNECTION_H
+#include "../libdbpp/connection.h"
+#include "../libdbpp/error.h"
#include "dsn.h"
#include "error.h"
#include <sql.h>
namespace ODBC {
- class Connection {
+ class Connection : public DB::Connection {
public:
Connection(const DSN& d);
Connection(const std::string & str);
@@ -20,21 +22,23 @@ namespace ODBC {
void abortTx() const;
bool txIsAborted() const;
bool inTx() const;
+ void ping() const;
std::string getAttrStr(SQLINTEGER) const;
SQLINTEGER getAttrInt(SQLINTEGER) const;
+ DB::SelectCommand * newSelectCommand(const std::string & sql) const;
+ DB::ModifyCommand * newModifyCommand(const std::string & sql) const;
+
private:
void connectPre();
void connectPost();
mutable unsigned int txDepth;
mutable bool txAborted;
};
- class ConnectionError : public Error {
+ class ConnectionError : public DB::ConnectionError, public virtual Error {
public:
ConnectionError(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * stage);
ConnectionError(const ConnectionError &);
-
- const time_t FailureTime;
};
}
diff --git a/libodbcpp/error.cpp b/libodbcpp/error.cpp
index 51b90c6..e971714 100644
--- a/libodbcpp/error.cpp
+++ b/libodbcpp/error.cpp
@@ -3,23 +3,17 @@
#include <syslog.h>
#include <malloc.h>
#include <time.h>
+#include <string.h>
#include "error.h"
static
void
-odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * actionfmt, va_list ap, char ** msg)
+odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action, char ** msg)
{
SQLCHAR sqlstatus[6];
SQLINTEGER sqlerr;
SQLCHAR sqlerrmsg[12800];
- char * action;
- if (vasprintf(&action, actionfmt, ap) < 0) {
- syslog(LOG_WARNING, "%s: %d: %ld: %5.5s: \"%s\" : failed to malloc for vasprintf",
- __FUNCTION__, err, sqlerr, sqlstatus, sqlerrmsg);
- return;
- }
-
SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg,
sizeof(sqlerrmsg), NULL);
switch (rc) {
@@ -62,28 +56,17 @@ odbc_verror(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const *
syslog(LOG_ERR, "%s: Unexpected error!!", __FUNCTION__);
break;
}
- free(action);
}
-ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action, ...)
+ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action)
{
- va_list ap;
-
- va_start(ap, action);
- odbc_verror(err, handletype, handle, action, ap, &msg);
- va_end(ap);
+ odbc_verror(err, handletype, handle, action, &msg);
}
-ODBC::Error::Error(char const * action, ...)
+ODBC::Error::Error(char const * action)
{
- va_list ap;
-
- va_start(ap, action);
- vsyslog(LOG_ERR, action, ap);
- if (vasprintf(&msg, action, ap) < 1) {
- msg = NULL;
- }
- va_end(ap);
+ syslog(LOG_ERR, "%s", action);
+ msg = strdup(action);
}
ODBC::Error::Error(char * m) : msg(m)
diff --git a/libodbcpp/error.h b/libodbcpp/error.h
index 73fa3bc..f3a2f79 100644
--- a/libodbcpp/error.h
+++ b/libodbcpp/error.h
@@ -4,14 +4,13 @@
#include <sql.h>
#include <stdlib.h>
#include <exception>
+#include "../libdbpp/error.h"
namespace ODBC {
- class Error : public std::exception {
+ class Error : public DB::Error {
public:
- Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action, ...)
- __attribute__((format(printf, 5, 6)));
- Error(char const * action, ...)
- __attribute__((format(printf, 2, 3)));
+ Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle, char const * action);
+ Error(char const * action);
~Error() throw();
const char * what() const throw();
diff --git a/libodbcpp/modifycommand.cpp b/libodbcpp/modifycommand.cpp
index a12b9dc..7a39be5 100644
--- a/libodbcpp/modifycommand.cpp
+++ b/libodbcpp/modifycommand.cpp
@@ -2,7 +2,9 @@
#include "error.h"
ODBC::ModifyCommand::ModifyCommand(const ODBC::Connection & c, const std::string & sql) :
- Command(c, sql)
+ DB::Command(sql),
+ ODBC::Command(c, sql),
+ DB::ModifyCommand(sql)
{
}
@@ -20,21 +22,19 @@ ODBC::ModifyCommand::execute(bool anc)
if (!SQL_SUCCEEDED(rc)) {
if (rc != SQL_NO_DATA || !anc) {
connection.abortTx();
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLExecute",
- __FUNCTION__);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::ModifyCommand::execute SQLExecute");
}
}
SQLLEN rows;
rc = SQLRowCount(hStmt, &rows);
if (!SQL_SUCCEEDED(rc)) {
connection.abortTx();
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLRowCount",
- __FUNCTION__);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::ModifyCommand::execute SQLRowCount");
}
if (rows > 0 || anc) {
return rows;
}
connection.abortTx();
- throw Error("%s: No rows affected", __FUNCTION__);
+ throw Error("No rows affected");
}
diff --git a/libodbcpp/modifycommand.h b/libodbcpp/modifycommand.h
index e833518..df7478a 100644
--- a/libodbcpp/modifycommand.h
+++ b/libodbcpp/modifycommand.h
@@ -1,10 +1,11 @@
#ifndef ODBC_MODIFYCOMMAND_H
#define ODBC_MODIFYCOMMAND_H
+#include "../libdbpp/modifycommand.h"
#include "command.h"
namespace ODBC {
- class ModifyCommand : public Command {
+ class ModifyCommand : public Command, public DB::ModifyCommand {
public:
ModifyCommand(const Connection &, const std::string & sql);
~ModifyCommand();
diff --git a/libodbcpp/param.cpp b/libodbcpp/param.cpp
index 91fc9e8..7f2319c 100644
--- a/libodbcpp/param.cpp
+++ b/libodbcpp/param.cpp
@@ -26,7 +26,7 @@ ParamType *
ODBC::Command::makeParam(unsigned int idx)
{
if (idx >= params.size()) {
- throw Error("%s: Bind out of bounds", __FUNCTION__);
+ throw Error("ODBC::Command::makeParam Bind out of bounds");
}
Param * & p = params[idx];
if (p) {
@@ -48,8 +48,7 @@ ODBC::Param::bind() const
RETCODE rc = SQLBindParameter(paramCmd->hStmt, paramIdx + 1, SQL_PARAM_INPUT, ctype(), stype(),
size(), dp(), const_cast<void *>(dataAddress()), size(), &bindLen);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, paramCmd->hStmt, "%s: Bind for parameter %u",
- __FUNCTION__, paramIdx);
+ throw Error(rc, SQL_HANDLE_STMT, paramCmd->hStmt, "ODBC::Param::bind Bind parameter");
}
paramBound = true;
}
diff --git a/libodbcpp/selectcommand.cpp b/libodbcpp/selectcommand.cpp
index a297f75..2153862 100644
--- a/libodbcpp/selectcommand.cpp
+++ b/libodbcpp/selectcommand.cpp
@@ -6,7 +6,9 @@
#include <string.h>
ODBC::SelectCommand::SelectCommand(const Connection & c, const std::string & s) :
- Command(c, s)
+ DB::Command(s),
+ ODBC::Command(c, s),
+ DB::SelectCommand(s)
{
}
@@ -20,13 +22,18 @@ ODBC::SelectCommand::~SelectCommand()
if (columns.size()) {
RETCODE rc = SQLCloseCursor(hStmt);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLCloseCursor",
- __FUNCTION__);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::~SelectCommand SQLCloseCursor");
}
}
}
bool
+ODBC::SelectCommand::fetch()
+{
+ return fetch(SQL_FETCH_NEXT, 0);
+}
+
+bool
ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
{
if (columns.size() == 0) {
@@ -55,8 +62,7 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
}
}
}
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLFetch",
- __FUNCTION__);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::fetch SQLFetch");
}
}
@@ -65,16 +71,14 @@ ODBC::SelectCommand::execute()
{
RETCODE rc = SQLExecute(hStmt);
if (!SQL_SUCCEEDED(rc)) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLExecute",
- __FUNCTION__);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::execute SQLExecute");
}
SQLSMALLINT colCount;
if (!SQL_SUCCEEDED(rc = SQLNumResultCols(hStmt, &colCount))) {
- throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLNumResultCols",
- __FUNCTION__);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::execute SQLNumResultCols");
}
if (colCount < 1) {
- throw Error("%s: No result columns", __FUNCTION__);
+ throw Error("ODBC::SelectCommand::execute No result columns");
}
columns.resize(colCount);
for (int col = 0; col < colCount; col++) {
@@ -84,8 +88,7 @@ ODBC::SelectCommand::execute()
int sqlcol = col + 1;
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);
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "ODBC::SelectCommand::execute SQLDescribeCol for %d");
}
Glib::ustring colName((const char *)_colName, nameLen);
switch (bindType) {
@@ -118,16 +121,16 @@ ODBC::SelectCommand::execute()
}
-const ODBC::Column&
+const DB::Column&
ODBC::SelectCommand::operator[](unsigned int col) const
{
if (col > columns.size()) {
- throw ODBC::Error("Column index (%u) out of range", col);
+ throw ODBC::Error("Column index out of range");
}
return *columns[col];
}
-const ODBC::Column&
+const DB::Column&
ODBC::SelectCommand::operator[](const Glib::ustring & colName) const
{
for (Columns::const_iterator col = columns.begin(); col != columns.end(); col++) {
@@ -135,7 +138,7 @@ ODBC::SelectCommand::operator[](const Glib::ustring & colName) const
return **col;
}
}
- throw ODBC::Error("Column (%s) does not exist", colName.c_str());
+ throw ODBC::Error("Column does not exist");
}
unsigned int
@@ -148,7 +151,7 @@ ODBC::SelectCommand::getOrdinal(const Glib::ustring & colName) const
}
n += 1;
}
- throw ODBC::Error("Column (%s) does not exist", colName.c_str());
+ throw ODBC::Error("Column does not exist");
}
unsigned int
diff --git a/libodbcpp/selectcommand.h b/libodbcpp/selectcommand.h
index a0cd6e1..81f3ea9 100644
--- a/libodbcpp/selectcommand.h
+++ b/libodbcpp/selectcommand.h
@@ -1,22 +1,24 @@
#ifndef ODBC_SELECTCOMMAND_H
#define ODBC_SELECTCOMMAND_H
+#include "../libdbpp/selectcommand.h"
#include "command.h"
namespace ODBC {
class Column;
- class SelectCommand : public Command {
+ class SelectCommand : public Command, public DB::SelectCommand {
typedef std::vector<Column*> Columns;
public:
SelectCommand (const Connection &, const std::string & sql);
~SelectCommand();
- bool fetch(SQLSMALLINT orientation = SQL_FETCH_NEXT, SQLLEN offset = 0);
+ bool fetch();
void execute();
- const Column & operator[](unsigned int col) const;
- const Column & operator[](const Glib::ustring &) const;
+ const DB::Column & operator[](unsigned int col) const;
+ const DB::Column & operator[](const Glib::ustring &) const;
unsigned int columnCount() const;
unsigned int getOrdinal(const Glib::ustring &) const;
private:
+ bool fetch(SQLSMALLINT orientation = SQL_FETCH_NEXT, SQLLEN offset = 0);
Columns columns;
};
}