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 | 6ae914ceb99aaeba3c69a4b9efe839f1c6e9932b (patch) | |
tree | b2bbfd5bf670ec04c1ac2d8ffebfe2a0181d8e63 /project2/sql | |
parent | Don't create the app engine instance before forking (diff) | |
download | project2-6ae914ceb99aaeba3c69a4b9efe839f1c6e9932b.tar.bz2 project2-6ae914ceb99aaeba3c69a4b9efe839f1c6e9932b.tar.xz project2-6ae914ceb99aaeba3c69a4b9efe839f1c6e9932b.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 'project2/sql')
-rw-r--r-- | project2/sql/sqlCache.cpp | 7 | ||||
-rw-r--r-- | project2/sql/sqlHandleAsVariableType.cpp | 7 | ||||
-rw-r--r-- | project2/sql/sqlHandleAsVariableType.h | 3 | ||||
-rw-r--r-- | project2/sql/sqlTest.cpp | 7 | ||||
-rw-r--r-- | project2/sql/sqlVariableBinder.cpp | 8 | ||||
-rw-r--r-- | project2/sql/sqlVariableBinder.h | 1 |
6 files changed, 23 insertions, 10 deletions
diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp index af59ee5..2d40bdd 100644 --- a/project2/sql/sqlCache.cpp +++ b/project2/sql/sqlCache.cpp @@ -15,6 +15,7 @@ #include <boost/foreach.hpp> #include "options.h" #include <boost/algorithm/string/predicate.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> typedef boost::shared_ptr<DB::SelectCommand> SelectPtr; typedef boost::shared_ptr<DB::ModifyCommand> ModifyPtr; @@ -141,7 +142,7 @@ class SqlCache : public Cache { auto con = db->getReadonly(); SelectPtr gh(con->newSelectCommand(sql)); unsigned int offset = 0; - gh->bindParamT(offset++, time(NULL) - CacheLife); + gh->bindParamT(offset++, boost::posix_time::microsec_clock::universal_time() - boost::posix_time::seconds(CacheLife)); applyKeys(ec, boost::bind(bindKeyValues, gh.get(), &offset, _2), ps); if (gh->fetch()) { return new SqlCacheRowSet(gh); @@ -215,7 +216,7 @@ class SqlCache : public Cache { Buffer del; del.appendf("INSERT INTO %s(p2_time) VALUES(?)", HeaderTable.c_str()); ModifyPtr h = ModifyPtr(con->newModifyCommand(del)); - h->bindParamT(0, time(NULL)); + h->bindParamT(0, boost::posix_time::microsec_clock::universal_time()); h->execute(); // Record set header Buffer sql; @@ -275,7 +276,7 @@ class CustomSqlCacheLoader : public ElementLoader::For<SqlCache> { del.appendf("DELETE FROM %s WHERE p2_time < ?", SqlCache::HeaderTable.c_str()); auto con = db->getWritable(); ModifyPtr m(con->newModifyCommand(del)); - m->bindParamT(0, time(NULL) - SqlCache::CacheLife); + m->bindParamT(0, boost::posix_time::microsec_clock::universal_time() - boost::posix_time::seconds(SqlCache::CacheLife)); m->execute(); db->commit(); } diff --git a/project2/sql/sqlHandleAsVariableType.cpp b/project2/sql/sqlHandleAsVariableType.cpp index e628c29..2583df5 100644 --- a/project2/sql/sqlHandleAsVariableType.cpp +++ b/project2/sql/sqlHandleAsVariableType.cpp @@ -14,7 +14,10 @@ void HandleAsVariableType::integer(int64_t i) { void HandleAsVariableType::floatingpoint(double d) { variable = d; } -void HandleAsVariableType::timestamp(const struct tm & t) { - variable = boost::posix_time::ptime(boost::posix_time::ptime_from_tm(t)); +void HandleAsVariableType::interval(const boost::posix_time::time_duration & t) { + variable = t; +} +void HandleAsVariableType::timestamp(const boost::posix_time::ptime & t) { + variable = t; } diff --git a/project2/sql/sqlHandleAsVariableType.h b/project2/sql/sqlHandleAsVariableType.h index c874b7c..2aa6ccb 100644 --- a/project2/sql/sqlHandleAsVariableType.h +++ b/project2/sql/sqlHandleAsVariableType.h @@ -10,7 +10,8 @@ class HandleAsVariableType : public DB::HandleField { void string(const char * c, size_t l); void integer(int64_t i); void floatingpoint(double d); - void timestamp(const struct tm & t); + void interval(const boost::posix_time::time_duration & t); + void timestamp(const boost::posix_time::ptime & t); VariableType variable; }; diff --git a/project2/sql/sqlTest.cpp b/project2/sql/sqlTest.cpp index 45178ef..30b43b8 100644 --- a/project2/sql/sqlTest.cpp +++ b/project2/sql/sqlTest.cpp @@ -54,8 +54,11 @@ class HandleDoCompare : public DB::HandleField { void floatingpoint(double val) { doTest(val); } - void timestamp(const struct tm & val) { - doTest(boost::posix_time::ptime_from_tm(val)); + void interval(const boost::posix_time::time_duration & val) { + doTest(val); + } + void timestamp(const boost::posix_time::ptime & val) { + doTest(val); } bool operator()() const { return retVal; diff --git a/project2/sql/sqlVariableBinder.cpp b/project2/sql/sqlVariableBinder.cpp index c56047c..7d6645a 100644 --- a/project2/sql/sqlVariableBinder.cpp +++ b/project2/sql/sqlVariableBinder.cpp @@ -35,8 +35,12 @@ SqlVariableBinder::operator()(const Boolean & i) const cmd->bindParamI(idx, i.value ? 1 : 0); } void +SqlVariableBinder::operator()(const boost::posix_time::time_duration & i) const +{ + cmd->bindParamT(idx, i); +} +void SqlVariableBinder::operator()(const boost::posix_time::ptime & i) const { - struct tm tm(boost::posix_time::to_tm(i)); - cmd->bindParamT(idx, &tm); + cmd->bindParamT(idx, i); } diff --git a/project2/sql/sqlVariableBinder.h b/project2/sql/sqlVariableBinder.h index 4bbee9f..9f351e4 100644 --- a/project2/sql/sqlVariableBinder.h +++ b/project2/sql/sqlVariableBinder.h @@ -14,6 +14,7 @@ class SqlVariableBinder : public boost::static_visitor<> { void operator()(const Glib::ustring & i) const; void operator()(const int64_t & i) const; void operator()(const double & i) const; + void operator()(const boost::posix_time::time_duration & i) const; void operator()(const boost::posix_time::ptime & i) const; private: |