summaryrefslogtreecommitdiff
path: root/libodbcpp/column.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-08-05 23:48:05 +0000
committerrandomdan <randomdan@localhost>2010-08-05 23:48:05 +0000
commitfd27b85b004ad13c4139d84a287fd3f3ef444c4b (patch)
treecd089ac1c4f2c93a2ee2911db07f49aa096a83f8 /libodbcpp/column.cpp
parentFix behaviour of composing a string column (diff)
downloadlibdbpp-odbc-fd27b85b004ad13c4139d84a287fd3f3ef444c4b.tar.bz2
libdbpp-odbc-fd27b85b004ad13c4139d84a287fd3f3ef444c4b.tar.xz
libdbpp-odbc-fd27b85b004ad13c4139d84a287fd3f3ef444c4b.zip
Cache the result of default column compose
Use this cache now lots of things are const refs
Diffstat (limited to 'libodbcpp/column.cpp')
-rw-r--r--libodbcpp/column.cpp30
1 files changed, 22 insertions, 8 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;
}
}