by Owyn » Fri Dec 19, 2008 3:55 pm
That was a long 2 hours.
Anyway. First cut on script based test on current database. Script is very raw, but, the basics are there to add in any specific tests.
The Script:
Code: Select all
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' This file can be replaced in one of the future versions,
' so please if you want to modify it, make a copy, do your
' modifications in that copy and change Scripts.ini file
' appropriately.
' If you do not do this, you will lose all your changes in
' this script when you install a new version of MediaMonkey
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Option Explicit ' report undefined variables, ...
Dim fout
' SDB variable is connected to MediaMonkey application object
Sub AuditDB
' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile
' Let user select the output path
Dim path
path = iniF.StringValue( "Scripts", "AuditDBDir")
path = SDB.SelectFolder( path, SDB.Localize( "Select where to create the Audit Report."))
If path="" Then
Exit Sub
End If
If Right( path, 1)<>"\" Then
path = path & "\"
End If
' Write selected directory to the ini file
iniF.StringValue( "Scripts", "AuditDBDir") = path
Set iniF = Nothing
' Connect to the FileSystemObject
Dim fso
Set fso = SDB.Tools.FileSystem
' Use progress to notify user about the current action
Dim Progress, ExpText
Set Progress = SDB.Progress
ExpText = SDB.Localize("Creating Audit Report...")
Progress.Text = ExpText
Dim title
title = "DB Audit Report"
' Create the Report File
Set fout = fso.CreateTextFile( path & fso.CorrectFilename( title) & ".txt", True)
fout.WriteLine "MediaMonkey3 Database Audit Report"
' Check the Database
Call CheckDB()
' Finish the Report
fout.WriteLine ""
fout.WriteLine "----End of Report--"
fout.Close
End Sub
Sub CheckDB()
fout.WriteLine " "
fout.Writeline "----Checking Links---"
Call CheckKey("PodcastEpisodes","IDTrack","Songs","ID")
Call CheckKey("ArtistsSongs","IDArtist","Artists","ID")
Call CheckKey("ArtistsSongs","IDSong","Songs","ID")
Call CheckKey("ArtistsAlbums","IDArtist","Artists","ID")
Call CheckKey("ArtistsAlbums","IDAlbum","Albums","ID")
Call CheckKey("GenresSongs","IDGenre","Genres","ID")
Call CheckKey("GenresSongs","IDSong","Songs","ID")
Call CheckKey("Songs","IDAlbum","Albums","ID")
Call CheckKey("Songs","IDMedia","Medias","ID")
Call CheckKey("Songs","IDFolder","Folders","ID")
' Call CheckKey("Lists","IDListType","ListTypes","ID")
Call CheckKey("ListsSongs","IDList","Lists","ID")
' Call CheckKey("ListsSongs","IDListType","ListTypes","ID")
Call CheckKey("ListsSongs","IDSong","Songs","ID")
Call CheckKey("DeviceFilters","IDDevice","Devices","ID")
Call CheckKey("DeviceTracks","IDDevice","Devices","ID")
Call CheckKey("DeviceTracks","IDTrack","Songs","ID")
Call CheckKey("Covers","IDSong","Songs","ID")
Call CheckKey("PlaylistSongs","IDPlayList","Playlists","IDPlaylist")
Call CheckKey("PlaylistSongs","IDSong","Songs","ID")
Call CheckKey("SynchAlbum","IDDevice","Devices","ID")
Call CheckKey("SynchAlbum","IDAlbum","Albums","ID")
Call CheckKey("SynchArtist","IDDevice","Devices","ID")
Call CheckKey("SynchArtist","IDArtist","Artists","ID")
Call CheckKey("SynchLocation","IDDevice","Devices","ID")
Call CheckKey("SynchLocation","IDMedia","Medias","ID")
Call CheckKey("SynchPlaylist","IDDevice","Devices","ID")
Call CheckKey("SynchPlaylist","IDPlaylist","Playlists","ID")
Call CheckKey("SynchPodcast","IDDevice","Devices","ID")
Call CheckKey("SynchPodcast","IDPodcast","Podcasts","ID")
Call CheckKey("Played","IDSong","Songs","ID")
Call CheckKey("PodcastEpisodes","IDPodcast","Podcasts","ID")
Call CheckKey("PodcastEpisodes","IDTrack","Songs","ID")
Call CheckKey("PathProcessing","IDMedia","Medias","ID")
Call CheckKey("PathProcessing","IDSong","Songs","ID")
Call CheckKey("Folders","IDMedia","Medias","ID")
Call CheckKey("Folders","IDParentFolder","Folders","ID")
Call CheckKey("FoldersHier","IDFolder","Folders","ID")
Call CheckKey("FoldersHier","IDChildFolder","Folders","ID")
End Sub
Function CheckKey(FromTable,FromField,ToTable,ToField)
Dim strSQL, qrySQL, strResult, strCount1, strCount2, strCount3
strResult = FromTable & "." & FromField & " -> " & ToTable & "." & ToField
strSQL = "SELECT COUNT(*) AS COUNT FROM " & FromTable
Set qrySQL = SDB.Database.OpenSQL(strSQL)
strCount1 = qrySQL.StringByIndex(0)
strSQL = "SELECT COUNT(*) AS COUNT FROM " & FromTable & " WHERE " &_
FromField & " > 0"
Set qrySQL = SDB.Database.OpenSQL(strSQL)
strCount2 = qrySQL.StringByIndex(0)
strSQL = "SELECT COUNT(*) AS COUNT FROM " & FromTable & " WHERE " &_
FromField & " > 0 AND " &_
FromField & " NOT IN " & "(SELECT " & ToField & " FROM " & ToTable & ")"
Set qrySQL = SDB.Database.OpenSQL(strSQL)
strCount3 = qrySQL.StringByIndex(0)
fout.WriteLine strResult & " Count[" & strCount1 & "]" & " Linked[" & strCount2 & "]" & " Errors[" & strCount3 & "]"
if strCount3 <> "0" Then
fout.WriteLine "********Error*********"
fout.WriteLine " "
End if
End Function
The first report:
Code: Select all
MediaMonkey3 Database Audit Report
----Checking Links---
PodcastEpisodes.IDTrack -> Songs.ID Count[3923] Linked[582] Errors[0]
ArtistsSongs.IDArtist -> Artists.ID Count[33578] Linked[33578] Errors[0]
ArtistsSongs.IDSong -> Songs.ID Count[33578] Linked[33578] Errors[0]
ArtistsAlbums.IDArtist -> Artists.ID Count[2099] Linked[2099] Errors[0]
ArtistsAlbums.IDAlbum -> Albums.ID Count[2099] Linked[2099] Errors[0]
GenresSongs.IDGenre -> Genres.ID Count[29309] Linked[29309] Errors[0]
GenresSongs.IDSong -> Songs.ID Count[29309] Linked[29309] Errors[0]
Songs.IDAlbum -> Albums.ID Count[20680] Linked[20678] Errors[0]
Songs.IDMedia -> Medias.ID Count[20680] Linked[20680] Errors[0]
Songs.IDFolder -> Folders.ID Count[20680] Linked[20680] Errors[0]
ListsSongs.IDList -> Lists.ID Count[1718] Linked[1718] Errors[0]
ListsSongs.IDSong -> Songs.ID Count[1718] Linked[1718] Errors[0]
DeviceFilters.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
DeviceTracks.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
DeviceTracks.IDTrack -> Songs.ID Count[0] Linked[0] Errors[0]
Covers.IDSong -> Songs.ID Count[25342] Linked[25342] Errors[0]
PlaylistSongs.IDPlayList -> Playlists.IDPlaylist Count[214] Linked[214] Errors[214]
********Error*********
PlaylistSongs.IDSong -> Songs.ID Count[214] Linked[214] Errors[0]
SynchAlbum.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchAlbum.IDAlbum -> Albums.ID Count[0] Linked[0] Errors[0]
SynchArtist.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchArtist.IDArtist -> Artists.ID Count[0] Linked[0] Errors[0]
SynchLocation.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchLocation.IDMedia -> Medias.ID Count[0] Linked[0] Errors[0]
SynchPlaylist.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchPlaylist.IDPlaylist -> Playlists.ID Count[0] Linked[0] Errors[0]
SynchPodcast.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchPodcast.IDPodcast -> Podcasts.ID Count[0] Linked[0] Errors[0]
Played.IDSong -> Songs.ID Count[206] Linked[206] Errors[44]
********Error*********
PodcastEpisodes.IDPodcast -> Podcasts.ID Count[3923] Linked[3923] Errors[0]
PodcastEpisodes.IDTrack -> Songs.ID Count[3923] Linked[582] Errors[0]
PathProcessing.IDMedia -> Medias.ID Count[0] Linked[0] Errors[0]
PathProcessing.IDSong -> Songs.ID Count[0] Linked[0] Errors[0]
Folders.IDMedia -> Medias.ID Count[1491] Linked[1491] Errors[0]
Folders.IDParentFolder -> Folders.ID Count[1491] Linked[1490] Errors[0]
FoldersHier.IDFolder -> Folders.ID Count[9542] Linked[9542] Errors[0]
FoldersHier.IDChildFolder -> Folders.ID Count[9542] Linked[9542] Errors[0]
----End of Report--
This should have checked every foreign key in the database.
Not sure what to make of the two errors.
Time for a break.
That was a long 2 hours.
Anyway. First cut on script based test on current database. Script is very raw, but, the basics are there to add in any specific tests.
The Script:
[code]' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' This file can be replaced in one of the future versions,
' so please if you want to modify it, make a copy, do your
' modifications in that copy and change Scripts.ini file
' appropriately.
' If you do not do this, you will lose all your changes in
' this script when you install a new version of MediaMonkey
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Option Explicit ' report undefined variables, ...
Dim fout
' SDB variable is connected to MediaMonkey application object
Sub AuditDB
' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile
' Let user select the output path
Dim path
path = iniF.StringValue( "Scripts", "AuditDBDir")
path = SDB.SelectFolder( path, SDB.Localize( "Select where to create the Audit Report."))
If path="" Then
Exit Sub
End If
If Right( path, 1)<>"\" Then
path = path & "\"
End If
' Write selected directory to the ini file
iniF.StringValue( "Scripts", "AuditDBDir") = path
Set iniF = Nothing
' Connect to the FileSystemObject
Dim fso
Set fso = SDB.Tools.FileSystem
' Use progress to notify user about the current action
Dim Progress, ExpText
Set Progress = SDB.Progress
ExpText = SDB.Localize("Creating Audit Report...")
Progress.Text = ExpText
Dim title
title = "DB Audit Report"
' Create the Report File
Set fout = fso.CreateTextFile( path & fso.CorrectFilename( title) & ".txt", True)
fout.WriteLine "MediaMonkey3 Database Audit Report"
' Check the Database
Call CheckDB()
' Finish the Report
fout.WriteLine ""
fout.WriteLine "----End of Report--"
fout.Close
End Sub
Sub CheckDB()
fout.WriteLine " "
fout.Writeline "----Checking Links---"
Call CheckKey("PodcastEpisodes","IDTrack","Songs","ID")
Call CheckKey("ArtistsSongs","IDArtist","Artists","ID")
Call CheckKey("ArtistsSongs","IDSong","Songs","ID")
Call CheckKey("ArtistsAlbums","IDArtist","Artists","ID")
Call CheckKey("ArtistsAlbums","IDAlbum","Albums","ID")
Call CheckKey("GenresSongs","IDGenre","Genres","ID")
Call CheckKey("GenresSongs","IDSong","Songs","ID")
Call CheckKey("Songs","IDAlbum","Albums","ID")
Call CheckKey("Songs","IDMedia","Medias","ID")
Call CheckKey("Songs","IDFolder","Folders","ID")
' Call CheckKey("Lists","IDListType","ListTypes","ID")
Call CheckKey("ListsSongs","IDList","Lists","ID")
' Call CheckKey("ListsSongs","IDListType","ListTypes","ID")
Call CheckKey("ListsSongs","IDSong","Songs","ID")
Call CheckKey("DeviceFilters","IDDevice","Devices","ID")
Call CheckKey("DeviceTracks","IDDevice","Devices","ID")
Call CheckKey("DeviceTracks","IDTrack","Songs","ID")
Call CheckKey("Covers","IDSong","Songs","ID")
Call CheckKey("PlaylistSongs","IDPlayList","Playlists","IDPlaylist")
Call CheckKey("PlaylistSongs","IDSong","Songs","ID")
Call CheckKey("SynchAlbum","IDDevice","Devices","ID")
Call CheckKey("SynchAlbum","IDAlbum","Albums","ID")
Call CheckKey("SynchArtist","IDDevice","Devices","ID")
Call CheckKey("SynchArtist","IDArtist","Artists","ID")
Call CheckKey("SynchLocation","IDDevice","Devices","ID")
Call CheckKey("SynchLocation","IDMedia","Medias","ID")
Call CheckKey("SynchPlaylist","IDDevice","Devices","ID")
Call CheckKey("SynchPlaylist","IDPlaylist","Playlists","ID")
Call CheckKey("SynchPodcast","IDDevice","Devices","ID")
Call CheckKey("SynchPodcast","IDPodcast","Podcasts","ID")
Call CheckKey("Played","IDSong","Songs","ID")
Call CheckKey("PodcastEpisodes","IDPodcast","Podcasts","ID")
Call CheckKey("PodcastEpisodes","IDTrack","Songs","ID")
Call CheckKey("PathProcessing","IDMedia","Medias","ID")
Call CheckKey("PathProcessing","IDSong","Songs","ID")
Call CheckKey("Folders","IDMedia","Medias","ID")
Call CheckKey("Folders","IDParentFolder","Folders","ID")
Call CheckKey("FoldersHier","IDFolder","Folders","ID")
Call CheckKey("FoldersHier","IDChildFolder","Folders","ID")
End Sub
Function CheckKey(FromTable,FromField,ToTable,ToField)
Dim strSQL, qrySQL, strResult, strCount1, strCount2, strCount3
strResult = FromTable & "." & FromField & " -> " & ToTable & "." & ToField
strSQL = "SELECT COUNT(*) AS COUNT FROM " & FromTable
Set qrySQL = SDB.Database.OpenSQL(strSQL)
strCount1 = qrySQL.StringByIndex(0)
strSQL = "SELECT COUNT(*) AS COUNT FROM " & FromTable & " WHERE " &_
FromField & " > 0"
Set qrySQL = SDB.Database.OpenSQL(strSQL)
strCount2 = qrySQL.StringByIndex(0)
strSQL = "SELECT COUNT(*) AS COUNT FROM " & FromTable & " WHERE " &_
FromField & " > 0 AND " &_
FromField & " NOT IN " & "(SELECT " & ToField & " FROM " & ToTable & ")"
Set qrySQL = SDB.Database.OpenSQL(strSQL)
strCount3 = qrySQL.StringByIndex(0)
fout.WriteLine strResult & " Count[" & strCount1 & "]" & " Linked[" & strCount2 & "]" & " Errors[" & strCount3 & "]"
if strCount3 <> "0" Then
fout.WriteLine "********Error*********"
fout.WriteLine " "
End if
End Function
[/code]
The first report:
[code]MediaMonkey3 Database Audit Report
----Checking Links---
PodcastEpisodes.IDTrack -> Songs.ID Count[3923] Linked[582] Errors[0]
ArtistsSongs.IDArtist -> Artists.ID Count[33578] Linked[33578] Errors[0]
ArtistsSongs.IDSong -> Songs.ID Count[33578] Linked[33578] Errors[0]
ArtistsAlbums.IDArtist -> Artists.ID Count[2099] Linked[2099] Errors[0]
ArtistsAlbums.IDAlbum -> Albums.ID Count[2099] Linked[2099] Errors[0]
GenresSongs.IDGenre -> Genres.ID Count[29309] Linked[29309] Errors[0]
GenresSongs.IDSong -> Songs.ID Count[29309] Linked[29309] Errors[0]
Songs.IDAlbum -> Albums.ID Count[20680] Linked[20678] Errors[0]
Songs.IDMedia -> Medias.ID Count[20680] Linked[20680] Errors[0]
Songs.IDFolder -> Folders.ID Count[20680] Linked[20680] Errors[0]
ListsSongs.IDList -> Lists.ID Count[1718] Linked[1718] Errors[0]
ListsSongs.IDSong -> Songs.ID Count[1718] Linked[1718] Errors[0]
DeviceFilters.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
DeviceTracks.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
DeviceTracks.IDTrack -> Songs.ID Count[0] Linked[0] Errors[0]
Covers.IDSong -> Songs.ID Count[25342] Linked[25342] Errors[0]
PlaylistSongs.IDPlayList -> Playlists.IDPlaylist Count[214] Linked[214] Errors[214]
********Error*********
PlaylistSongs.IDSong -> Songs.ID Count[214] Linked[214] Errors[0]
SynchAlbum.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchAlbum.IDAlbum -> Albums.ID Count[0] Linked[0] Errors[0]
SynchArtist.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchArtist.IDArtist -> Artists.ID Count[0] Linked[0] Errors[0]
SynchLocation.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchLocation.IDMedia -> Medias.ID Count[0] Linked[0] Errors[0]
SynchPlaylist.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchPlaylist.IDPlaylist -> Playlists.ID Count[0] Linked[0] Errors[0]
SynchPodcast.IDDevice -> Devices.ID Count[0] Linked[0] Errors[0]
SynchPodcast.IDPodcast -> Podcasts.ID Count[0] Linked[0] Errors[0]
Played.IDSong -> Songs.ID Count[206] Linked[206] Errors[44]
********Error*********
PodcastEpisodes.IDPodcast -> Podcasts.ID Count[3923] Linked[3923] Errors[0]
PodcastEpisodes.IDTrack -> Songs.ID Count[3923] Linked[582] Errors[0]
PathProcessing.IDMedia -> Medias.ID Count[0] Linked[0] Errors[0]
PathProcessing.IDSong -> Songs.ID Count[0] Linked[0] Errors[0]
Folders.IDMedia -> Medias.ID Count[1491] Linked[1491] Errors[0]
Folders.IDParentFolder -> Folders.ID Count[1491] Linked[1490] Errors[0]
FoldersHier.IDFolder -> Folders.ID Count[9542] Linked[9542] Errors[0]
FoldersHier.IDChildFolder -> Folders.ID Count[9542] Linked[9542] Errors[0]
----End of Report--
[/code]
This should have checked every foreign key in the database.
Not sure what to make of the two errors.
Time for a break.