summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libodbcpp/bind.cpp7
-rw-r--r--libodbcpp/bind.h10
-rw-r--r--libodbcpp/column.cpp23
-rw-r--r--libodbcpp/command.h6
-rw-r--r--libodbcpp/param.cpp26
-rw-r--r--libodbcpp/selectcommand.cpp6
6 files changed, 26 insertions, 52 deletions
diff --git a/libodbcpp/bind.cpp b/libodbcpp/bind.cpp
index 2e40975..07e9d35 100644
--- a/libodbcpp/bind.cpp
+++ b/libodbcpp/bind.cpp
@@ -7,11 +7,4 @@ ODBC::BindBase::BindBase() :
{
}
-ODBC::Bind<unsigned char *>::~Bind()
-{
- if (value) {
- delete[] value;
- }
-}
-
diff --git a/libodbcpp/bind.h b/libodbcpp/bind.h
index 7dfbf34..5baa53a 100644
--- a/libodbcpp/bind.h
+++ b/libodbcpp/bind.h
@@ -2,6 +2,7 @@
#define ODBC_BIND_H
#include <sql.h>
+#include <vector>
namespace ODBC {
class Command;
@@ -19,13 +20,14 @@ namespace ODBC {
class Bind {
public:
virtual ~Bind() {}
- t value;
+ mutable t value;
};
+ typedef std::vector<char> SQLCHARVEC;
template <>
- class Bind<unsigned char*> {
+ class Bind<SQLCHARVEC> {
public:
- virtual ~Bind();
- unsigned char * value;
+ virtual ~Bind() {}
+ mutable SQLCHARVEC value;
};
}
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 8237535..6e517a6 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -34,7 +34,6 @@ ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, long long);
ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, int);
ODBC_DEFAULT_COLUMN_CAST(SQLDOUBLE, double);
ODBC_DEFAULT_COLUMN_CAST(SQLDOUBLE, float);
-ODBC_DEFAULT_COLUMN_CAST(SQLCHAR*, const unsigned char *);
ODBC::Column::operator Glib::ustring() const {
return Glib::ustring((const char *)((dynamic_cast<const _Column<SQLCHAR*>& >(*this)).value));
}
@@ -75,11 +74,13 @@ namespace ODBC {
REBIND(double, bindParamF)
REBIND(float, bindParamF)
REBIND(SQL_TIMESTAMP_STRUCT, bindParamT)
- template<> void _Column<unsigned char *>::rebind(Command * cmd, unsigned int col) const \
+
+ template<>
+ void
+ _Column<SQLCHARVEC>::rebind(Command * cmd, unsigned int col) const \
{
- cmd->bindParamS(col, (const char *)value);
+ cmd->bindParamS(col, &value[0]);
}
-
template <>
int
_Column<SQLDOUBLE>::writeToBuf(char ** buf, const char * fmt) const
@@ -136,30 +137,30 @@ namespace ODBC {
}
template <>
int
- _Column<SQLCHAR*>::writeToBuf(char ** buf, const char * fmt) const
+ _Column<SQLCHARVEC>::writeToBuf(char ** buf, const char * fmt) const
{
- return asprintf(buf, fmt, value);
+ return asprintf(buf, fmt, &value[0]);
}
template <>
int
- _Column<SQLCHAR*>::writeToBuf(char ** buf) const
+ _Column<SQLCHARVEC>::writeToBuf(char ** buf) const
{
return writeToBuf(buf, "%s");
}
template <>
const Glib::ustring &
- _Column<SQLCHAR*>::compose() const
+ _Column<SQLCHARVEC>::compose() const
{
if (!composeCache) {
- composeCache = new Glib::ustring((const char *)value);
+ composeCache = new Glib::ustring((const char *)&value[0]);
}
return *composeCache;
}
template <>
Glib::ustring
- _Column<SQLCHAR*>::compose(const Glib::ustring & fmt) const
+ _Column<SQLCHARVEC>::compose(const Glib::ustring & fmt) const
{
- return Glib::ustring::compose(fmt, value);
+ return Glib::ustring::compose(fmt, &value[0]);
}
template <>
int
diff --git a/libodbcpp/command.h b/libodbcpp/command.h
index 1348441..830f573 100644
--- a/libodbcpp/command.h
+++ b/libodbcpp/command.h
@@ -18,12 +18,12 @@ namespace ODBC {
void bindParamI(unsigned int i, unsigned int val);
void bindParamI(unsigned int i, long unsigned int val);
void bindParamI(unsigned int i, long long unsigned int val);
+
void bindParamF(unsigned int i, double val);
void bindParamF(unsigned int i, float val);
- void bindParamS(unsigned int i, const char *);
- void bindParamS(unsigned int i, const char *, size_t);
- void bindParamS(unsigned int i, const std::string &);
+
void bindParamS(unsigned int i, const Glib::ustring &);
+
void bindParamT(unsigned int i, const struct tm *);
void bindParamT(unsigned int i, const SQL_TIMESTAMP_STRUCT &);
void bindParamT(unsigned int i, time_t);
diff --git a/libodbcpp/param.cpp b/libodbcpp/param.cpp
index c4d2223..ff10d3a 100644
--- a/libodbcpp/param.cpp
+++ b/libodbcpp/param.cpp
@@ -31,10 +31,10 @@ ODBC::Param::makeParam(ODBC::Param*& p)
void
ODBC::Param::bind(SQLHANDLE hStmt, SQLUINTEGER col, SQLSMALLINT ctype, SQLSMALLINT stype,
- SQLINTEGER colsize, SQLINTEGER dp, const void* value, size_t buflen)
+ SQLINTEGER colsize, SQLINTEGER dp, const void * value, size_t buflen)
{
RETCODE rc = SQLBindParameter(hStmt, col, SQL_PARAM_INPUT, ctype, stype,
- colsize, dp, (void*)value, buflen, &bindLen);
+ colsize, dp, const_cast<void*>(value), buflen, &bindLen);
if (rc != SQL_SUCCESS) {
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: Bind for column %lu",
__FUNCTION__, col);
@@ -114,18 +114,6 @@ ODBC::Command::bindParamS(unsigned int i, const Glib::ustring & val)
throw Error("%s: Bind out of bounds", __FUNCTION__);
}
void
-ODBC::Command::bindParamS(unsigned int i, const char * val, size_t len)
-{
- if (i < params.size()) {
- _Param<Glib::ustring>* p = Param::makeParam<Glib::ustring>(params[i]);
- p->value.assign(val);
- p->bindLen = len;
- p->bind(this->hStmt, i + 1, SQL_C_CHAR, SQL_CHAR, 0, 0, p->value.data(), p->value.bytes());
- return;
- }
- throw Error("%s: Bind out of bounds", __FUNCTION__);
-}
-void
ODBC::Command::bindParamT(unsigned int i, const struct tm * val)
{
if (i < params.size()) {
@@ -171,16 +159,6 @@ ODBC::Command::bindParamI(unsigned int i, unsigned int val)
bindParamI(i, (long long unsigned int)val);
}
void
-ODBC::Command::bindParamS(unsigned int i, const char * val)
-{
- bindParamS(i, val, strlen(val));
-}
-void
-ODBC::Command::bindParamS(unsigned int i, const std::string & val)
-{
- bindParamS(i, val.c_str(), val.length());
-}
-void
ODBC::Command::bindParamF(unsigned int i, float val)
{
bindParamF(i, (double)val);
diff --git a/libodbcpp/selectcommand.cpp b/libodbcpp/selectcommand.cpp
index 97102ab..88a071f 100644
--- a/libodbcpp/selectcommand.cpp
+++ b/libodbcpp/selectcommand.cpp
@@ -87,9 +87,9 @@ ODBC::SelectCommand::execute()
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
{
- _Column<SQLCHAR*>* s = new _Column<SQLCHAR*>(colName, col);
- s->value = new SQLCHAR[bindSize + 1];
- s->bind(hStmt, sqlcol, SQL_C_CHAR, s->value, bindSize + 1);
+ _Column<SQLCHARVEC>* s = new _Column<SQLCHARVEC>(colName, col);
+ s->value.resize(bindSize + 1);
+ s->bind(hStmt, sqlcol, SQL_C_CHAR, &s->value[0], bindSize + 1);
columns[col] = s;
break;
}