summaryrefslogtreecommitdiff
path: root/libodbcpp/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
commite267def4f9f2e47402d72b56a45924f0bd2c0a18 (patch)
tree3384c10e1dbd84247c6d9429ffe3fab4ae398a48 /libodbcpp/column.cpp
parentFix slice scanner and split .ice files back into logical blocks (diff)
downloadlibdbpp-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/column.cpp')
-rw-r--r--libodbcpp/column.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
index 9ff6d8d..da31ed0 100644
--- a/libodbcpp/column.cpp
+++ b/libodbcpp/column.cpp
@@ -61,32 +61,19 @@ ODBC::Column::bind()
}
}
-ODBC::TimeStampColumn::operator struct tm() const
+ODBC::TimeStampColumn::operator boost::posix_time::ptime() const
{
- struct tm t;
- t << data;
- return t;
+ return boost::posix_time::ptime(
+ boost::gregorian::date(data.year, data.month, data.day),
+ boost::posix_time::time_duration(data.hour, data.minute, data.second, data.fraction));
}
-void operator << (SQL_TIMESTAMP_STRUCT & target, const struct tm & src)
+ODBC::IntervalColumn::operator boost::posix_time::time_duration() const
{
- target.year = src.tm_year + 1900;
- target.month = src.tm_mon + 1;
- target.day = src.tm_mday;
- target.hour = src.tm_hour;
- target.minute = src.tm_min;
- target.second = src.tm_sec;
- target.fraction = 0;
+ auto dur = boost::posix_time::time_duration(
+ (24 * data.intval.day_second.day) + data.intval.day_second.hour,
+ data.intval.day_second.minute, data.intval.day_second.second, data.intval.day_second.fraction);
+ return (data.interval_sign ? -dur : dur);
}
-void operator << (struct tm & target, const SQL_TIMESTAMP_STRUCT & src)
-{
- target.tm_year = src.year - 1900;
- target.tm_mon = src.month - 1;
- target.tm_mday = src.day;
- target.tm_hour = src.hour;
- target.tm_min = src.minute;
- target.tm_sec = src.second;
-}
-
void
ODBC::SignedIntegerColumn::apply(DB::HandleField & h) const
{
@@ -111,3 +98,9 @@ ODBC::TimeStampColumn::apply(DB::HandleField & h) const
if (isNull()) return h.null();
h.timestamp(*this);
}
+void
+ODBC::IntervalColumn::apply(DB::HandleField & h) const
+{
+ if (isNull()) return h.null();
+ h.interval(*this);
+}