aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Kerling <pkerling@casix.org>2019-01-12 10:24:31 +0100
committerPhilipp Kerling <pkerling@casix.org>2019-01-12 10:24:31 +0100
commitfeaeaec5189265d125ab80cb6c8572100ca0c852 (patch)
tree3eb18685c0ae347c53aabcf3dcc3a76b5cb18676
parent1c7bd27c297f6e78e2463cd3844f4d6acf08e683 (diff)
[database] Move join subquery into separate view for ancient MySQL
So it seems MySQL < 5.7 cannot perform subqueries in SQL FROM. As a workaround, put the subquery into a separate view.
-rw-r--r--xbmc/video/VideoDatabase.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp
index 3a1d66242e..28f88c5b83 100644
--- a/xbmc/video/VideoDatabase.cpp
+++ b/xbmc/video/VideoDatabase.cpp
@@ -397,6 +397,20 @@ void CVideoDatabase::CreateViews()
"GROUP BY tvshow.idShow");
m_pDS->exec(tvshowcounts);
+ CLog::Log(LOGINFO, "create tvshowlinkpath_minview");
+ // This view only exists to workaround a limitation in MySQL <5.7 which is not able to
+ // perform subqueries in joins.
+ // Also, the correct solution is to remove the path information altogether, since a
+ // TV series can always have multiple paths. It is used in the GUI at the moment, but
+ // such usage should be removed together with this view and the path columns in tvshow_view.
+ //!@todo Remove the hacky selection of a semi-random path for tvshows from the queries and UI
+ std::string tvshowlinkpathview = PrepareSQL("CREATE VIEW tvshowlinkpath_minview AS SELECT "
+ " idShow, "
+ " min(idPath) AS idPath "
+ "FROM tvshowlinkpath "
+ "GROUP BY idShow");
+ m_pDS->exec(tvshowlinkpathview);
+
CLog::Log(LOGINFO, "create tvshow_view");
std::string tvshowview = PrepareSQL("CREATE VIEW tvshow_view AS SELECT "
" tvshow.*,"
@@ -410,12 +424,10 @@ void CVideoDatabase::CreateViews()
" uniqueid.value AS uniqueid_value, "
" uniqueid.type AS uniqueid_type "
"FROM tvshow"
- " LEFT JOIN (SELECT idShow, MAX(idPath) as idPath "
- " FROM tvshowlinkpath "
- " GROUP BY tvshowlinkpath.idShow) AS tvshowlinkpath ON "
- " tvshowlinkpath.idShow=tvshow.idShow"
+ " LEFT JOIN tvshowlinkpath_minview ON "
+ " tvshowlinkpath_minview.idShow=tvshow.idShow"
" LEFT JOIN path ON"
- " path.idPath=tvshowlinkpath.idPath"
+ " path.idPath=tvshowlinkpath_minview.idPath"
" INNER JOIN tvshowcounts ON"
" tvshow.idShow = tvshowcounts.idShow "
" LEFT JOIN rating ON"
@@ -5455,7 +5467,7 @@ void CVideoDatabase::UpdateTables(int iVersion)
int CVideoDatabase::GetSchemaVersion() const
{
- return 115;
+ return 116;
}
bool CVideoDatabase::LookupByFolders(const std::string &path, bool shows)