summaryrefslogtreecommitdiff
path: root/libmysqlpp/column.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
commit274b757c0626abcda3a0414451fc4d1b2bc766f9 (patch)
tree714942e2fd8694548c7ced7859a996475e30a571 /libmysqlpp/column.cpp
parentFix slice scanner and split .ice files back into logical blocks (diff)
downloadlibdbpp-mysql-274b757c0626abcda3a0414451fc4d1b2bc766f9.tar.bz2
libdbpp-mysql-274b757c0626abcda3a0414451fc4d1b2bc766f9.tar.xz
libdbpp-mysql-274b757c0626abcda3a0414451fc4d1b2bc766f9.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 'libmysqlpp/column.cpp')
-rw-r--r--libmysqlpp/column.cpp24
1 files changed, 15 insertions, 9 deletions
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 <string.h>
+#include <boost/date_time/gregorian/gregorian_types.hpp>
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<MYSQL_TIME, MYSQL_TYPE_TIME>::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<int64_t, MYSQL_TYPE_LONGLONG>;
template class Column<double, MYSQL_TYPE_DOUBLE>;
template class Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>;
+ template class Column<MYSQL_TIME, MYSQL_TYPE_TIME>;
}