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

Code before:
                                                         : "NULL"};
    const std::string lastPlayed{fileInfo.m_lastPlayed.IsValid()
                                     ? "'" + fileInfo.m_lastPlayed.GetAsDBDateTime() + "'"
                                     : "NULL"};

    sql = PrepareSQL("SELECT idFile FROM files WHERE strFileName = '%s' AND idPath=%i",
                     strFileName.c_str(), idPath);

    m_pDS->query(sql);
    if (m_pDS->num_rows() > 0)
    {
      const int idFile{m_pDS->fv("idFile").get_asInt()};
      m_pDS->close();

      if (existsAction == FileExistsAction::UPDATE)
      {
        sql = PrepareSQL("UPDATE files "
                         "SET playCount = " +
                             playCount +
                             ", "
                             "lastPlayed = " +
                             lastPlayed +
                             ", "
                             "dateAdded = '%s' "
                             "WHERE idFile = %i",
                         finalDateAdded.GetAsDBDateTime().c_str(), idFile);

        m_pDS->exec(sql);
      }

      return idFile;
    }

    m_pDS->close();

    sql = PrepareSQL(
        "INSERT INTO files (idFile, idPath, strFileName, playCount, lastPlayed, dateAdded) "
        "VALUES(NULL, %i, '%s', " +
            playCount + ", " + lastPlayed + ", '%s')",
        idPath, strFileName.c_str(), finalDateAdded.GetAsDBDateTime().c_str());

    m_pDS->exec(sql);

    return static_cast<int>(m_pDS->lastinsertid());
  }
  catch (...)
  {
    CLog::LogF(LOGERROR, "unable to add or update file ({})", sql);
  }
  return -1;
}

Review comment (suggestion):
clang-format requires this? strange. you could try m_pDS->exec(PrepareSQL(...)) in case it looks better.

Code after:
                                                         : "NULL"};
    const std::string lastPlayed{fileInfo.m_lastPlayed.IsValid()
                                     ? "'" + fileInfo.m_lastPlayed.GetAsDBDateTime() + "'"
                                     : "NULL"};

    sql = PrepareSQL("SELECT idFile FROM files WHERE strFileName = '%s' AND idPath=%i",
                     strFileName.c_str(), idPath);

    m_pDS->query(sql);
    if (m_pDS->num_rows() > 0)
    {
      const int idFile{m_pDS->fv("idFile").get_asInt()};
      m_pDS->close();

      if (existsAction == FileExistsAction::ACTION_UPDATE)
      {
        sql = PrepareSQL("UPDATE files "
                         "SET playCount = " +
                             playCount +
                             ", "
                             "lastPlayed = " +
                             lastPlayed +
                             ", "
                             "dateAdded = '%s' "
                             "WHERE idFile = %i",
                         finalDateAdded.GetAsDBDateTime().c_str(), idFile);

        m_pDS->exec(sql);
      }

      return idFile;
    }

    m_pDS->close();

    sql = PrepareSQL(
        "INSERT INTO files (idFile, idPath, strFileName, playCount, lastPlayed, dateAdded) "
        "VALUES(NULL, %i, '%s', " +
            playCount + ", " + lastPlayed + ", '%s')",
        idPath, strFileName.c_str(), finalDateAdded.GetAsDBDateTime().c_str());

    m_pDS->exec(sql);

    return static_cast<int>(m_pDS->lastinsertid());
  }
  catch (...)
  {
    CLog::LogF(LOGERROR, "unable to add or update file ({})", sql);
  }
  return -1;
}