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

Code before:

  if (strValue.empty())
    return 0;

  return atoi(strValue.c_str());
}

void CPVRDatabase::FixupClientIDs()
{
  // Get enabled and disabled PVR client addon infos
  std::vector<ADDON::AddonInfoPtr> addonInfos;
  CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, false, ADDON::AddonType::PVRDLL);

  std::vector<std::tuple<std::string, ADDON::AddonInstanceId, std::string>> clientInfos;
  for (const auto& addonInfo : addonInfos)
  {
    const std::vector<ADDON::AddonInstanceId> instanceIds{addonInfo->GetKnownInstanceIds()};
    for (const auto instanceId : instanceIds)
    {
      clientInfos.emplace_back(addonInfo->ID(), instanceId, addonInfo->Name());
    }
  }

  for (const auto& clientInfo : clientInfos)
  {
    const std::string addonID{std::get<0>(clientInfo)};
    const ADDON::AddonInstanceId instanceID{std::get<1>(clientInfo)};

    // Entry with legacy client id present in clients or channels table?
    const CPVRClientUID uid{addonID, instanceID};
    int legacyID{uid.GetLegacyUID()};
    std::string sql{PrepareSQL("idClient = %i", legacyID)};
    int id{GetSingleValueInt("clients", "idClient", sql)};
    if (id == legacyID)
    {
      // Add addon id and instance id to existing clients table entry.
      sql = PrepareSQL("UPDATE clients SET sAddonID = '%s', iInstanceID = %i WHERE idClient = %i",
                       addonID.c_str(), instanceID, legacyID);
      ExecuteQuery(sql);
    }
    else
    {
      sql = PrepareSQL("iClientId = %i", legacyID);
      id = GetSingleValueInt("channels", "iClientId", sql);
      if (id == legacyID)
      {
        // Create a new entry with the legacy client id in clients table.
        sql = PrepareSQL("REPLACE INTO clients (idClient, iPriority, sAddonID, iInstanceID) VALUES "
                         "(%i, %i, '%s', %i)",
                         legacyID, 0, addonID.c_str(), instanceID);
        ExecuteQuery(sql);

Review comment (suggestion):
You could use structured bindings in the for loop to avoid this.
```c++
for (const auto& [addonID, instanceID, addonName] : clientInfos)
```


Code after:

  if (strValue.empty())
    return 0;

  return atoi(strValue.c_str());
}

void CPVRDatabase::FixupClientIDs()
{
  // Get enabled and disabled PVR client addon infos
  std::vector<ADDON::AddonInfoPtr> addonInfos;
  CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, false, ADDON::AddonType::PVRDLL);

  std::vector<std::tuple<std::string, ADDON::AddonInstanceId, std::string>> clientInfos;
  for (const auto& addonInfo : addonInfos)
  {
    const std::vector<ADDON::AddonInstanceId> instanceIds{addonInfo->GetKnownInstanceIds()};
    for (const auto instanceId : instanceIds)
    {
      clientInfos.emplace_back(addonInfo->ID(), instanceId, addonInfo->Name());
    }
  }

  for (const auto& [addonID, instanceID, addonName] : clientInfos)
  {
    // Entry with legacy client id present in clients or channels table?
    const CPVRClientUID uid{addonID, instanceID};
    int legacyID{uid.GetLegacyUID()};
    std::string sql{PrepareSQL("idClient = %i", legacyID)};
    int id{GetSingleValueInt("clients", "idClient", sql)};
    if (id == legacyID)
    {
      // Add addon id and instance id to existing clients table entry.
      sql = PrepareSQL("UPDATE clients SET sAddonID = '%s', iInstanceID = %i WHERE idClient = %i",
                       addonID.c_str(), instanceID, legacyID);
      ExecuteQuery(sql);
    }
    else
    {
      sql = PrepareSQL("iClientId = %i", legacyID);
      id = GetSingleValueInt("channels", "iClientId", sql);
      if (id == legacyID)
      {
        // Create a new entry with the legacy client id in clients table.
        sql = PrepareSQL("REPLACE INTO clients (idClient, iPriority, sAddonID, iInstanceID) VALUES "
                         "(%i, %i, '%s', %i)",
                         legacyID, 0, addonID.c_str(), instanceID);
        ExecuteQuery(sql);
      }
      else
      {