diff options
author | Jonathan Marshall <jmarshall@xbmc.org> | 2013-11-30 18:21:16 +1300 |
---|---|---|
committer | Jonathan Marshall <jmarshall@xbmc.org> | 2013-12-24 13:48:49 +1300 |
commit | 0c6e32543b8fe31a40f2a9baaee55b66df6828bd (patch) | |
tree | e9b66c8d453525b57826754f0e0464e7e6350e2c | |
parent | 6e2baea75a685bcbb9bdcd6a19c5006e65d35d79 (diff) |
[musicdb] cosmetic: tidy up the song table definition and GetSongByFileName
-rw-r--r-- | xbmc/music/MusicDatabase.cpp | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp index d438094e33..3e2f6f4aca 100644 --- a/xbmc/music/MusicDatabase.cpp +++ b/xbmc/music/MusicDatabase.cpp @@ -131,7 +131,16 @@ bool CMusicDatabase::CreateTables() CLog::Log(LOGINFO, "create path table"); m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath varchar(512), strHash text)\n"); CLog::Log(LOGINFO, "create song table"); - m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, strArtists text, strGenres text, strTitle varchar(512), iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed varchar(20) default NULL, rating char default '0', comment text)\n"); + m_pDS->exec("CREATE TABLE song ( idSong integer primary key, " + " idAlbum integer, idPath integer, " + " strArtists text, strGenres text, strTitle varchar(512), " + " iTrack integer, iDuration integer, iYear integer, " + " dwFileNameCRC text, " + " strFileName text, strMusicBrainzTrackID text, " + " iTimesPlayed integer, iStartOffset integer, iEndOffset integer, " + " idThumb integer, " + " lastplayed varchar(20) default NULL, " + " rating char default '0', comment text)"); CLog::Log(LOGINFO, "create song_artist table"); m_pDS->exec("CREATE TABLE song_artist ( idArtist integer, idSong integer, strJoinPhrase text, boolFeatured integer, iOrder integer )\n"); CLog::Log(LOGINFO, "create song_genre table"); @@ -1171,47 +1180,33 @@ CArtist CMusicDatabase::GetArtistFromDataset(const dbiplus::sql_record* const re bool CMusicDatabase::GetSongByFileName(const CStdString& strFileName, CSong& song, int startOffset) { - try + song.Clear(); + CURL url(strFileName); + + if (url.GetProtocol()=="musicdb") { - song.Clear(); - CURL url(strFileName); + CStdString strFile = URIUtils::GetFileName(strFileName); + URIUtils::RemoveExtension(strFile); + return GetSong(atol(strFile.c_str()), song); + } - if (url.GetProtocol()=="musicdb") - { - CStdString strFile = URIUtils::GetFileName(strFileName); - URIUtils::RemoveExtension(strFile); - return GetSong(atol(strFile.c_str()), song); - } + CStdString strPath = URIUtils::GetDirectory(strFileName); + URIUtils::AddSlashAtEnd(strPath); - if (NULL == m_pDB.get()) return false; - if (NULL == m_pDS.get()) return false; + if (NULL == m_pDB.get()) return false; + if (NULL == m_pDS.get()) return false; - CStdString strPath = URIUtils::GetDirectory(strFileName); - URIUtils::AddSlashAtEnd(strPath); + DWORD crc = ComputeCRC(strFileName); - DWORD crc = ComputeCRC(strFileName); - CStdString strSQL=PrepareSQL("select * from songview " - "where dwFileNameCRC='%ul' and strPath='%s'" - , crc, - strPath.c_str()); - if (startOffset) - strSQL += PrepareSQL(" AND iStartOffset=%i", startOffset); + CStdString strSQL = PrepareSQL("select idSong from songview " + "where dwFileNameCRC='%ul' and strPath='%s'", + crc, strPath.c_str()); + if (startOffset) + strSQL += PrepareSQL(" AND iStartOffset=%i", startOffset); - if (!m_pDS->query(strSQL.c_str())) return false; - int iRowsFound = m_pDS->num_rows(); - if (iRowsFound == 0) - { - m_pDS->close(); - return false; - } - song = GetSongFromDataset(); - m_pDS->close(); // cleanup recordset data - return true; - } - catch (...) - { - CLog::Log(LOGERROR, "%s(%s) failed", __FUNCTION__, strFileName.c_str()); - } + int idSong = (int)strtol(GetSingleValue(strSQL).c_str(), NULL, 10); + if (idSong > 0) + return GetSong(idSong, song); return false; } |