- Code: Select all
UPDATE Songs
SET PlayCounter = (SELECT COUNT(*) FROM Played WHERE Played.IDSong = Songs.ID GROUP BY Played.IDSong),
LastTimePlayed = (SELECT MAX(PlayDate) FROM Played WHERE Played.IDSong = Songs.ID GROUP BY Played.IDSong)
WHERE Songs.ID IN
(SELECT IDSong FROM Played, Songs WHERE Played.IDSong = Songs.ID GROUP BY IDSong
HAVING PlayCounter<>COUNT(*) OR CAST(LastTimePlayed AS TEXT)<>CAST(MAX(PlayDate) AS TEXT))
Bex gave that SQL statement a while back, for fixing the difference between Play Count and History Plays (caused by iPod sinking I believe), and I believe it calculates the number of plays in the Played table and sets the Playcount of the track to the number. I believe it also sets Last Played based on the newest play in said table as well.
For the "Merge" ability, something like this might need to be implemented to run after the IDs are updated or whatnot. Then again, you might already have something like this under the hood (as I have not peeked inside the script) and it's simply breaking due to a type or something. Or maybe you didn't include such a feature, as it would erase these ghost iPod plays. *Shrugs*