videodb: add DeleteSeason()
authormontellese <montellese@xbmc.org>
Thu, 15 May 2014 22:04:57 +0000 (00:04 +0200)
committermontellese <montellese@xbmc.org>
Thu, 15 May 2014 22:04:57 +0000 (00:04 +0200)
xbmc/video/VideoDatabase.cpp
xbmc/video/VideoDatabase.h

index e5e9925..59dea3f 100644 (file)
@@ -3007,6 +3007,49 @@ void CVideoDatabase::DeleteTvShow(const CStdString& strPath, bool bKeepId /* = f
   }
 }
 
+void CVideoDatabase::DeleteSeason(int idSeason, bool bKeepId /* = false */)
+{
+  if (idSeason < 0)
+    return;
+
+  try
+  {
+    if (m_pDB.get() == NULL ||
+        m_pDS.get() == NULL ||
+        m_pDS2.get() == NULL)
+      return;
+
+    BeginTransaction();
+
+    CStdString strSQL = PrepareSQL("SELECT episode.idEpisode, path.strPath, files.strFileName FROM episode "
+                                   "JOIN seasons ON seasons.idSeason = %d AND episode.idShow = seasons.idShow AND episode.c%02d = seasons.season "
+                                   "JOIN files ON files.idFile = episode.idFile "
+                                   "JOIN path ON path.idPath = files.idPath",
+                                   idSeason, VIDEODB_ID_EPISODE_SEASON);
+    m_pDS2->query(strSQL.c_str());
+    while (!m_pDS2->eof())
+    {
+      CStdString strPath = m_pDS2->fv("path.strPath").get_asString();
+      CStdString strFileName = m_pDS2->fv("files.strFilename").get_asString();
+
+      CStdString strFilenameAndPath;
+      ConstructPath(strFilenameAndPath, strPath, strFileName);
+
+      DeleteEpisode(strFilenameAndPath, m_pDS2->fv(0).get_asInt(), bKeepId);
+      m_pDS2->next();
+    }
+
+    ExecuteQuery(PrepareSQL("DELETE FROM seasons WHERE idSeason = %i", idSeason));
+
+    CommitTransaction();
+  }
+  catch (...)
+  {
+    CLog::Log(LOGERROR, "%s (%d) failed", __FUNCTION__, idSeason);
+    RollbackTransaction();
+  }
+}
+
 void CVideoDatabase::DeleteEpisode(int idEpisode, bool bKeepId /* = false */)
 {
   if (idEpisode < 0)
index d626944..694e501 100644 (file)
@@ -481,6 +481,7 @@ public:
   void DeleteMovie(const CStdString& strFilenameAndPath, bool bKeepId = false, int idMovie = -1);
   void DeleteTvShow(int idTvShow, bool bKeepId = false);
   void DeleteTvShow(const CStdString& strPath, bool bKeepId = false, int idTvShow = -1);
+  void DeleteSeason(int idSeason, bool bKeepId = false);
   void DeleteEpisode(int idEpisode, bool bKeepId = false);
   void DeleteEpisode(const CStdString& strFilenameAndPath, int idEpisode = -1, bool bKeepId = false);
   void DeleteMusicVideo(int idMusicVideo, bool bKeepId = false);