FACT++  1.0
int FillSql ( Database db,
int  enter,
const vector< Source > &  obs,
double  startup_offset 
)

Definition at line 535 of file makeschedule.cc.

References begin, Time::GetAsStr(), and str.

Referenced by main().

536 {
537  const string query0 = "SELECT COUNT(*) FROM Schedule WHERE DATE(ADDTIME(fStart, '-12:00')) = '"+Time(obs[0].begin).GetAsStr("%Y-%m-%d")+"'";
538 
539  const mysqlpp::StoreQueryResult res0 = db.query(query0).store();
540 
541  if (res0.num_rows()!=1)
542  {
543  cout << "Check for schedule size failed." << endl;
544  return 10;
545  }
546 
547  if (uint32_t(res0[0][0])!=0)
548  {
549  cout << "Schedule not empty." << endl;
550  return 11;
551  }
552 
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])));
557 
558  ostringstream str;
559  str << "INSERT INTO Schedule (fStart, fUser, fMeasurementID, fMeasurementTypeKEY, fSourceKEY) VALUES ";
560 
561  str << "('" << Time(obs[0].begin-startup_offset).GetAsStr() << "', 'auto', 0, " << types["Startup"] << ", NULL),\n"; // [Startup]\n";
562  for (const auto& src: obs)
563  {
564  string tm = Time(src.begin).GetAsStr();
565 
566  /*
567  if (src.preobs.size()>0)
568  {
569  for (const auto& pre: src.preobs)
570  {
571  str << tm << " " << pre << "\n";
572  tm = " ";
573  }
574  }*/
575 
576  if (src.name!="SLEEP")
577  str << "('" << tm << "', 'auto', 0, " << types["Data"] << ", " << src.key << "),\n"; // [Data: " << src.name << "]\n";
578  else
579  str << "('" << tm << "', 'auto', 0, " << types["Sleep"] << ", NULL),\n"; // [Sleep]\n";
580  }
581 
582  str << "('" << Time(obs.back().end).GetAsStr() << "', 'auto', 0, " << types["Shutdown"] << ", NULL)";// [Shutdown]";
583 
584  if (enter<0)
585  {
586  cout << str.str() << endl;
587  return 0;
588  }
589 
590  db.query(str.str()).exec();
591 
592  cout << "Schedule entered successfully into database." << endl;
593  return 0;
594 }
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
double begin
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240

+ Here is the call graph for this function:

+ Here is the caller graph for this function: