diff options
author | randomdan <randomdan@localhost> | 2014-03-03 20:57:27 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2014-03-03 20:57:27 +0000 |
commit | e267def4f9f2e47402d72b56a45924f0bd2c0a18 (patch) | |
tree | 3384c10e1dbd84247c6d9429ffe3fab4ae398a48 /libodbcpp/param.cpp | |
parent | Fix slice scanner and split .ice files back into logical blocks (diff) | |
download | libdbpp-odbc-e267def4f9f2e47402d72b56a45924f0bd2c0a18.tar.bz2 libdbpp-odbc-e267def4f9f2e47402d72b56a45924f0bd2c0a18.tar.xz libdbpp-odbc-e267def4f9f2e47402d72b56a45924f0bd2c0a18.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 'libodbcpp/param.cpp')
-rw-r--r-- | libodbcpp/param.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/libodbcpp/param.cpp b/libodbcpp/param.cpp index 466892c..8e30f14 100644 --- a/libodbcpp/param.cpp +++ b/libodbcpp/param.cpp @@ -74,9 +74,8 @@ SIMPLEBINDER(float, FloatingPointParam, F); SIMPLEBINDER(const Glib::ustring &, GlibUstringParam, S); -SIMPLEBINDER(const struct tm *, TimeStampParam, T); -SIMPLEBINDER(const SQL_TIMESTAMP_STRUCT &, TimeStampParam, T); -SIMPLEBINDER(time_t, TimeStampParam, T); +SIMPLEBINDER(const boost::posix_time::ptime &, TimeStampParam, T); +SIMPLEBINDER(const boost::posix_time::time_duration &, IntervalParam, T); void ODBC::Command::bindNull(unsigned int i) @@ -98,10 +97,26 @@ ODBC::GlibUstringParam::operator=(Glib::ustring const & d) } void -ODBC::TimeStampParam::operator=(time_t const & d) +ODBC::TimeStampParam::operator=(const boost::posix_time::ptime & d) { - struct tm t; - gmtime_r(&d, &t); - data << t; + data.year = d.date().year(); + data.month = d.date().month(); + data.day = d.date().day(); + data.hour = d.time_of_day().hours(); + data.minute = d.time_of_day().minutes(); + data.second = d.time_of_day().seconds(); + data.fraction = d.time_of_day().fractional_seconds(); +} + +void +ODBC::IntervalParam::operator=(const boost::posix_time::time_duration & d) +{ + data.interval_type = SQL_IS_DAY_TO_SECOND; + data.interval_sign = d.is_negative(); + data.intval.day_second.day = d.hours() / 24; + data.intval.day_second.hour = d.hours() % 24; + data.intval.day_second.minute = d.minutes(); + data.intval.day_second.second = d.seconds(); + data.intval.day_second.fraction = d.fractional_seconds(); } |