Beispiel #1
0
bool SqliteObject::deleteDay(const boost::gregorian::date &d) 
{

  //std::cout << boost::gregorian::to_simple_string(d) << std::endl;

  boost::gregorian::greg_day gd = d.day();
  std::stringstream ssd;
  ssd << gd.as_number();
  std::string d_day = ssd.str();

  boost::gregorian::greg_month gm = d.month();
  std::stringstream ssm;
  ssm << gm.as_number();
  std::string d_month = ssm.str();

  //std::cout << " " << d_month << " " << d_day << std::endl;

  // What are the timeindex values to delete
  std::stringstream cmd1;
  cmd1 << "select TimeIndex from Time where month=" << d_month << " and day=" << d_day;
  execute(cmd1.str());

  std::vector<int> time_index(0);
  for(size_t r=0; r<m_results->data.size(); ++r){
    time_index.push_back(atoi(m_results->data[r][0].c_str()));
  }

  // What are the ReportExtendedData records associated with the timeindex values from ReportData to delete
  std::stringstream cmd3;
  std::vector<int> RVEDV_index(0);
  for(size_t s=0; s<time_index.size(); ++s){
    cmd3 << "select ReportExtendedDataIndex from reportExtendedData inner join reportData on reportExtendedData.ReportDataIndex=reportData.ReportDataIndex where reportData.timeindex =" << time_index[s];
    execute(cmd3.str());
    cmd3.str(std::string());  //clear out the string

    for(size_t r=0; r<m_results->data.size(); ++r){
      RVEDV_index.push_back(atoi(m_results->data[r][0].c_str()));
    }
  }


  execute("begin");

  std::stringstream cmd2;
  // reportData
  for(size_t r=0; r<time_index.size(); ++r){
    cmd2.str(std::string());  //clear out the string
    cmd2 << "delete from reportData where TimeIndex = " << time_index[r];
    execute(cmd2.str());
    //std::cout << cmd2.str() << std::endl;
    //print();
  }
  // reportExtendedData
  for(size_t r=0; r<RVEDV_index.size(); ++r){
    //std::stringstream cmd2;
    cmd2.str(std::string());  //clear out the string
    cmd2 << "delete from reportExtendedData where ReportExtendedDataIndex = " << RVEDV_index[r];
    execute(cmd2.str());
    //std::cout << cmd2.str() << std::endl;
    //print();
  }

  // Time
  for(size_t r=0; r<time_index.size(); ++r){
    //std::stringstream cmd2;
    cmd2.str(std::string());  //clear out the string
    cmd2 << "delete from Time where TimeIndex = " << time_index[r];
    execute(cmd2.str());
    //std::cout << cmd2.str() << std::endl;
    //print();
  }

  execute("commit");

  return true;
}