summaryrefslogtreecommitdiff
path: root/libpqpp/command.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-03-03 20:57:27 +0000
committerrandomdan <randomdan@localhost>2014-03-03 20:57:27 +0000
commit1b6aaca3c5eb7e58ebc54242cb76ebe712e2821a (patch)
treec6e389a14de0f8a4ca75e26a1128b71b4c746a2f /libpqpp/command.cpp
parentImprovements to popenrw and add popenrwe for the stderr pipe too (diff)
downloadlibdbpp-postgresql-1b6aaca3c5eb7e58ebc54242cb76ebe712e2821a.tar.bz2
libdbpp-postgresql-1b6aaca3c5eb7e58ebc54242cb76ebe712e2821a.tar.xz
libdbpp-postgresql-1b6aaca3c5eb7e58ebc54242cb76ebe712e2821a.zip
Adds native support for time_duration as a variable type
Pass/retrieve boost::posix_time ptime and time_duration into/out of the db tier
Diffstat (limited to 'libpqpp/command.cpp')
-rw-r--r--libpqpp/command.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/libpqpp/command.cpp b/libpqpp/command.cpp
index b901310..abd37e6 100644
--- a/libpqpp/command.cpp
+++ b/libpqpp/command.cpp
@@ -2,6 +2,7 @@
#include "connection.h"
#include <stdlib.h>
#include <string.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
static std::string addrStr(void * p, unsigned int no) {
std::string r(50, ' ');
@@ -102,20 +103,22 @@ PQ::Command::bindParamS(unsigned int n, const Glib::ustring & s)
lengths[n] = s.bytes();
}
void
-PQ::Command::bindParamT(unsigned int n, const tm * v)
+PQ::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration & v)
{
paramsAtLeast(n);
- values[n] = static_cast<char *>(malloc(20));
+ auto buf = boost::posix_time::to_simple_string(v);
+ values[n] = strdup(buf.c_str());
formats[n] = 0;
- strftime(values[n], 20, "%F %T", v);
- lengths[n] = 19;
+ lengths[n] = buf.length();
}
void
-PQ::Command::bindParamT(unsigned int n, time_t v)
+PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime & v)
{
- struct tm t;
- gmtime_r(&v, &t);
- bindParamT(n, &t);
+ paramsAtLeast(n);
+ auto buf = boost::posix_time::to_iso_extended_string(v);
+ values[n] = strdup(buf.c_str());
+ formats[n] = 0;
+ lengths[n] = buf.length();
}
void
PQ::Command::bindNull(unsigned int n)