aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornight199uk <night199uk@xbmc.org>2013-07-16 22:03:59 +0800
committernight199uk <night199uk@xbmc.org>2013-07-19 19:18:50 +0800
commite54553dd84ce14301e04aaaa1f2eb377478e7828 (patch)
treee919374c5eb7266a011a36c06e3a3885d6a3f6d1
parentfc3c06c75ef35d2aebb6f3778ebcc8bec3cfe68f (diff)
[musicdb] fix album and artist SQL queries for musicbrainz
-rw-r--r--xbmc/music/MusicDatabase.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp
index 19a9010369..db4c6a2f10 100644
--- a/xbmc/music/MusicDatabase.cpp
+++ b/xbmc/music/MusicDatabase.cpp
@@ -364,12 +364,15 @@ int CMusicDatabase::AddSong(const int idAlbum,
bHasKaraoke = CKaraokeLyricsFactory::HasLyrics(strPathAndFileName);
#endif
- strSQL=PrepareSQL("SELECT * FROM song WHERE (idAlbum = %i AND strMusicBrainzTrackID = '%s') OR (idAlbum=%i AND dwFileNameCRC='%ul' AND strTitle='%s' AND strMusicBrainzTrackID IS NULL)",
- idAlbum,
- strMusicBrainzTrackID.c_str(),
- idAlbum,
- crc,
- strTitle.c_str());
+ if (!strMusicBrainzTrackID.empty())
+ strSQL = PrepareSQL("SELECT * FROM song WHERE idAlbum = %i AND strMusicBrainzTrackID = '%s'",
+ idAlbum,
+ strMusicBrainzTrackID.c_str());
+ else
+ strSQL = PrepareSQL("SELECT * FROM song WHERE idAlbum=%i AND dwFileNameCRC='%ul' AND strTitle='%s' AND strMusicBrainzTrackID IS NULL",
+ idAlbum,
+ crc,
+ strTitle.c_str());
if (!m_pDS->query(strSQL.c_str()))
return -1;
@@ -497,10 +500,13 @@ int CMusicDatabase::AddAlbum(const CStdString& strAlbum, const CStdString& strMu
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;
- strSQL=PrepareSQL("SELECT * FROM album WHERE strMusicBrainzAlbumID = '%s' OR (strArtists = '%s' AND strAlbum like '%s' and strMusicBrainzAlbumID IS NULL)",
- strMusicBrainzAlbumID.c_str(),
- strArtist.c_str(),
- strAlbum.c_str());
+ if (!strMusicBrainzAlbumID.empty())
+ strSQL = PrepareSQL("SELECT * FROM album WHERE strMusicBrainzAlbumID = '%s'",
+ strMusicBrainzAlbumID.c_str());
+ else
+ strSQL = PrepareSQL("SELECT * FROM album WHERE strArtists = '%s' AND strAlbum like '%s' and strMusicBrainzAlbumID IS NULL",
+ strArtist.c_str(),
+ strAlbum.c_str());
m_pDS->query(strSQL.c_str());
if (m_pDS->num_rows() == 0)
@@ -607,9 +613,13 @@ int CMusicDatabase::AddArtist(const CStdString& strArtist, const CStdString& str
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;
- strSQL = PrepareSQL("SELECT * FROM artist WHERE strMusicBrainzArtistID = '%s' OR (strArtist = '%s' AND strMusicBrainzArtistID IS NULL)",
- strMusicBrainzArtistID.IsEmpty() ? "x" : strMusicBrainzArtistID.c_str(),
- strArtist.c_str());
+ if (!strMusicBrainzArtistID.empty())
+ strSQL = PrepareSQL("SELECT * FROM artist WHERE strMusicBrainzArtistID = '%s'",
+ strMusicBrainzArtistID.c_str());
+ else
+ strSQL = PrepareSQL("SELECT * FROM artist WHERE strArtist = '%s' AND strMusicBrainzArtistID IS NULL",
+ strArtist.c_str());
+
m_pDS->query(strSQL.c_str());
if (m_pDS->num_rows() == 0)