Permalink
Browse files

videodb: only allow one set per movie

  • Loading branch information...
Montellese committed Jun 28, 2012
1 parent 5abd62b commit 1a535fd5a6651dbb21a66afd65636314a085d860
@@ -825,7 +825,7 @@ void CVideoLibrary::UpdateVideoTag(const CVariant &parameterObject, CVideoInfoTa
if (ParameterNotNull(parameterObject, "episodeguide"))
details.m_strEpisodeGuide = parameterObject["episodeguide"].asString();
if (ParameterNotNull(parameterObject, "set"))
CopyStringArray(parameterObject["set"], details.m_set);
details.m_strSet = parameterObject["set"].asString();
if (ParameterNotNull(parameterObject, "showlink"))
CopyStringArray(parameterObject["showlink"], details.m_showLink);
if (ParameterNotNull(parameterObject, "thumbnail"))
@@ -177,6 +177,7 @@ std::string DatabaseUtils::GetField(Field field, MediaType mediaType, DatabaseQu
else if (field == FieldTime) result.Format("movieview.c%02d", VIDEODB_ID_RUNTIME);
else if (field == FieldMPAA) result.Format("movieview.c%02d", VIDEODB_ID_MPAA);
else if (field == FieldTop250) result.Format("movieview.c%02d", VIDEODB_ID_TOP250);
else if (field == FieldSet) return "movieview.strSet";
else if (field == FieldGenre) result.Format("movieview.c%02d", VIDEODB_ID_GENRE);
else if (field == FieldDirector) result.Format("movieview.c%02d", VIDEODB_ID_DIRECTOR);
else if (field == FieldStudio) result.Format("movieview.c%02d", VIDEODB_ID_STUDIOS);
@@ -340,6 +341,7 @@ int DatabaseUtils::GetFieldIndex(Field field, MediaType mediaType)
else if (field == FieldTime) index = VIDEODB_ID_RUNTIME;
else if (field == FieldMPAA) index = VIDEODB_ID_MPAA;
else if (field == FieldTop250) index = VIDEODB_ID_TOP250;
else if (field == FieldSet) return VIDEODB_DETAILS_SET_NAME;
else if (field == FieldGenre) index = VIDEODB_ID_GENRE;
else if (field == FieldDirector) index = VIDEODB_ID_DIRECTOR;
else if (field == FieldStudio) index = VIDEODB_ID_STUDIOS;
@@ -53,7 +53,6 @@ typedef enum {
FieldBitrate,
FieldListeners,
FieldPlaylist,
FieldSet,
FieldRandom,

// fields retrievable from the database
@@ -87,6 +86,7 @@ typedef enum {
FieldCountry,
FieldMPAA,
FieldTop250,
FieldSet,
FieldNumberOfEpisodes,
FieldNumberOfWatchedEpisodes,
FieldWriter,
@@ -136,7 +136,7 @@ bool CVideoDatabase::CreateTables()
column.Format(",c%02d text", i);
columns += column;
}
columns += ")";
columns += ", idSet integer)";
m_pDS->exec(columns.c_str());
m_pDS->exec("CREATE UNIQUE INDEX ix_movie_file_1 ON movie (idFile, idMovie)");
m_pDS->exec("CREATE UNIQUE INDEX ix_movie_file_2 ON movie (idMovie, idFile)");
@@ -298,11 +298,6 @@ bool CVideoDatabase::CreateTables()
CLog::Log(LOGINFO, "create sets table");
m_pDS->exec("CREATE TABLE sets ( idSet integer primary key, strSet text)\n");

CLog::Log(LOGINFO, "create setlinkmovie table");
m_pDS->exec("CREATE TABLE setlinkmovie ( idSet integer, idMovie integer)\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_setlinkmovie_1 ON setlinkmovie ( idSet, idMovie)\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_setlinkmovie_2 ON setlinkmovie ( idMovie, idSet)\n");

// create basepath indices
m_pDS->exec("CREATE INDEX ixMovieBasePath ON movie ( c23(12) )");
m_pDS->exec("CREATE INDEX ixMusicVideoBasePath ON musicvideo ( c14(12) )");
@@ -423,6 +418,7 @@ void CVideoDatabase::CreateViews()
m_pDS->exec("DROP VIEW IF EXISTS movieview");
m_pDS->exec("CREATE VIEW movieview AS SELECT"
" movie.*,"
" sets.strSet AS strSet,"
" files.strFileName AS strFileName,"
" path.strPath AS strPath,"
" files.playCount AS playCount,"
@@ -431,6 +427,8 @@ void CVideoDatabase::CreateViews()
" bookmark.timeInSeconds AS resumeTimeInSeconds, "
" bookmark.totalTimeInSeconds AS totalTimeInSeconds "
"FROM movie"
" LEFT JOIN sets ON"
" sets.idSet = movie.idSet"
" JOIN files ON"
" files.idFile=movie.idFile"
" JOIN path ON"
@@ -1275,6 +1273,9 @@ int CVideoDatabase::AddToTable(const CStdString& table, const CStdString& firstF

int CVideoDatabase::AddSet(const CStdString& strSet)
{
if (strSet.empty())
return -1;

return AddToTable("sets", "idSet", "strSet", strSet);
}

@@ -1413,11 +1414,6 @@ void CVideoDatabase::RemoveFromLinkTable(const char *table, const char *firstFie
}
}

//****Sets****
void CVideoDatabase::AddSetToMovie(int idMovie, int idSet)
{
AddToLinkTable("setlinkmovie", "idSet", idSet, "idMovie", idMovie);
}
//****Tags****
void CVideoDatabase::AddTagToItem(int idMovie, int idTag, const std::string &type)
{
@@ -1947,16 +1943,12 @@ int CVideoDatabase::SetDetailsForMovie(const CStdString& strFilenameAndPath, con
AddActorToMovie(idMovie, idActor, it->strRole, order++);
}

// add sets...
for (unsigned int i = 0; i < details.m_set.size(); i++)
{
int idSet = AddSet(details.m_set[i]);
// add art if not available
map<string, string> setArt;
if (!GetArtForItem(idSet, "set", setArt))
SetArtForItem(idSet, "set", artwork);
AddSetToMovie(idMovie, idSet);
}
// add set...
int idSet = AddSet(details.m_strSet);
// add art if not available
map<string, string> setArt;
if (!GetArtForItem(idSet, "set", setArt))
SetArtForItem(idSet, "set", artwork);

// add tags...
for (unsigned int i = 0; i < details.m_tags.size(); i++)
@@ -1977,6 +1969,10 @@ int CVideoDatabase::SetDetailsForMovie(const CStdString& strFilenameAndPath, con
// update our movie table (we know it was added already above)
// and insert the new row
CStdString sql = "update movie set " + GetValueString(details, VIDEODB_ID_MIN, VIDEODB_ID_MAX, DbMovieOffsets);
if (idSet > 0)
sql += PrepareSQL(", idSet = %i", idSet);
else
sql += ", idSet = NULL";
sql += PrepareSQL(" where idMovie=%i", idMovie);
m_pDS->exec(sql.c_str());
CommitTransaction();
@@ -2654,9 +2650,6 @@ void CVideoDatabase::DeleteMovie(const CStdString& strFilenameAndPath, bool bKee
strSQL=PrepareSQL("delete from studiolinkmovie where idMovie=%i", idMovie);
m_pDS->exec(strSQL.c_str());

strSQL=PrepareSQL("delete from setlinkmovie where idMovie=%i", idMovie);
m_pDS->exec(strSQL.c_str());

strSQL=PrepareSQL("delete from countrylinkmovie where idMovie=%i", idMovie);
m_pDS->exec(strSQL.c_str());

@@ -2894,9 +2887,9 @@ void CVideoDatabase::DeleteSet(int idSet)
if (NULL == m_pDS.get()) return ;

CStdString strSQL;
strSQL=PrepareSQL("delete from sets where idSet=%i", idSet);
strSQL=PrepareSQL("delete from sets where idSet = %i", idSet);
m_pDS->exec(strSQL.c_str());
strSQL=PrepareSQL("delete from setlinkmovie where idSet=%i", idSet);
strSQL=PrepareSQL("update movie set idSet = null where idSet = %i", idSet);
m_pDS->exec(strSQL.c_str());
}
catch (...)
@@ -3139,19 +3132,8 @@ CVideoInfoTag CVideoDatabase::GetDetailsForMovie(const dbiplus::sql_record* cons
castTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
details.m_strPictureURL.Parse();

// create sets string
CStdString strSQL = PrepareSQL("SELECT sets.idSet, sets.strSet FROM sets,setlinkmovie WHERE setlinkmovie.idMovie=%i AND setlinkmovie.idSet=sets.idSet ORDER BY sets.idSet",idMovie);
m_pDS2->query(strSQL.c_str());
while (!m_pDS2->eof())
{
details.m_set.push_back(m_pDS2->fv("sets.strSet").get_asString());
details.m_setId.push_back(m_pDS2->fv("sets.idSet").get_asInt());

m_pDS2->next();
}

// get tags
strSQL = PrepareSQL("SELECT tag.strTag FROM tag, taglinks WHERE taglinks.idMedia = %i AND taglinks.media_type = 'movie' AND taglinks.idTag = tag.idTag ORDER BY tag.idTag", idMovie);
CStdString strSQL = PrepareSQL("SELECT tag.strTag FROM tag, taglinks WHERE taglinks.idMedia = %i AND taglinks.media_type = 'movie' AND taglinks.idTag = tag.idTag ORDER BY tag.idTag", idMovie);
m_pDS2->query(strSQL.c_str());
while (!m_pDS2->eof())
{
@@ -3164,7 +3146,7 @@ CVideoInfoTag CVideoDatabase::GetDetailsForMovie(const dbiplus::sql_record* cons
GetLinksToTvShow(idMovie,links);
for (unsigned int i=0;i<links.size();++i)
{
strSQL = PrepareSQL("select c%02d from tvshow where idShow=%i",
CStdString strSQL = PrepareSQL("select c%02d from tvshow where idShow=%i",
VIDEODB_ID_TV_TITLE,links[i]);
m_pDS2->query(strSQL.c_str());
if (!m_pDS2->eof())
@@ -3296,6 +3278,8 @@ void CVideoDatabase::GetCommonDetails(auto_ptr<Dataset> &pDS, CVideoInfoTag &det

void CVideoDatabase::GetCommonDetails(const dbiplus::sql_record* const record, CVideoInfoTag &details)
{
details.m_iSetId = record->at(VIDEODB_DETAILS_SET_ID).get_asInt();
details.m_strSet = record->at(VIDEODB_DETAILS_SET_NAME).get_asInt();
details.m_iFileId = record->at(VIDEODB_DETAILS_FILEID).get_asInt();
details.m_strPath = record->at(VIDEODB_DETAILS_PATH).get_asString();
CStdString strFileName = record->at(VIDEODB_DETAILS_FILE).get_asString();
@@ -4011,6 +3995,19 @@ bool CVideoDatabase::UpdateOldVersion(int iVersion)
m_pDS->exec("CREATE UNIQUE INDEX ix_taglinks_2 ON taglinks (idMedia, media_type(20), idTag)");
m_pDS->exec("CREATE INDEX ix_taglinks_3 ON taglinks (media_type(20))");
}
if (iVersion < 68)
{ // add idSet to movie table
m_pDS->exec("ALTER TABLE movie ADD idSet integer");
m_pDS->query("SELECT idMovie FROM movie");
while (!m_pDS->eof())
{
int idMovie = m_pDS->fv(0).get_asInt();
CStdString sql = PrepareSQL("UPDATE movie SET idSet=(SELECT idSet FROM setlinkmovie WHERE idMovie = %d LIMIT 1) WHERE idMovie = %d", idMovie, idMovie);
m_pDS2->exec(sql.c_str());
m_pDS->next();
}
m_pDS->exec("DROP TABLE IF EXISTS setlinkmovie");
}
// always recreate the view after any table change
CreateViews();
return true;
@@ -4582,10 +4579,8 @@ bool CVideoDatabase::GetSetsByWhere(const CStdString& strBaseDir, const Filter &
if (!videoUrl.FromString(strBaseDir))
return false;

CStdString strSQL = "SELECT movieview.*, sets.idSet, sets.strSet FROM movieview"
" JOIN setlinkmovie ON movieview.idMovie = setlinkmovie.idMovie"
" JOIN sets ON setlinkmovie.idSet = sets.idSet"
" JOIN (SELECT idSet, COUNT(1) AS c FROM setlinkmovie GROUP BY idSet HAVING c>1) s2 ON s2.idSet = sets.idSet ";
CStdString strSQL = "SELECT movieview.*, sets.strSet FROM movieview"
" JOIN sets ON movieview.idSet = sets.idSet ";
if (!filter.join.empty())
strSQL += filter.join;
if (!filter.where.empty())
@@ -4609,7 +4604,7 @@ bool CVideoDatabase::GetSetsByWhere(const CStdString& strBaseDir, const Filter &
continue;

// get the setid and check if we already have this set
int idSet = m_pDS->fv("sets.idSet").get_asInt();
int idSet = m_pDS->fv("movieview.idSet").get_asInt();
if ((it = mapSets.find(idSet)) == mapSets.end())
{
// add the set to the list of sets
@@ -5530,7 +5525,7 @@ bool CVideoDatabase::GetMoviesByWhere(const CStdString& strBaseDir, const Filter
CStdString movieSetsWhere;
if (setItems.Size() > 0)
{
movieSetsWhere = "movieview.idMovie NOT IN (SELECT idMovie FROM setlinkmovie s1 JOIN(SELECT idSet, COUNT(1) AS c FROM setlinkmovie GROUP BY idSet HAVING c>1) s2 ON s2.idSet=s1.idSet WHERE s1.idSet IN (";
movieSetsWhere = "movieview.idMovie NOT IN (SELECT idMovie FROM movieview WHERE movieview.idSet IN (";
for (int index = 0; index < setItems.Size(); index++)
movieSetsWhere.AppendFormat("%s%d", index > 0 ? "," : "", setItems[index]->GetVideoInfoTag()->m_iDbId);
movieSetsWhere += "))";
@@ -6135,10 +6130,9 @@ bool CVideoDatabase::HasSets() const
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;

m_pDS->query("SELECT sets.idSet,COUNT(1) AS c FROM sets "
"JOIN setlinkmovie ON sets.idSet=setlinkmovie.idSet "
"JOIN movie ON setlinkmovie.idMovie=movie.idMovie "
"GROUP BY sets.idSet HAVING c>1");
m_pDS->query("SELECT movieview.idSet,COUNT(1) AS c FROM movieview "
"JOIN sets ON sets.idSet = movieview.idSet "
"GROUP BY movieview.idSet HAVING c>1");

bool bResult = (m_pDS->num_rows() > 0);
m_pDS->close();
@@ -7008,9 +7002,9 @@ void CVideoDatabase::GetMoviesByName(const CStdString& strSearch, CFileItemList&
if (NULL == m_pDS.get()) return;

if (g_settings.GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
strSQL = PrepareSQL("select movie.idMovie,movie.c%02d,path.strPath from movie,files,path where files.idFile=movie.idFile and files.idPath=path.idPath and movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
strSQL = PrepareSQL("select movie.idMovie,movie.c%02d,path.strPath, movie.idSet from movie,files,path where files.idFile=movie.idFile and files.idPath=path.idPath and movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
else
strSQL = PrepareSQL("select movie.idMovie,movie.c%02d from movie where movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
strSQL = PrepareSQL("select movie.idMovie,movie.c%02d, movie.idSet from movie where movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
m_pDS->query( strSQL.c_str() );

while (!m_pDS->eof())
@@ -7023,18 +7017,16 @@ void CVideoDatabase::GetMoviesByName(const CStdString& strSearch, CFileItemList&
}

int movieId = m_pDS->fv("movie.idMovie").get_asInt();
CStdString strSQL2 = PrepareSQL("select idSet from setlinkmovie where idMovie=%i",movieId);
m_pDS2->query(strSQL2.c_str());
int setId = m_pDS->fv("movie.idSet").get_asInt();
CFileItemPtr pItem(new CFileItem(m_pDS->fv(1).get_asString()));
CStdString path;
if (m_pDS2->eof())
path.Format("videodb://1/2/%i",movieId);
if (setId <= 0)
path.Format("videodb://1/2/%i", movieId);
else
path.Format("videodb://1/7/%i/%i",m_pDS2->fv(0).get_asInt(),movieId);
path.Format("videodb://1/7/%i/%i", setId, movieId);
pItem->SetPath(path);
pItem->m_bIsFolder=false;
items.Add(pItem);
m_pDS2->close();
m_pDS->next();
}
m_pDS->close();
@@ -7610,10 +7602,6 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s
CLog::Log(LOGDEBUG, "%s: Cleaning studiolinkmovie table", __FUNCTION__);
sql = "delete from studiolinkmovie where idMovie in " + moviesToDelete;
m_pDS->exec(sql.c_str());

CLog::Log(LOGDEBUG, "%s: Cleaning setlinkmovie table", __FUNCTION__);
sql = "delete from setlinkmovie where idMovie in " + moviesToDelete;
m_pDS->exec(sql.c_str());
}

if ( ! episodesToDelete.IsEmpty() )
@@ -7756,7 +7744,7 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s
m_pDS->exec(sql.c_str());

CLog::Log(LOGDEBUG, "%s: Cleaning set table", __FUNCTION__);
sql = "delete from sets where idSet not in (select distinct idSet from setlinkmovie)";
sql = "delete from sets where idSet not in (select distinct idSet from movie)";
m_pDS->exec(sql.c_str());

CommitTransaction();
@@ -8849,10 +8837,7 @@ bool CVideoDatabase::GetFilter(const CVideoDbUrl &videoUrl, Filter &filter) cons

option = options.find("setid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join setlinkmovie on setlinkmovie.idMovie = movieview.idMovie"));
filter.AppendWhere(PrepareSQL("setlinkmovie.idSet = %i", (int)option->second.asInteger()));
}
filter.AppendWhere(PrepareSQL("movieview.idSet = %i", (int)option->second.asInteger()));

option = options.find("tagid");
if (option != options.end())
@@ -69,13 +69,15 @@ namespace VIDEO
// when we do GetDetailsForMovie()
#define VIDEODB_MAX_COLUMNS 24
#define VIDEODB_DETAILS_FILEID 1
#define VIDEODB_DETAILS_FILE VIDEODB_MAX_COLUMNS + 2
#define VIDEODB_DETAILS_PATH VIDEODB_MAX_COLUMNS + 3
#define VIDEODB_DETAILS_PLAYCOUNT VIDEODB_MAX_COLUMNS + 4
#define VIDEODB_DETAILS_LASTPLAYED VIDEODB_MAX_COLUMNS + 5
#define VIDEODB_DETAILS_DATEADDED VIDEODB_MAX_COLUMNS + 6
#define VIDEODB_DETAILS_RESUME_TIME VIDEODB_MAX_COLUMNS + 7
#define VIDEODB_DETAILS_TOTAL_TIME VIDEODB_MAX_COLUMNS + 8
#define VIDEODB_DETAILS_SET_ID VIDEODB_MAX_COLUMNS + 2
#define VIDEODB_DETAILS_SET_NAME VIDEODB_MAX_COLUMNS + 3
#define VIDEODB_DETAILS_FILE VIDEODB_MAX_COLUMNS + 4
#define VIDEODB_DETAILS_PATH VIDEODB_MAX_COLUMNS + 5
#define VIDEODB_DETAILS_PLAYCOUNT VIDEODB_MAX_COLUMNS + 6
#define VIDEODB_DETAILS_LASTPLAYED VIDEODB_MAX_COLUMNS + 7
#define VIDEODB_DETAILS_DATEADDED VIDEODB_MAX_COLUMNS + 8
#define VIDEODB_DETAILS_RESUME_TIME VIDEODB_MAX_COLUMNS + 9
#define VIDEODB_DETAILS_TOTAL_TIME VIDEODB_MAX_COLUMNS + 10

#define VIDEODB_DETAILS_EPISODE_TVSHOW_ID VIDEODB_MAX_COLUMNS + 2
#define VIDEODB_DETAILS_EPISODE_FILE VIDEODB_MAX_COLUMNS + 3
@@ -710,8 +712,6 @@ class CVideoDatabase : public CDatabase
void AddToLinkTable(const char *table, const char *firstField, int firstID, const char *secondField, int secondID, const char *typeField = NULL, const char *type = NULL);
void RemoveFromLinkTable(const char *table, const char *firstField, int firstID, const char *secondField, int secondID, const char *typeField = NULL, const char *type = NULL);

void AddSetToMovie(int idMovie, int idSet);

void AddActorToMovie(int idMovie, int idActor, const CStdString& strRole, int order);
void AddActorToTvShow(int idTvShow, int idActor, const CStdString& strRole, int order);
void AddActorToEpisode(int idEpisode, int idActor, const CStdString& strRole, int order);
@@ -797,7 +797,7 @@ class CVideoDatabase : public CDatabase
*/
bool LookupByFolders(const CStdString &path, bool shows = false);

virtual int GetMinVersion() const { return 67; };
virtual int GetMinVersion() const { return 68; };
virtual int GetExportVersion() const { return 1; };
const char *GetBaseDBName() const { return "MyVideos"; };

Oops, something went wrong.

0 comments on commit 1a535fd

Please sign in to comment.