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

Code before:
                   "SELECT itemType FROM videoversiontype WHERE itemType NOT IN (%i, %i) "
                   "LIMIT 1 ",
                   VIDEOASSETTYPE_VERSION_OLD, VIDEOASSETTYPE_EXTRA_OLD, VIDEOASSETTYPE_VERSION_OLD,
                   VIDEOASSETTYPE_EXTRA_OLD));
    if (!m_pDS->eof())
    {
      CLog::LogF(LOGERROR, "invalid itemType values in videoversion or videoversiontype");
      m_pDS->close();
    }

    m_pDS->exec(
        PrepareSQL("UPDATE videoversion SET itemType = itemType + 1  WHERE itemType IN (%i, %i)",
                   VIDEOASSETTYPE_VERSION_OLD, VIDEOASSETTYPE_EXTRA_OLD));
    m_pDS->exec(PrepareSQL(
        "UPDATE videoversiontype SET itemType = itemType + 1  WHERE itemType IN (%i, %i)",
        VIDEOASSETTYPE_VERSION_OLD, VIDEOASSETTYPE_EXTRA_OLD));
  }
}

int CVideoDatabase::GetSchemaVersion() const
{
  return 134;
}

bool CVideoDatabase::LookupByFolders(const std::string &path, bool shows)
{
  SScanSettings settings;
  bool foundDirectly = false;
  ScraperPtr scraper = GetScraperForPath(path, settings, foundDirectly);
  if (scraper && scraper->Content() == CONTENT_TVSHOWS && !shows)
    return false; // episodes
  return settings.parent_name_root; // shows, movies, musicvids
}

bool CVideoDatabase::GetPlayCounts(const std::string &strPath, CFileItemList &items)
{
  if(URIUtils::IsMultiPath(strPath))
  {
    std::vector<std::string> paths;
    CMultiPathDirectory::GetPaths(strPath, paths);

    bool ret = false;
    for(unsigned i=0;i<paths.size();i++)
      ret |= GetPlayCounts(paths[i], items);

    return ret;
  }
  int pathID = -1;
  if (!URIUtils::IsPlugin(strPath))
  {
    pathID = GetPathId(strPath);

Review comment (suggestion):
Consider defining the prefix 'pvr://recordings/' as a constant and deriving its length rather than using the hardcoded value 17. This change would improve maintainability if the base URL ever changes.

Code after:
                   "SELECT itemType FROM videoversiontype WHERE itemType NOT IN (%i, %i) "
                   "LIMIT 1 ",
                   VIDEOASSETTYPE_VERSION_OLD, VIDEOASSETTYPE_EXTRA_OLD, VIDEOASSETTYPE_VERSION_OLD,
                   VIDEOASSETTYPE_EXTRA_OLD));
    if (!m_pDS->eof())
    {
      CLog::LogF(LOGERROR, "invalid itemType values in videoversion or videoversiontype");
      m_pDS->close();
    }

    m_pDS->exec(
        PrepareSQL("UPDATE videoversion SET itemType = itemType + 1  WHERE itemType IN (%i, %i)",
                   VIDEOASSETTYPE_VERSION_OLD, VIDEOASSETTYPE_EXTRA_OLD));
    m_pDS->exec(PrepareSQL(
        "UPDATE videoversiontype SET itemType = itemType + 1  WHERE itemType IN (%i, %i)",
        VIDEOASSETTYPE_VERSION_OLD, VIDEOASSETTYPE_EXTRA_OLD));
  }

  if (iVersion < 135)
  {
    // Fix PVR recording path encoding bug.
    m_pDS->query("SELECT idPath, strPath FROM path WHERE strPath LIKE 'pvr://recordings/%'");
    while (!m_pDS->eof())
    {
      std::string fixedPath{m_pDS->fv(1).get_asString()};
      fixedPath.erase(0, 17); // Omit "pvr://recordings/".

      // Fix special case where ? contained in directory names was treated as URL parameter.
      const size_t pos{fixedPath.find("/?")};
      if (pos != std::string::npos)
        fixedPath.erase(pos, 1);

      std::vector<std::string> segments{StringUtils::Split(fixedPath, "/")};
      for (auto& segment : segments)
        segment = CURL::Encode(segment);

      fixedPath = "pvr://recordings/";
      fixedPath += StringUtils::Join(segments, "/");

      m_pDS2->exec(PrepareSQL("UPDATE path SET strPath='%s' WHERE idPath=%i", fixedPath.c_str(),
                              m_pDS->fv(0).get_asInt()));
      m_pDS->next();
    }
    m_pDS->close();
  }
}

int CVideoDatabase::GetSchemaVersion() const
{
  return 135;
}