diff options
author | Jonathan Marshall <jmarshall@xbmc.org> | 2013-11-30 19:44:20 +1300 |
---|---|---|
committer | Jonathan Marshall <jmarshall@xbmc.org> | 2013-12-24 13:48:52 +1300 |
commit | 0893f491587a1b6a36ecd01d0de53f8fc97b1aa2 (patch) | |
tree | 2db4e2e0595a278a4a83cc59c4ef740a6cac5ad2 | |
parent | f028958fea2b95382e01fa5d201210a68168d79e (diff) |
[musicdb] Adds album and song artist views, and move GetAlbumArtistCreditFromDataset -> GetArtistCreditFromDataset for re-use
-rw-r--r-- | xbmc/music/MusicDatabase.cpp | 47 | ||||
-rw-r--r-- | xbmc/music/MusicDatabase.h | 23 |
2 files changed, 52 insertions, 18 deletions
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp index 7e87655ac3..6eec62c988 100644 --- a/xbmc/music/MusicDatabase.cpp +++ b/xbmc/music/MusicDatabase.cpp @@ -349,6 +349,33 @@ void CMusicDatabase::CreateViews() "FROM artist " " LEFT OUTER JOIN artistinfo ON" " artist.idArtist = artistinfo.idArtist"); + + CLog::Log(LOGINFO, "create albumartistview"); + m_pDS->exec("DROP VIEW IF EXISTS albumartistview"); + m_pDS->exec("CREATE VIEW albumartistview AS SELECT" + " album_artist.idAlbum AS idAlbum, " + " album_artist.idArtist AS idArtist, " + " artist.strArtist AS strArtist, " + " artist.strMusicBrainzArtistID AS strMusicBrainzArtistID, " + " album_artist.boolFeatured AS boolFeatured, " + " album_artist.strJoinPhrase AS strJoinPhrase, " + " album_artist.iOrder AS iOrder " + "FROM album_artist " + "JOIN artist ON " + " album_artist.idArtist = artist.idArtist"); + CLog::Log(LOGINFO, "create songartistview"); + m_pDS->exec("DROP VIEW IF EXISTS songartistview"); + m_pDS->exec("CREATE VIEW songartistview AS SELECT" + " song_artist.idSong AS idSong, " + " song_artist.idArtist AS idArtist, " + " artist.strArtist AS strArtist, " + " artist.strMusicBrainzArtistID AS strMusicBrainzArtistID, " + " song_artist.boolFeatured AS boolFeatured, " + " song_artist.strJoinPhrase AS strJoinPhrase, " + " song_artist.iOrder AS iOrder " + "FROM song_artist " + "JOIN artist ON " + " song_artist.idArtist = artist.idArtist"); } int CMusicDatabase::AddSong(const int idAlbum, @@ -1147,14 +1174,14 @@ CAlbum CMusicDatabase::GetAlbumFromDataset(const dbiplus::sql_record* const reco return album; } -CArtistCredit CMusicDatabase::GetAlbumArtistCreditFromDataset(const dbiplus::sql_record* const record, int offset /* = 0 */) +CArtistCredit CMusicDatabase::GetArtistCreditFromDataset(const dbiplus::sql_record* const record, int offset /* = 0 */) { CArtistCredit artistCredit; - artistCredit.idArtist = record->at(offset + album_idArtist).get_asInt(); - artistCredit.m_strArtist = record->at(offset + album_strArtist).get_asString(); - artistCredit.m_strMusicBrainzArtistID = record->at(offset + album_strMusicBrainzArtistID).get_asString(); - artistCredit.m_boolFeatured = record->at(offset + album_bFeatured).get_asBool(); - artistCredit.m_strJoinPhrase = record->at(offset + album_strJoinPhrase).get_asString(); + artistCredit.idArtist = record->at(offset + artistCredit_idArtist).get_asInt(); + artistCredit.m_strArtist = record->at(offset + artistCredit_strArtist).get_asString(); + artistCredit.m_strMusicBrainzArtistID = record->at(offset + artistCredit_strMusicBrainzArtistID).get_asString(); + artistCredit.m_boolFeatured = record->at(offset + artistCredit_bFeatured).get_asBool(); + artistCredit.m_strJoinPhrase = record->at(offset + artistCredit_strJoinPhrase).get_asString(); return artistCredit; } @@ -1332,7 +1359,7 @@ bool CMusicDatabase::GetAlbumInfo(int idAlbum, CAlbum &info, VECSONGS* songs, bo if (idAlbum == -1) return false; // not in the database - CStdString strSQL=PrepareSQL("SELECT albumview.*, album_artist.idArtist, artist.strArtist, artist.strMusicBrainzArtistID, album_artist.boolFeatured, album_artist.strJoinPhrase FROM albumview JOIN album_artist ON albumview.idAlbum = album_artist.idAlbum JOIN artist ON album_artist.idArtist = artist.idArtist WHERE albumview.idAlbum = %ld", idAlbum); + CStdString strSQL=PrepareSQL("SELECT albumview.*,albumartistview.* FROM albumview JOIN albumartistview ON albumview.idAlbum = albumartistview.idAlbum WHERE albumview.idAlbum = %ld", idAlbum); if (scrapedInfo) // require additional information strSQL += " and idAlbumInfo > 0"; @@ -1347,9 +1374,9 @@ bool CMusicDatabase::GetAlbumInfo(int idAlbum, CAlbum &info, VECSONGS* songs, bo int idAlbumInfo = m_pDS2->fv(album_idAlbumInfo).get_asInt(); while (!m_pDS2->eof()) { - if (!info.artistCredits.empty() && (m_pDS2->fv(album_idArtist).get_asInt() != info.artistCredits.back().idArtist)) + if (!info.artistCredits.empty() && (m_pDS2->fv(album_enumCount + artistCredit_idArtist).get_asInt() != info.artistCredits.back().idArtist)) { - info.artistCredits.push_back(GetAlbumArtistCreditFromDataset(m_pDS2.get()->get_sql_record())); + info.artistCredits.push_back(GetArtistCreditFromDataset(m_pDS2.get()->get_sql_record(), album_enumCount)); } m_pDS2->next(); } @@ -3796,7 +3823,7 @@ bool CMusicDatabase::UpdateOldVersion(int version) int CMusicDatabase::GetMinVersion() const { - return 37; + return 38; } unsigned int CMusicDatabase::GetSongIDs(const Filter &filter, vector<pair<int,int> > &songIDs) diff --git a/xbmc/music/MusicDatabase.h b/xbmc/music/MusicDatabase.h index 2a2f976934..6e2d8b0fec 100644 --- a/xbmc/music/MusicDatabase.h +++ b/xbmc/music/MusicDatabase.h @@ -466,7 +466,7 @@ private: CArtist GetArtistFromDataset(const dbiplus::sql_record* const record, int offset = 0, bool needThumb = true); CAlbum GetAlbumFromDataset(dbiplus::Dataset* pDS, int offset = 0, bool imageURL = false); CAlbum GetAlbumFromDataset(const dbiplus::sql_record* const record, int offset = 0, bool imageURL = false); - CArtistCredit GetAlbumArtistCreditFromDataset(const dbiplus::sql_record* const record, int offset = 0); + CArtistCredit GetArtistCreditFromDataset(const dbiplus::sql_record* const record, int offset = 0); void GetFileItemFromDataset(CFileItem* item, const CMusicDbUrl &baseUrl); void GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CMusicDbUrl &baseUrl); bool CleanupSongs(); @@ -533,15 +533,22 @@ private: album_iRating, album_bCompilation, album_iTimesPlayed, - - // used for GetAlbumInfo to get the cascaded artist credits - album_idArtist, - album_strArtist, - album_strMusicBrainzArtistID, - album_bFeatured, - album_strJoinPhrase + album_enumCount // end of the enum, do not add past here } AlbumFields; + enum _ArtistCreditFields + { + // used for GetAlbum to get the cascaded album/song artist credits + artistCredit_idEntity = 0, // can be idSong or idAlbum depending on context + artistCredit_idArtist, + artistCredit_strArtist, + artistCredit_strMusicBrainzArtistID, + artistCredit_bFeatured, + artistCredit_strJoinPhrase, + artistCredit_iOrder, + artistCredit_enumCount + } ArtistCreditFields; + enum _ArtistFields { artist_idArtist=0, |