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/command.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'libmysqlpp/command.cpp') diff --git a/libmysqlpp/command.cpp b/libmysqlpp/command.cpp index 3551ca7..04628ec 100644 --- a/libmysqlpp/command.cpp +++ b/libmysqlpp/command.cpp @@ -115,25 +115,31 @@ MySQL::Command::bindParamS(unsigned int n, const Glib::ustring & s) binds[n].is_unsigned = 0; } void -MySQL::Command::bindParamT(unsigned int n, const tm * v) +MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::ptime & v) { binds[n].buffer_type = MYSQL_TYPE_DATETIME; binds[n].buffer = realloc(binds[n].buffer, sizeof(MYSQL_TIME)); MYSQL_TIME & ts = *static_cast(binds[n].buffer); - ts.year = v->tm_year + 1900; - ts.month = v->tm_mon + 1; - ts.day = v->tm_mday; - ts.hour = v->tm_hour; - ts.minute = v->tm_min; - ts.second = v->tm_sec; + ts.year = v.date().year(); + ts.month = v.date().month(); + ts.day = v.date().day(); + ts.hour = v.time_of_day().hours(); + ts.minute = v.time_of_day().minutes(); + ts.second = v.time_of_day().seconds(); + ts.second_part = v.time_of_day().total_microseconds() % 1000000; ts.neg = 0; } void -MySQL::Command::bindParamT(unsigned int n, time_t v) +MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration & v) { - struct tm t; - gmtime_r(&v, &t); - bindParamT(n, &t); + binds[n].buffer_type = MYSQL_TYPE_TIME; + binds[n].buffer = realloc(binds[n].buffer, sizeof(MYSQL_TIME)); + MYSQL_TIME & ts = *static_cast(binds[n].buffer); + ts.hour = v.hours(); + ts.minute = v.minutes(); + ts.second = v.seconds(); + ts.second_part = v.total_microseconds() % 1000000; + ts.neg = (v.is_negative() ? 1 : 0); } void MySQL::Command::bindNull(unsigned int n) -- cgit v1.2.3