From 1b6aaca3c5eb7e58ebc54242cb76ebe712e2821a Mon Sep 17 00:00:00 2001 From: randomdan Date: Mon, 3 Mar 2014 20:57:27 +0000 Subject: 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 --- libpqpp/command.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'libpqpp/command.cpp') 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 #include +#include 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(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) -- cgit v1.2.3