From 274b757c0626abcda3a0414451fc4d1b2bc766f9 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 --- libmysqlpp/column.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'libmysqlpp/column.cpp') diff --git a/libmysqlpp/column.cpp b/libmysqlpp/column.cpp index cd1d811..7ff365a 100644 --- a/libmysqlpp/column.cpp +++ b/libmysqlpp/column.cpp @@ -2,6 +2,7 @@ #include "selectcommand.h" #include "error.h" #include +#include MySQL::ColumnBase::ColumnBase(const char * name, unsigned int i) : DB::Column(name, i) @@ -94,19 +95,24 @@ namespace MySQL { h.null(); } else { - struct tm tm; - memset(&tm, 0, sizeof(tm)); - tm.tm_year = value.year - 1900; - tm.tm_mon = value.month - 1; - tm.tm_mday = value.day; - tm.tm_hour = value.hour; - tm.tm_min = value.minute; - tm.tm_sec = value.second; - h.timestamp(tm); + h.timestamp(boost::posix_time::ptime( + boost::gregorian::date(value.year, value.month, value.day), + boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part))); + } + } + template <> void Column::apply(DB::HandleField & h) const + { + if (is_null) { + h.null(); + } + else { + h.interval( + boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part)); } } template class Column; template class Column; template class Column; + template class Column; } -- cgit v1.2.3