Created
September 24, 2015 15:45
-
-
Save kabili207/224942f90eb7ccda0a6a to your computer and use it in GitHub Desktop.
SQL to pickup where Kodi left off when database creation fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use MyMusic48; | |
delimiter // | |
CREATE TRIGGER tgrDeleteAlbum AFTER delete ON album FOR EACH ROW BEGIN | |
DELETE FROM song WHERE song.idAlbum = old.idAlbum; | |
DELETE FROM album_artist WHERE album_artist.idAlbum = old.idAlbum; | |
DELETE FROM album_genre WHERE album_genre.idAlbum = old.idAlbum; | |
DELETE FROM albuminfosong WHERE albuminfosong.idAlbumInfo=old.idAlbum; | |
DELETE FROM art WHERE media_id=old.idAlbum AND media_type='album'; | |
END// | |
CREATE TRIGGER tgrDeleteArtist AFTER delete ON artist FOR EACH ROW BEGIN | |
DELETE FROM album_artist WHERE album_artist.idArtist = old.idArtist; | |
DELETE FROM song_artist WHERE song_artist.idArtist = old.idArtist; | |
DELETE FROM discography WHERE discography.idArtist = old.idArtist; | |
DELETE FROM art WHERE media_id=old.idArtist AND media_type='artist'; | |
END// | |
CREATE TRIGGER tgrDeleteSong AFTER delete ON song FOR EACH ROW BEGIN | |
DELETE FROM song_artist WHERE song_artist.idSong = old.idSong; | |
DELETE FROM song_genre WHERE song_genre.idSong = old.idSong; | |
DELETE FROM karaokedata WHERE karaokedata.idSong = old.idSong; | |
DELETE FROM art WHERE media_id=old.idSong AND media_type='song'; | |
END// | |
delimiter ; | |
CREATE VIEW songview AS SELECT | |
song.idSong AS idSong, | |
song.strArtists AS strArtists, | |
song.strGenres AS strGenres, | |
strTitle, | |
iTrack, iDuration, | |
song.iYear AS iYear, | |
strFileName, | |
strMusicBrainzTrackID, | |
iTimesPlayed, iStartOffset, iEndOffset, | |
lastplayed, rating, comment, | |
song.idAlbum AS idAlbum, | |
strAlbum, | |
strPath, | |
iKaraNumber, iKaraDelay, strKaraEncoding, | |
album.bCompilation AS bCompilation, | |
album.strArtists AS strAlbumArtists | |
FROM song | |
JOIN album ON | |
song.idAlbum=album.idAlbum | |
JOIN path ON | |
song.idPath=path.idPath | |
LEFT OUTER JOIN karaokedata ON | |
song.idSong=karaokedata.idSong; | |
CREATE VIEW albumview AS SELECT | |
album.idAlbum AS idAlbum, | |
strAlbum, | |
strMusicBrainzAlbumID, | |
album.strArtists AS strArtists, | |
album.strGenres AS strGenres, | |
album.iYear AS iYear, | |
album.strMoods AS strMoods, | |
album.strStyles AS strStyles, | |
strThemes, | |
strReview, | |
strLabel, | |
strType, | |
album.strImage as strImage, | |
iRating, | |
bCompilation, | |
MIN(song.iTimesPlayed) AS iTimesPlayed | |
FROM album | |
LEFT OUTER JOIN song ON | |
album.idAlbum=song.idAlbum | |
GROUP BY album.idAlbum; | |
CREATE VIEW artistview AS SELECT | |
idArtist, strArtist, | |
strMusicBrainzArtistID, | |
strBorn, strFormed, strGenres, | |
strMoods, strStyles, strInstruments, | |
strBiography, strDied, strDisbanded, | |
strYearsActive, strImage, strFanart | |
FROM artist; | |
CREATE VIEW albumartistview AS SELECT | |
album_artist.idAlbum AS idAlbum, | |
album_artist.idArtist AS idArtist, | |
artist.strArtist AS strArtist, | |
artist.strMusicBrainzArtistID AS strMusicBrainzArtistID, | |
album_artist.boolFeatured AS boolFeatured, | |
album_artist.strJoinPhrase AS strJoinPhrase, | |
album_artist.iOrder AS iOrder | |
FROM album_artist | |
JOIN artist ON | |
album_artist.idArtist = artist.idArtist; | |
CREATE VIEW songartistview AS SELECT | |
song_artist.idSong AS idSong, | |
song_artist.idArtist AS idArtist, | |
artist.strArtist AS strArtist, | |
artist.strMusicBrainzArtistID AS strMusicBrainzArtistID, | |
song_artist.boolFeatured AS boolFeatured, | |
song_artist.strJoinPhrase AS strJoinPhrase, | |
song_artist.iOrder AS iOrder | |
FROM song_artist | |
JOIN artist ON | |
song_artist.idArtist = artist.idArtist; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment