Repository: xbmc/xbmc
File: xbmc/video/VideoDatabase.cpp (C++)

Code before:
      return -1;
    if (nullptr == m_pDS)
      return -1;

    // need this due to the nested GetEpisodeInfo query
    std::unique_ptr<Dataset> pDS;
    pDS.reset(m_pDB->CreateDataset());
    if (nullptr == pDS)
      return -1;

    int idFile = GetFileId(strFilenameAndPath);
    if (idFile < 0)
      return -1;

    std::string strSQL=PrepareSQL("select idEpisode from episode where idFile=%i", idFile);

    CLog::LogFC(LOGDEBUG, LOGDATABASE, "({}), query = {}", CURL::GetRedacted(strFilenameAndPath),
                strSQL);
    pDS->query(strSQL);
    if (pDS->num_rows() > 0)
    {
      if (idEpisode == -1)
        idEpisode = pDS->fv("episode.idEpisode").get_asInt();
      else // use the hint!
      {
        while (!pDS->eof())
        {
          CVideoInfoTag tag;
          int idTmpEpisode = pDS->fv("episode.idEpisode").get_asInt();
          GetEpisodeBasicInfo(strFilenameAndPath, tag, idTmpEpisode);
          if (tag.m_iEpisode == idEpisode && (idSeason == -1 || tag.m_iSeason == idSeason)) {
            // match on the episode hint, and there's no season hint or a season hint match
            idEpisode = idTmpEpisode;
            break;
          }
          pDS->next();
        }
        if (pDS->eof())
          idEpisode = -1;
      }
    }
    else
      idEpisode = -1;

    pDS->close();

    return idEpisode;
  }
  catch (...)
  {
    CLog::LogF(LOGERROR, "({}) failed", strFilenameAndPath);

Review comment (suggestion):
The hint idEpisode and idSeason are not the db idEpisode and idSeason but the episode and season numbers, please change the parameter names to the clearer "episode" and "season".

Code after:

int CVideoDatabase::GetEpisodeId(const std::string& strFilenameAndPath, int idEpisode, int idSeason) // input value is episode/season number hint - for multiparters
{
  try
  {
    if (nullptr == m_pDB)
      return -1;

    // need this due to the nested GetEpisodeInfo query
    std::unique_ptr<Dataset> pDS;
    pDS.reset(m_pDB->CreateDataset());
    if (nullptr == pDS)
      return -1;

    const int idFile{GetFileId(strFilenameAndPath)};
    int idReturnEpisode{-1};
    if (idFile > 0)
    {
      const std::string strSQL{PrepareSQL("select idEpisode from episode where idFile=%i", idFile)};

      CLog::LogFC(LOGDEBUG, LOGDATABASE, "({}), query = {}", CURL::GetRedacted(strFilenameAndPath),
                  strSQL);
      pDS->query(strSQL);
      if (pDS->num_rows() > 0)
      {
        if (idEpisode == -1)
          idReturnEpisode = pDS->fv("episode.idEpisode").get_asInt();
        else // use the hint!
        {
          while (!pDS->eof())
          {
            CVideoInfoTag tag;
            const int idTmpEpisode{pDS->fv("episode.idEpisode").get_asInt()};
            GetEpisodeBasicInfo(strFilenameAndPath, tag, idTmpEpisode);
            if (tag.m_iEpisode == idEpisode && (idSeason == -1 || tag.m_iSeason == idSeason))
            {
              // match on the episode hint, and there's no season hint or a season hint match
              idReturnEpisode = idTmpEpisode;
              break;
            }
            pDS->next();
          }
        }
      }
    }

    if (idReturnEpisode == -1 && idEpisode != -1 && idSeason != -1)
    {
      // Consider the possibility the path could be bluray://
      // In which case strFilenameAndPath is the basepath (in case of files) or
      // <basepath>/file.iso (in case of ISO)