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

Code before:
    // Retrieve current utilization per type
    m_pDS->query("SELECT vvt.id, vvt.name, count(vv.idType) "
                 "FROM videoversiontype vvt "
                 "  LEFT JOIN videoversion vv ON vvt.id = vv.idType "
                 "WHERE vvt.id = 40405 OR vvt.id BETWEEN 40418 AND 40430 "
                 "GROUP BY vvt.id, vvt.name");

    while (!m_pDS->eof())
    {
      const int typeId{m_pDS->fv(0).get_asInt()};
      const std::string typeName{m_pDS->fv(1).get_asString()};
      const int versionsCount{m_pDS->fv(2).get_asInt()};

      if (versionsCount > 0)
      {
        // type used by some versions, recreate as user type and link the versions to the new id
        m_pDS2->exec(PrepareSQL(
            "INSERT INTO videoversiontype (id, name, owner, itemType) VALUES(NULL, '%s', %i, %i)",
            typeName.c_str(), VideoAssetTypeOwner::USER, VideoAssetType::VERSION));

        const int newId{static_cast<int>(m_pDS2->lastinsertid())};

        m_pDS2->exec(
            PrepareSQL("UPDATE videoversion SET idType = %i WHERE idType = %i", newId, typeId));
      }
      m_pDS2->exec(PrepareSQL("DELETE FROM videoversiontype WHERE id = %i", typeId));
      m_pDS->next();
    }
    m_pDS->close();
  }
}

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

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))
  {

Review comment (suggestion):
wouldn't the more correct way be to just empty the string? We still use the string ID as DB ID, don't we? And since we have a reserved ID range for builtin version labels, the full range is currently in the DB, partially with empty strings. That's at least the case on my beta2 build (can't run anything newer on Fedora as there are no nightlies).

So if we still have all the reserved IDs in the versiontype table, just empty the strings.

Code after:
    // Retrieve current utilization per type
    m_pDS->query("SELECT vvt.id, vvt.name, count(vv.idType) "
                 "FROM videoversiontype vvt "
                 "  LEFT JOIN videoversion vv ON vvt.id = vv.idType "
                 "WHERE vvt.id = 40405 OR vvt.id BETWEEN 40418 AND 40430 "
                 "GROUP BY vvt.id");

    while (!m_pDS->eof())
    {
      const int typeId{m_pDS->fv(0).get_asInt()};
      const std::string typeName{m_pDS->fv(1).get_asString()};
      const int versionsCount{m_pDS->fv(2).get_asInt()};

      if (versionsCount > 0)
      {
        // type used by some versions, recreate as user type and link the versions to the new id
        m_pDS2->exec(PrepareSQL(
            "INSERT INTO videoversiontype (id, name, owner, itemType) VALUES(NULL, '%s', %i, %i)",
            typeName.c_str(), VideoAssetTypeOwner::USER, VideoAssetType::VERSION));

        const int newId{static_cast<int>(m_pDS2->lastinsertid())};

        m_pDS2->exec(
            PrepareSQL("UPDATE videoversion SET idType = %i WHERE idType = %i", newId, typeId));
      }
      m_pDS2->exec(PrepareSQL("DELETE FROM videoversiontype WHERE id = %i", typeId));
      m_pDS->next();
    }
    m_pDS->close();
  }
}

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

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))
  {