Repository: xbmc/xbmc
File: xbmc/pvr/epg/EpgDatabase.cpp (C++)

Code before:
                "bIncludeUnknownGenres     bool, "
                "bRemoveDuplicates         bool, "
                "bIgnoreFinishedBroadcasts bool, "
                "bIgnoreFutureBroadcasts   bool, "
                "bFreeToAirOnly            bool, "
                "bIgnorePresentTimers      bool, "
                "bIgnorePresentRecordings  bool"
                ")");
  }

  if (iVersion < 16)
  {
    m_pDS->exec("ALTER TABLE savedsearches ADD iChannelGroup integer;");
    m_pDS->exec("UPDATE savedsearches SET iChannelGroup = -1");
  }

  if (iVersion < 17)
  {
    m_pDS->exec("ALTER TABLE savedsearches ADD sIconPath varchar(255);");
    m_pDS->exec("UPDATE savedsearches SET sIconPath = ''");
    m_pDS->exec("ALTER TABLE epgtags ADD sParentalRatingIcon varchar(512);");
    m_pDS->exec("ALTER TABLE epgtags ADD sParentalRatingSource varchar(128);");
  }
}

bool CPVREpgDatabase::DeleteEpg()
{
  bool bReturn(false);
  CLog::LogFC(LOGDEBUG, LOGEPG, "Deleting all EPG data from the database");

  std::unique_lock<CCriticalSection> lock(m_critSection);

  bReturn = DeleteValues("epg") || bReturn;
  bReturn = DeleteValues("epgtags") || bReturn;
  bReturn = DeleteValues("lastepgscan") || bReturn;

  return bReturn;
}

bool CPVREpgDatabase::QueueDeleteEpgQuery(const CPVREpg& table)
{
  /* invalid channel */
  if (table.EpgID() <= 0)
  {
    CLog::LogF(LOGERROR, "Invalid channel id: {}", table.EpgID());
    return false;
  }

  Filter filter;

  std::unique_lock<CCriticalSection> lock(m_critSection);

Review comment (bug):
This is wrong. You need to bump epg database version to 18. The code that inserts the two new columns MUST be executed in a block `if (iVersion < 18)`.

Code after:
                "bIncludeUnknownGenres     bool, "
                "bRemoveDuplicates         bool, "
                "bIgnoreFinishedBroadcasts bool, "
                "bIgnoreFutureBroadcasts   bool, "
                "bFreeToAirOnly            bool, "
                "bIgnorePresentTimers      bool, "
                "bIgnorePresentRecordings  bool"
                ")");
  }

  if (iVersion < 16)
  {
    m_pDS->exec("ALTER TABLE savedsearches ADD iChannelGroup integer;");
    m_pDS->exec("UPDATE savedsearches SET iChannelGroup = -1");
  }

  if (iVersion < 17)
  {
    m_pDS->exec("ALTER TABLE savedsearches ADD sIconPath varchar(255);");
    m_pDS->exec("UPDATE savedsearches SET sIconPath = ''");
  }

  if (iVersion < 18)
  {
    m_pDS->exec("ALTER TABLE epgtags ADD sParentalRatingIcon varchar(512);");
    m_pDS->exec("ALTER TABLE epgtags ADD sParentalRatingSource varchar(128);");
  }
}

bool CPVREpgDatabase::DeleteEpg()
{
  bool bReturn(false);
  CLog::LogFC(LOGDEBUG, LOGEPG, "Deleting all EPG data from the database");

  std::unique_lock<CCriticalSection> lock(m_critSection);

  bReturn = DeleteValues("epg") || bReturn;
  bReturn = DeleteValues("epgtags") || bReturn;
  bReturn = DeleteValues("lastepgscan") || bReturn;

  return bReturn;
}

bool CPVREpgDatabase::QueueDeleteEpgQuery(const CPVREpg& table)
{
  /* invalid channel */
  if (table.EpgID() <= 0)
  {
    CLog::LogF(LOGERROR, "Invalid channel id: {}", table.EpgID());
    return false;
  }