summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libodbcpp/column.cpp56
-rw-r--r--libodbcpp/column.h4
2 files changed, 58 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)
diff --git a/libodbcpp/column.h b/libodbcpp/column.h
index 9f3b93d..3b3370f 100644
--- a/libodbcpp/column.h
+++ b/libodbcpp/column.h
@@ -22,6 +22,8 @@ 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 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;
bool isNull() const;
@@ -38,6 +40,8 @@ namespace ODBC {
_Column(const Glib::ustring &, unsigned int);
~_Column() {}
void rebind(Command *, unsigned int col) 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;
};