| 167 | | insertSongLibraryId.Value = libraryID; |
|---|
| 168 | | insertSongRemoteSongId.Value = song.Id; |
|---|
| 169 | | insertSongArtist.Value = song.Artist; |
|---|
| 170 | | insertSongAlbum.Value = song.Album; |
|---|
| 171 | | insertSongTitle.Value = song.Title; |
|---|
| 172 | | insertSongYear.Value = song.Year; |
|---|
| 173 | | insertSongFormat.Value = song.Format; |
|---|
| 174 | | insertSongDuration.Value = song.Duration.TotalMilliseconds; |
|---|
| 175 | | insertSongGenre.Value = song.Genre; |
|---|
| 176 | | insertSongTrackNumber.Value = song.TrackNumber; |
|---|
| 177 | | insertSongTrackCount.Value = song.TrackCount; |
|---|
| 178 | | insertSongSize.Value = song.Size; |
|---|
| 179 | | insertSongLastUpdatedInfo.Value = song.DateModified; |
|---|
| 180 | | |
|---|
| 181 | | insertSong.ExecuteNonQuery(); |
|---|
| | 167 | if(SongExists(libraryID, song.Id)) { |
|---|
| | 168 | /*updateSongLibraryId.Value = libraryID; |
|---|
| | 169 | updateSongRemoteSongId.Value = song.Id; |
|---|
| | 170 | updateSongArtist.Value = song.Artist; |
|---|
| | 171 | updateSongAlbum.Value = song.Album; |
|---|
| | 172 | updateSongTitle.Value = song.Title; |
|---|
| | 173 | updateSongYear.Value = song.Year; |
|---|
| | 174 | updateSongFormat.Value = song.Format; |
|---|
| | 175 | updateSongDuration.Value = song.Duration.TotalMilliseconds; |
|---|
| | 176 | updateSongGenre.Value = song.Genre; |
|---|
| | 177 | updateSongTrackNumber.Value = song.TrackNumber; |
|---|
| | 178 | updateSongTrackCount.Value = song.TrackCount; |
|---|
| | 179 | updateSongSize.Value = song.Size; |
|---|
| | 180 | updateSongLastUpdatedInfo.Value = song.DateModified; |
|---|
| | 181 | |
|---|
| | 182 | updateSong.ExecuteNonQuery();*/ |
|---|
| | 183 | } |
|---|
| | 184 | else { |
|---|
| | 185 | insertSongLibraryId.Value = libraryID; |
|---|
| | 186 | insertSongRemoteSongId.Value = song.Id; |
|---|
| | 187 | insertSongArtist.Value = song.Artist; |
|---|
| | 188 | insertSongAlbum.Value = song.Album; |
|---|
| | 189 | insertSongTitle.Value = song.Title; |
|---|
| | 190 | insertSongYear.Value = song.Year; |
|---|
| | 191 | insertSongFormat.Value = song.Format; |
|---|
| | 192 | insertSongDuration.Value = song.Duration.TotalMilliseconds; |
|---|
| | 193 | insertSongGenre.Value = song.Genre; |
|---|
| | 194 | insertSongTrackNumber.Value = song.TrackNumber; |
|---|
| | 195 | insertSongTrackCount.Value = song.TrackCount; |
|---|
| | 196 | insertSongSize.Value = song.Size; |
|---|
| | 197 | insertSongLastUpdatedInfo.Value = song.DateModified; |
|---|
| | 198 | |
|---|
| | 199 | insertSong.ExecuteNonQuery(); |
|---|
| | 200 | } |
|---|
| | 394 | |
|---|
| | 395 | private IDataParameter updateSongLibraryId; |
|---|
| | 396 | private IDataParameter updateSongRemoteSongId; |
|---|
| | 397 | private IDataParameter updateSongArtist; |
|---|
| | 398 | private IDataParameter updateSongAlbum; |
|---|
| | 399 | private IDataParameter updateSongTitle; |
|---|
| | 400 | private IDataParameter updateSongYear; |
|---|
| | 401 | private IDataParameter updateSongFormat; |
|---|
| | 402 | private IDataParameter updateSongDuration; |
|---|
| | 403 | private IDataParameter updateSongGenre; |
|---|
| | 404 | private IDataParameter updateSongTrackNumber; |
|---|
| | 405 | private IDataParameter updateSongTrackCount; |
|---|
| | 406 | private IDataParameter updateSongSize; |
|---|
| | 407 | private IDataParameter updateSongLastUpdatedInfo; |
|---|
| | 408 | |
|---|
| | 409 | //Parameters to determine whether a song is already in the bridge db or not |
|---|
| | 410 | private IDbCommand songExists; |
|---|
| | 411 | private IDataParameter existsLibraryId; |
|---|
| | 412 | private IDataParameter existsSongId; |
|---|
| 409 | | } |
|---|
| 410 | | |
|---|
| | 449 | |
|---|
| | 450 | updateSong = databaseConnection.CreateCommand(); |
|---|
| | 451 | updateSong.CommandText = @"UPDATE songs SET artist=?, album=?, title=?, year=?, format=?, duration=?, |
|---|
| | 452 | genre=?, tracknumber=?, trackcount=?, size=?, lastUpdated=? |
|---|
| | 453 | WHERE libraryId=? AND remoteSongId=?"; |
|---|
| | 454 | |
|---|
| | 455 | |
|---|
| | 456 | //Create and add parameters for updating songs |
|---|
| | 457 | updateSongArtist = updateSong.CreateParameter(); |
|---|
| | 458 | updateSong.Parameters.Add(updateSongArtist); |
|---|
| | 459 | updateSongAlbum = updateSong.CreateParameter(); |
|---|
| | 460 | updateSong.Parameters.Add(updateSongAlbum); |
|---|
| | 461 | updateSongTitle = updateSong.CreateParameter(); |
|---|
| | 462 | updateSong.Parameters.Add(updateSongTitle); |
|---|
| | 463 | updateSongYear = updateSong.CreateParameter(); |
|---|
| | 464 | updateSong.Parameters.Add(updateSongYear); |
|---|
| | 465 | updateSongFormat = updateSong.CreateParameter(); |
|---|
| | 466 | updateSong.Parameters.Add(updateSongFormat); |
|---|
| | 467 | updateSongDuration = updateSong.CreateParameter(); |
|---|
| | 468 | updateSong.Parameters.Add(updateSongDuration); |
|---|
| | 469 | updateSongGenre = updateSong.CreateParameter(); |
|---|
| | 470 | updateSong.Parameters.Add(updateSongGenre); |
|---|
| | 471 | updateSongTrackNumber = updateSong.CreateParameter(); |
|---|
| | 472 | updateSong.Parameters.Add(updateSongTrackNumber); |
|---|
| | 473 | updateSongTrackCount = updateSong.CreateParameter(); |
|---|
| | 474 | updateSong.Parameters.Add(updateSongTrackCount); |
|---|
| | 475 | updateSongSize = updateSong.CreateParameter(); |
|---|
| | 476 | updateSong.Parameters.Add(updateSongSize); |
|---|
| | 477 | updateSongLastUpdatedInfo = updateSong.CreateParameter(); |
|---|
| | 478 | updateSong.Parameters.Add(updateSongLastUpdatedInfo); |
|---|
| | 479 | updateSongLibraryId = updateSong.CreateParameter(); |
|---|
| | 480 | updateSong.Parameters.Add(updateSongLibraryId); |
|---|
| | 481 | updateSongRemoteSongId = updateSong.CreateParameter(); |
|---|
| | 482 | updateSong.Parameters.Add(updateSongRemoteSongId); |
|---|
| | 483 | |
|---|
| | 484 | //Song existance parameters |
|---|
| | 485 | songExists = databaseConnection.CreateCommand(); |
|---|
| | 486 | songExists.CommandText = "SELECT COUNT(*) FROM songs WHERE libraryId=? AND remoteSongId=?"; |
|---|
| | 487 | existsLibraryId = songExists.CreateParameter(); |
|---|
| | 488 | songExists.Parameters.Add(existsLibraryId); |
|---|
| | 489 | existsSongId = songExists.CreateParameter(); |
|---|
| | 490 | songExists.Parameters.Add(existsSongId); |
|---|
| | 491 | } |
|---|
| | 492 | |
|---|
| | 493 | /// <summary> |
|---|
| | 494 | /// Determines whether we need to insert a new song or update and existing record |
|---|
| | 495 | /// </summary> |
|---|
| | 496 | private bool SongExists(int libraryId, int songId) |
|---|
| | 497 | { |
|---|
| | 498 | existsLibraryId.Value = libraryId; |
|---|
| | 499 | existsSongId.Value = songId; |
|---|
| | 500 | |
|---|
| | 501 | IDataReader reader = songExists.ExecuteReader(); |
|---|
| | 502 | reader.Read(); |
|---|
| | 503 | int count = reader.GetInt32(0); |
|---|
| | 504 | reader.Dispose(); |
|---|
| | 505 | |
|---|
| | 506 | return (count == 1) ? true : false; |
|---|
| | 507 | } |
|---|