Skip to content

Commit

Permalink
Add idSeason to episode table
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Oct 9, 2015
1 parent 8b88a4b commit 974668e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
43 changes: 34 additions & 9 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -161,7 +161,7 @@ void CVideoDatabase::CreateTables()

columns += column;
}
columns += ", idShow integer, userrating integer)";
columns += ", idShow integer, userrating integer, idSeason integer)";
m_pDS->exec(columns);

CLog::Log(LOGINFO, "create tvshowlinkpath table");
Expand Down Expand Up @@ -348,22 +348,21 @@ void CVideoDatabase::CreateViews()
" tvshow.c%02d AS premiered,"
" tvshow.c%02d AS mpaa,"
" bookmark.timeInSeconds AS resumeTimeInSeconds, "
" bookmark.totalTimeInSeconds AS totalTimeInSeconds, "
" seasons.idSeason AS idSeason "
" bookmark.totalTimeInSeconds AS totalTimeInSeconds "
"FROM episode"
" JOIN files ON"
" files.idFile=episode.idFile"
" JOIN tvshow ON"
" tvshow.idShow=episode.idShow"
" LEFT JOIN seasons ON"
" seasons.idShow=episode.idShow AND seasons.season=episode.c%02d"
" JOIN seasons ON"
" seasons.idSeason=episode.idSeason"
" JOIN path ON"
" files.idPath=path.idPath"
" LEFT JOIN bookmark ON"
" bookmark.idFile=episode.idFile AND bookmark.type=1",
VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_GENRE,
VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED,
VIDEODB_ID_TV_MPAA, VIDEODB_ID_EPISODE_SEASON);
VIDEODB_ID_TV_MPAA);
m_pDS->exec(episodeview);

CLog::Log(LOGINFO, "create tvshowcounts");
Expand Down Expand Up @@ -2459,13 +2458,18 @@ int CVideoDatabase::SetDetailsForEpisode(const std::string& strFilenameAndPath,
}

// ensure we have this season already added
AddSeason(idShow, details.m_iSeason);
int idSeason = AddSeason(idShow, details.m_iSeason);

SetArtForItem(idEpisode, MediaTypeEpisode, artwork);

if (details.m_iEpisode != -1 && details.m_iSeason != -1)
{ // query DB for any episodes matching idShow, Season and Episode
std::string strSQL = PrepareSQL("SELECT files.playCount, files.lastPlayed FROM episode INNER JOIN files ON files.idFile=episode.idFile WHERE episode.c%02d=%i AND episode.c%02d=%i AND episode.idShow=%i AND episode.idEpisode!=%i AND files.playCount > 0", VIDEODB_ID_EPISODE_SEASON, details.m_iSeason, VIDEODB_ID_EPISODE_EPISODE, details.m_iEpisode, idShow, idEpisode);
std::string strSQL = PrepareSQL("SELECT files.playCount, files.lastPlayed "
"FROM episode INNER JOIN files ON files.idFile=episode.idFile "
"WHERE episode.c%02d=%i AND episode.c%02d=%i AND episode.idShow=%i "
"AND episode.idEpisode!=%i AND files.playCount > 0",
VIDEODB_ID_EPISODE_SEASON, details.m_iSeason, VIDEODB_ID_EPISODE_EPISODE,
details.m_iEpisode, idShow, idEpisode);
m_pDS->query(strSQL);

if (!m_pDS->eof())
Expand All @@ -2490,6 +2494,7 @@ int CVideoDatabase::SetDetailsForEpisode(const std::string& strFilenameAndPath,
sql += PrepareSQL(", userrating = %i", details.m_iUserRating);
else
sql += ", userrating = NULL";
sql += PrepareSQL(", idSeason = %i", idSeason);
sql += PrepareSQL(" where idEpisode=%i", idEpisode);
m_pDS->exec(sql);
CommitTransaction();
Expand Down Expand Up @@ -4655,11 +4660,31 @@ void CVideoDatabase::UpdateTables(int iVersion)

if (iVersion < 98)
m_pDS->exec("ALTER TABLE seasons ADD name text");

if (iVersion < 99)
{
// Add idSeason to episode table, so we don't have to join via idShow and season in the future
m_pDS->exec("ALTER TABLE episode ADD idSeason integer");

m_pDS->query("SELECT idSeason, idShow, season FROM seasons");
while (!m_pDS->eof())
{
m_pDS2->exec(PrepareSQL("UPDATE episode "
"SET idSeason = %d "
"WHERE "
"episode.idShow = %d AND "
"episode.c%02d = %d",
m_pDS->fv(0).get_asInt(), m_pDS->fv(1).get_asInt(),
VIDEODB_ID_EPISODE_SEASON, m_pDS->fv(2).get_asInt()));

m_pDS->next();
}
}
}

int CVideoDatabase::GetSchemaVersion() const
{
return 98;
return 99;
}

bool CVideoDatabase::LookupByFolders(const std::string &path, bool shows)
Expand Down
31 changes: 18 additions & 13 deletions xbmc/video/VideoDatabase.h
Expand Up @@ -86,19 +86,19 @@ namespace VIDEO

#define VIDEODB_DETAILS_EPISODE_TVSHOW_ID VIDEODB_MAX_COLUMNS + 2
#define VIDEODB_DETAILS_EPISODE_USER_RATING VIDEODB_MAX_COLUMNS + 3
#define VIDEODB_DETAILS_EPISODE_FILE VIDEODB_MAX_COLUMNS + 4
#define VIDEODB_DETAILS_EPISODE_PATH VIDEODB_MAX_COLUMNS + 5
#define VIDEODB_DETAILS_EPISODE_PLAYCOUNT VIDEODB_MAX_COLUMNS + 6
#define VIDEODB_DETAILS_EPISODE_LASTPLAYED VIDEODB_MAX_COLUMNS + 7
#define VIDEODB_DETAILS_EPISODE_DATEADDED VIDEODB_MAX_COLUMNS + 8
#define VIDEODB_DETAILS_EPISODE_TVSHOW_NAME VIDEODB_MAX_COLUMNS + 9
#define VIDEODB_DETAILS_EPISODE_TVSHOW_GENRE VIDEODB_MAX_COLUMNS + 10
#define VIDEODB_DETAILS_EPISODE_TVSHOW_STUDIO VIDEODB_MAX_COLUMNS + 11
#define VIDEODB_DETAILS_EPISODE_TVSHOW_AIRED VIDEODB_MAX_COLUMNS + 12
#define VIDEODB_DETAILS_EPISODE_TVSHOW_MPAA VIDEODB_MAX_COLUMNS + 13
#define VIDEODB_DETAILS_EPISODE_RESUME_TIME VIDEODB_MAX_COLUMNS + 14
#define VIDEODB_DETAILS_EPISODE_TOTAL_TIME VIDEODB_MAX_COLUMNS + 15
#define VIDEODB_DETAILS_EPISODE_SEASON_ID VIDEODB_MAX_COLUMNS + 16
#define VIDEODB_DETAILS_EPISODE_SEASON_ID VIDEODB_MAX_COLUMNS + 4
#define VIDEODB_DETAILS_EPISODE_FILE VIDEODB_MAX_COLUMNS + 5
#define VIDEODB_DETAILS_EPISODE_PATH VIDEODB_MAX_COLUMNS + 6
#define VIDEODB_DETAILS_EPISODE_PLAYCOUNT VIDEODB_MAX_COLUMNS + 7
#define VIDEODB_DETAILS_EPISODE_LASTPLAYED VIDEODB_MAX_COLUMNS + 8
#define VIDEODB_DETAILS_EPISODE_DATEADDED VIDEODB_MAX_COLUMNS + 9
#define VIDEODB_DETAILS_EPISODE_TVSHOW_NAME VIDEODB_MAX_COLUMNS + 10
#define VIDEODB_DETAILS_EPISODE_TVSHOW_GENRE VIDEODB_MAX_COLUMNS + 11
#define VIDEODB_DETAILS_EPISODE_TVSHOW_STUDIO VIDEODB_MAX_COLUMNS + 12
#define VIDEODB_DETAILS_EPISODE_TVSHOW_AIRED VIDEODB_MAX_COLUMNS + 13
#define VIDEODB_DETAILS_EPISODE_TVSHOW_MPAA VIDEODB_MAX_COLUMNS + 14
#define VIDEODB_DETAILS_EPISODE_RESUME_TIME VIDEODB_MAX_COLUMNS + 15
#define VIDEODB_DETAILS_EPISODE_TOTAL_TIME VIDEODB_MAX_COLUMNS + 16

#define VIDEODB_DETAILS_TVSHOW_USER_RATING VIDEODB_MAX_COLUMNS + 1
#define VIDEODB_DETAILS_TVSHOW_PARENTPATHID VIDEODB_MAX_COLUMNS + 2
Expand Down Expand Up @@ -798,6 +798,11 @@ class CVideoDatabase : public CDatabase

virtual bool GetFilter(CDbUrl &videoUrl, Filter &filter, SortDescription &sorting);

/*! \brief Will check if the season exists and if that is not the case add it to the database.
\param showID The id of the show in question.
\param season The season number we want to add.
\return The dbId of the season.
*/
int AddSeason(int showID, int season);
int AddSet(const std::string& strSet, const std::string& strOverview = "");
void ClearMovieSet(int idMovie);
Expand Down

0 comments on commit 974668e

Please sign in to comment.