Example #1
0
int CEpgDatabase::Get(CEpgContainer &container)
{
  int iReturn(-1);
  CSingleLock lock(m_critSection);

  CStdString strQuery = FormatSQL("SELECT idEpg, sName, sScraperName FROM epg;");
  if (ResultQuery(strQuery))
  {
    iReturn = 0;

    try
    {
      while (!m_pDS->eof())
      {
        int iEpgID                = m_pDS->fv("idEpg").get_asInt();
        CStdString strName        = m_pDS->fv("sName").get_asString().c_str();
        CStdString strScraperName = m_pDS->fv("sScraperName").get_asString().c_str();

        CEpg newEpg(iEpgID, strName, strScraperName, true);
        if (container.UpdateEntry(newEpg))
          ++iReturn;
        else
        {
          CLog::Log(LOGERROR, "%s - deleting EPG table %d from the database",
              __FUNCTION__, iEpgID);

          CStdString strWhereClause = FormatSQL("idEpg = %u", iEpgID);
          DeleteValues("lastepgscan", strWhereClause);
          DeleteValues("epgtags", strWhereClause);
          DeleteValues("epg", strWhereClause);
        }

        m_pDS->next();
      }
      m_pDS->close();
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "%s - couldn't load EPG data from the database", __FUNCTION__);
    }
  }

  return iReturn;
}