From de6be7bbb9a2984a514d4076d77d97b054585d7c Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 7 Apr 2010 19:25:52 +0000 Subject: Add a writeToBuf function and use it --- libodbcpp/column.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- libodbcpp/column.h | 4 ++++ 2 files changed, 56 insertions(+), 1 deletion(-) (limited to 'libodbcpp') diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp index 0d0e6e2..14b12f8 100644 --- a/libodbcpp/column.cpp +++ b/libodbcpp/column.cpp @@ -1,3 +1,5 @@ +#include +#include #include "column.h" #include "command.h" #include "error.h" @@ -67,5 +69,54 @@ namespace ODBC { REBIND(float, bindParamF) REBIND(TimeTypePair, bindParamT) REBIND(unsigned char *, bindParamS) -} + template <> + int + _Column::writeToBuf(char ** buf, const char * fmt) const + { + return asprintf(buf, fmt, value); + } + template <> + int + _Column::writeToBuf(char ** buf) const + { + return writeToBuf(buf, "%d"); + } + template <> + int + _Column::writeToBuf(char ** buf, const char * fmt) const + { + return asprintf(buf, fmt, value); + } + template <> + int + _Column::writeToBuf(char ** buf) const + { + return writeToBuf(buf, "%ld"); + } + template <> + int + _Column::writeToBuf(char ** buf, const char * fmt) const + { + return asprintf(buf, fmt, value); + } + template <> + int + _Column::writeToBuf(char ** buf) const + { + return writeToBuf(buf, "%s"); + } + template <> + int + _Column::writeToBuf(char ** buf, const char * fmt) const + { + *buf = (char *)malloc(30); + return strftime(*buf, sizeof(buf), fmt, &value.c()); + } + template <> + int + _Column::writeToBuf(char ** buf) const + { + return writeToBuf(buf, "%F %T"); + } +} diff --git a/libodbcpp/column.h b/libodbcpp/column.h index acc6904..616ca2d 100644 --- a/libodbcpp/column.h +++ b/libodbcpp/column.h @@ -22,6 +22,8 @@ namespace ODBC { operator String () const; operator const struct tm & () const; virtual void rebind(Command *, unsigned int col) const = 0; + virtual int writeToBuf(char ** buf) const = 0; + virtual int writeToBuf(char ** buf, const char * fmt) const = 0; const unsigned int colNo; const String name; @@ -35,6 +37,8 @@ namespace ODBC { _Column(String, unsigned int); ~_Column() {} void rebind(Command *, unsigned int col) const; + int writeToBuf(char ** buf) const; + int writeToBuf(char ** buf, const char * fmt) const; }; } -- cgit v1.2.3