summaryrefslogtreecommitdiff
path: root/libodbcpp/column.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-06-13 15:25:33 +0000
committerrandomdan <randomdan@localhost>2010-06-13 15:25:33 +0000
commit89ddd6821bb7ecb0c29077ea427df0cd86017e38 (patch)
tree3a370c705e0b84033042dd708426516d088a66ee /libodbcpp/column.cpp
parentFix odbc select destructor when cursor not opened (diff)
downloadlibdbpp-odbc-89ddd6821bb7ecb0c29077ea427df0cd86017e38.tar.bz2
libdbpp-odbc-89ddd6821bb7ecb0c29077ea427df0cd86017e38.tar.xz
libdbpp-odbc-89ddd6821bb7ecb0c29077ea427df0cd86017e38.zip
Add support for composing Glib::ustrings from columns
Break Project2 components down into generalised classes Tidy up code
Diffstat (limited to 'libodbcpp/column.cpp')
-rw-r--r--libodbcpp/column.cpp56
1 files changed, 54 insertions, 2 deletions
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 386cbfd..c94c25d 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -91,6 +91,18 @@ namespace ODBC {
return writeToBuf(buf, "%g");
}
template <>
+ Glib::ustring
+ _Column<SQLDOUBLE>::compose() const
+ {
+ return Glib::ustring::compose("%1", value);
+ }
+ template <>
+ Glib::ustring
+ _Column<SQLDOUBLE>::compose(const Glib::ustring & fmt) const
+ {
+ return Glib::ustring::compose(fmt, value);
+ }
+ template <>
int
_Column<SQLINTEGER>::writeToBuf(char ** buf, const char * fmt) const
{
@@ -103,6 +115,18 @@ namespace ODBC {
return writeToBuf(buf, "%ld");
}
template <>
+ Glib::ustring
+ _Column<SQLINTEGER>::compose() const
+ {
+ return Glib::ustring::compose("%1", value);
+ }
+ template <>
+ Glib::ustring
+ _Column<SQLINTEGER>::compose(const Glib::ustring & fmt) const
+ {
+ return Glib::ustring::compose(fmt, value);
+ }
+ template <>
int
_Column<SQLCHAR*>::writeToBuf(char ** buf, const char * fmt) const
{
@@ -115,13 +139,25 @@ namespace ODBC {
return writeToBuf(buf, "%s");
}
template <>
+ Glib::ustring
+ _Column<SQLCHAR*>::compose() const
+ {
+ return Glib::ustring::compose("%1", value);
+ }
+ template <>
+ Glib::ustring
+ _Column<SQLCHAR*>::compose(const Glib::ustring & fmt) const
+ {
+ return Glib::ustring::compose(fmt, value);
+ }
+ template <>
int
_Column<SQL_TIMESTAMP_STRUCT>::writeToBuf(char ** buf, const char * fmt) const
{
- *buf = (char *)malloc(30);
+ *buf = (char *)malloc(300);
struct tm t;
t << value;
- return strftime(*buf, 30, fmt, &t);
+ return strftime(*buf, sizeof(*buf), fmt, &t);
}
template <>
int
@@ -129,6 +165,22 @@ namespace ODBC {
{
return writeToBuf(buf, "%F %T");
}
+ template <>
+ Glib::ustring
+ _Column<SQL_TIMESTAMP_STRUCT>::compose(const Glib::ustring & fmt) const
+ {
+ char buf[300];
+ struct tm t;
+ t << value;
+ int len = strftime(buf, sizeof(buf), fmt.c_str(), &t);
+ return Glib::ustring(buf, len);
+ }
+ template <>
+ Glib::ustring
+ _Column<SQL_TIMESTAMP_STRUCT>::compose() const
+ {
+ return compose("%F %T");
+ }
}
void operator << (SQL_TIMESTAMP_STRUCT & target, const struct tm & src)