summaryrefslogtreecommitdiff
path: root/libodbcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libodbcpp')
-rw-r--r--libodbcpp/column.cpp30
-rw-r--r--libodbcpp/column.h6
-rw-r--r--libodbcpp/selectcommand.cpp4
3 files changed, 30 insertions, 10 deletions
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 31e9642..6f45617 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -7,12 +7,14 @@
ODBC::Column::Column(const Glib::ustring & n, unsigned int i) :
colNo(i),
name(n),
+ composeCache(NULL),
bindSize(0)
{
}
ODBC::Column::~Column()
{
+ delete composeCache;
}
bool
@@ -91,10 +93,13 @@ namespace ODBC {
return writeToBuf(buf, "%g");
}
template <>
- Glib::ustring
+ const Glib::ustring &
_Column<SQLDOUBLE>::compose() const
{
- return Glib::ustring::compose("%1", value);
+ if (!composeCache) {
+ composeCache = new Glib::ustring(Glib::ustring::compose("%1", value));
+ }
+ return *composeCache;
}
template <>
Glib::ustring
@@ -115,10 +120,13 @@ namespace ODBC {
return writeToBuf(buf, "%ld");
}
template <>
- Glib::ustring
+ const Glib::ustring &
_Column<SQLINTEGER>::compose() const
{
- return Glib::ustring::compose("%1", value);
+ if (!composeCache) {
+ composeCache = new Glib::ustring(Glib::ustring::compose("%1", value));
+ }
+ return *composeCache;
}
template <>
Glib::ustring
@@ -139,10 +147,13 @@ namespace ODBC {
return writeToBuf(buf, "%s");
}
template <>
- Glib::ustring
+ const Glib::ustring &
_Column<SQLCHAR*>::compose() const
{
- return Glib::ustring((const char *)value);
+ if (!composeCache) {
+ composeCache = new Glib::ustring((const char *)value);
+ }
+ return *composeCache;
}
template <>
Glib::ustring
@@ -176,10 +187,13 @@ namespace ODBC {
return Glib::ustring(buf, len);
}
template <>
- Glib::ustring
+ const Glib::ustring &
_Column<SQL_TIMESTAMP_STRUCT>::compose() const
{
- return compose("%F %T");
+ if (!composeCache) {
+ composeCache = new Glib::ustring(Glib::ustring(compose("%F %T")));
+ }
+ return *composeCache;
}
}
diff --git a/libodbcpp/column.h b/libodbcpp/column.h
index 3b3370f..67dd0c4 100644
--- a/libodbcpp/column.h
+++ b/libodbcpp/column.h
@@ -22,7 +22,7 @@ namespace ODBC {
operator Glib::ustring () const;
operator struct tm () const;
virtual void rebind(Command *, unsigned int col) const = 0;
- virtual Glib::ustring compose() const = 0;
+ virtual const Glib::ustring & compose() const = 0;
virtual Glib::ustring compose(const Glib::ustring & fmt) const = 0;
virtual int writeToBuf(char ** buf) const = 0;
virtual int writeToBuf(char ** buf, const char * fmt) const = 0;
@@ -30,6 +30,8 @@ namespace ODBC {
const unsigned int colNo;
const Glib::ustring name;
+ protected:
+ mutable Glib::ustring * composeCache;
private:
SQLUINTEGER bindSize; // Allocated memory
friend class SelectCommand;
@@ -40,7 +42,7 @@ namespace ODBC {
_Column(const Glib::ustring &, unsigned int);
~_Column() {}
void rebind(Command *, unsigned int col) const;
- Glib::ustring compose() const;
+ const Glib::ustring & compose() const;
Glib::ustring compose(const Glib::ustring & fmt) const;
int writeToBuf(char ** buf) const;
int writeToBuf(char ** buf, const char * fmt) const;
diff --git a/libodbcpp/selectcommand.cpp b/libodbcpp/selectcommand.cpp
index a1a5531..97102ab 100644
--- a/libodbcpp/selectcommand.cpp
+++ b/libodbcpp/selectcommand.cpp
@@ -34,6 +34,10 @@ ODBC::SelectCommand::fetch()
RETCODE rc = SQLFetch(hStmt);
switch (rc) {
case SQL_SUCCESS:
+ for (Columns::iterator i = columns.begin(); i != columns.end(); i++) {
+ delete (*i)->composeCache;
+ (*i)->composeCache = NULL;
+ }
return true;
case SQL_NO_DATA:
return false;