void MongoDBTest::testInsertRequest() { if (!_connected) { std::cout << "Not connected, test skipped." << std::endl; return; } Poco::MongoDB::Document::Ptr player = new Poco::MongoDB::Document(); player->add("lastname", std::string("Braem")); player->add("firstname", std::string("Franky")); Poco::DateTime birthdate; birthdate.assign(1969, 3, 9); player->add("birthdate", birthdate.timestamp()); player->add("start", 1993); player->add("active", false); Poco::DateTime now; std::cout << now.day() << " " << now.hour() << ":" << now.minute() << ":" << now.second() << std::endl; player->add("lastupdated", now.timestamp()); player->add("unknown", NullValue()); Poco::MongoDB::InsertRequest request("team.players"); request.documents().push_back(player); _mongo.sendRequest(request); }
void InactiveIdentityRequester::PopulateIDList() { Poco::DateTime weekago; int id; int count=0; SQLite3DB::Transaction trans(m_db); weekago-=Poco::Timespan(7,0,0,0,0); weekago.assign(weekago.year(),weekago.month(),weekago.day(),0,0,0); // only selects, deferred OK trans.Begin(); // select identities we want to query (haven't seen yet today) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending) SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen IS NOT NULL AND LastSeen<? AND tblIdentity.FailureCount<=(SELECT OptionValue FROM tblOption WHERE Option='MaxFailureCount') AND (PurgeDate IS NULL OR PurgeDate>datetime('now')) ORDER BY RANDOM();"); st.Bind(0, Poco::DateTimeFormatter::format(weekago,"%Y-%m-%d %H:%M:%S")); trans.Step(st); m_ids.clear(); while(st.RowReturned()) { st.ResultInt(0,id); m_ids[std::pair<long,long>(count,id)].m_requested=false; trans.Step(st); count+=1; } trans.Finalize(st); trans.Commit(); }
void TrustListInserter::CheckForNeededInsert() { Poco::DateTime date; int currentday=date.day(); date-=Poco::Timespan(0,6,0,0,0); // insert trust lists every 6 hours - if 6 hours ago was different day then set to midnight of current day to insert list today ASAP if(currentday!=date.day()) { date.assign(date.year(),date.month(),currentday,0,0,0); } SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID, PrivateKey FROM tblLocalIdentity WHERE tblLocalIdentity.Active='true' AND PrivateKey IS NOT NULL AND PrivateKey <> '' AND PublishTrustList='true' AND InsertingTrustList='false' AND (LastInsertedTrustList<=? OR LastInsertedTrustList IS NULL);"); st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")); st.Step(); if(st.RowReturned()) { int lid=0; std::string pkey(""); st.ResultInt(0,lid); st.ResultText(1,pkey); StartInsert(lid,pkey); } }
void Utility::dateTimeSync(Poco::DateTime& dt, const SQL_TIMESTAMP_STRUCT& ts) { double msec = ts.fraction/1000000; double usec = 1000 * (msec - std::floor(msec)); dt.assign(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, (int) std::floor(msec), (int) std::floor(usec)); }
void MongoDBTest::testInsertRequest() { Poco::MongoDB::Document::Ptr player = new Poco::MongoDB::Document(); player->add("lastname", std::string("Braem")); player->add("firstname", std::string("Franky")); Poco::DateTime birthdate; birthdate.assign(1969, 3, 9); player->add("birthdate", birthdate.timestamp()); player->add("start", 1993); player->add("active", false); Poco::DateTime now; player->add("lastupdated", now.timestamp()); player->add("unknown", NullValue()); Poco::MongoDB::InsertRequest request("team.players"); request.documents().push_back(player); _mongo->sendRequest(request); }