Skip to content
This repository
Browse code

[musicdb] fix album and artist SQL queries for musicbrainz

  • Loading branch information...
commit e54553dd84ce14301e04aaaa1f2eb377478e7828 1 parent fc3c06c
night199uk authored July 16, 2013

Showing 1 changed file with 23 additions and 13 deletions. Show diff stats Hide diff stats

  1. 36  xbmc/music/MusicDatabase.cpp
36  xbmc/music/MusicDatabase.cpp
@@ -364,12 +364,15 @@ int CMusicDatabase::AddSong(const int idAlbum,
364 364
     bHasKaraoke = CKaraokeLyricsFactory::HasLyrics(strPathAndFileName);
365 365
 #endif
366 366
 
367  
-    strSQL=PrepareSQL("SELECT * FROM song WHERE (idAlbum = %i AND strMusicBrainzTrackID = '%s') OR (idAlbum=%i AND dwFileNameCRC='%ul' AND strTitle='%s' AND strMusicBrainzTrackID IS NULL)",
368  
-                      idAlbum,
369  
-                      strMusicBrainzTrackID.c_str(),
370  
-                      idAlbum,
371  
-                      crc,
372  
-                      strTitle.c_str());
  367
+    if (!strMusicBrainzTrackID.empty())
  368
+      strSQL = PrepareSQL("SELECT * FROM song WHERE idAlbum = %i AND strMusicBrainzTrackID = '%s'",
  369
+                          idAlbum,
  370
+                          strMusicBrainzTrackID.c_str());
  371
+    else
  372
+      strSQL = PrepareSQL("SELECT * FROM song WHERE idAlbum=%i AND dwFileNameCRC='%ul' AND strTitle='%s' AND strMusicBrainzTrackID IS NULL",
  373
+                          idAlbum,
  374
+                          crc,
  375
+                          strTitle.c_str());
373 376
 
374 377
     if (!m_pDS->query(strSQL.c_str()))
375 378
       return -1;
@@ -497,10 +500,13 @@ int CMusicDatabase::AddAlbum(const CStdString& strAlbum, const CStdString& strMu
497 500
     if (NULL == m_pDB.get()) return -1;
498 501
     if (NULL == m_pDS.get()) return -1;
499 502
 
500  
-    strSQL=PrepareSQL("SELECT * FROM album WHERE strMusicBrainzAlbumID = '%s' OR (strArtists = '%s' AND strAlbum like '%s' and strMusicBrainzAlbumID IS NULL)",
501  
-                      strMusicBrainzAlbumID.c_str(),
502  
-                      strArtist.c_str(),
503  
-                      strAlbum.c_str());
  503
+    if (!strMusicBrainzAlbumID.empty())
  504
+      strSQL = PrepareSQL("SELECT * FROM album WHERE strMusicBrainzAlbumID = '%s'",
  505
+                        strMusicBrainzAlbumID.c_str());
  506
+    else
  507
+      strSQL = PrepareSQL("SELECT * FROM album WHERE strArtists = '%s' AND strAlbum like '%s' and strMusicBrainzAlbumID IS NULL",
  508
+                          strArtist.c_str(),
  509
+                          strAlbum.c_str());
504 510
     m_pDS->query(strSQL.c_str());
505 511
 
506 512
     if (m_pDS->num_rows() == 0)
@@ -607,9 +613,13 @@ int CMusicDatabase::AddArtist(const CStdString& strArtist, const CStdString& str
607 613
     if (NULL == m_pDB.get()) return -1;
608 614
     if (NULL == m_pDS.get()) return -1;
609 615
 
610  
-     strSQL = PrepareSQL("SELECT * FROM artist WHERE strMusicBrainzArtistID = '%s' OR (strArtist = '%s' AND strMusicBrainzArtistID IS NULL)",
611  
-                         strMusicBrainzArtistID.IsEmpty() ? "x" : strMusicBrainzArtistID.c_str(),
612  
-                         strArtist.c_str());
  616
+    if (!strMusicBrainzArtistID.empty())
  617
+      strSQL = PrepareSQL("SELECT * FROM artist WHERE strMusicBrainzArtistID = '%s'",
  618
+                          strMusicBrainzArtistID.c_str());
  619
+    else
  620
+      strSQL = PrepareSQL("SELECT * FROM artist WHERE strArtist = '%s' AND strMusicBrainzArtistID IS NULL",
  621
+                          strArtist.c_str());
  622
+
613 623
     m_pDS->query(strSQL.c_str());
614 624
 
615 625
     if (m_pDS->num_rows() == 0)

0 notes on commit e54553d

Please sign in to comment.
Something went wrong with that request. Please try again.