537 const string query0 =
"SELECT COUNT(*) FROM Schedule WHERE DATE(ADDTIME(fStart, '-12:00')) = '"+
Time(obs[0].
begin).
GetAsStr(
"%Y-%m-%d")+
"'";
539 const mysqlpp::StoreQueryResult res0 = db.query(query0).store();
541 if (res0.num_rows()!=1)
543 cout <<
"Check for schedule size failed." << endl;
547 if (uint32_t(res0[0][0])!=0)
549 cout <<
"Schedule not empty." << endl;
553 const mysqlpp::StoreQueryResult res1 = db.query(
"SELECT fMeasurementTypeName, fMeasurementTypeKEY FROM MeasurementType").store();
554 map<string, uint32_t> types;
555 for (
const auto &row: res1)
556 types.insert(make_pair(
string(row[0]), uint32_t(row[1])));
559 str <<
"INSERT INTO Schedule (fStart, fUser, fMeasurementID, fMeasurementTypeKEY, fSourceKEY) VALUES ";
561 str <<
"('" <<
Time(obs[0].
begin-startup_offset).
GetAsStr() <<
"', 'auto', 0, " << types[
"Startup"] <<
", NULL),\n";
562 for (
const auto& src: obs)
576 if (src.name!=
"SLEEP")
577 str <<
"('" << tm <<
"', 'auto', 0, " << types[
"Data"] <<
", " << src.key <<
"),\n";
579 str <<
"('" << tm <<
"', 'auto', 0, " << types[
"Sleep"] <<
", NULL),\n";
582 str <<
"('" <<
Time(obs.back().end).GetAsStr() <<
"', 'auto', 0, " << types[
"Shutdown"] <<
", NULL)";
586 cout << str.str() << endl;
590 db.query(str.str()).exec();
592 cout <<
"Schedule entered successfully into database." << endl;
Adds some functionality to boost::posix_time::ptime for our needs.
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const