summaryrefslogtreecommitdiff
path: root/libmysqlpp/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
commit274b757c0626abcda3a0414451fc4d1b2bc766f9 (patch)
tree714942e2fd8694548c7ced7859a996475e30a571 /libmysqlpp/command.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/command.cpp')
-rw-r--r--libmysqlpp/command.cpp28
1 files changed, 17 insertions, 11 deletions
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<MYSQL_TIME*>(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<MYSQL_TIME*>(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)