SDB.Database.Commit

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Psyker7
Posts: 255
Joined: Sat Mar 03, 2007 8:00 am

SDB.Database.Commit

Post by Psyker7 » Sat Dec 12, 2009 8:28 pm

For my own education:

I'm wondering why I need to use a SDB.Database.Commit in the following code - If I don't then adding a track to a playlist causes the script to hang.
The only sql being done is a SDB.Database.QuerySongs and the wiki mentions that commit should only be needed if SDB.Database.BeginTransaction is used.

Code sample below:

Code: Select all

Set list = SDB.Database.QuerySongs("Artist = '" & CorrectSt(ArtistName) & "' AND SongTitle = '" & CorrectSt(TrackTitle) & "'")
				SDB.Database.Commit

				If list.EOF Then
					Not_Added = Not_Added & VbCrLf & TrackTitle & " - " & ArtistName
				End If

				Plays = -1
				Num_Dupes = 0

				Do While Not list.EOF

					Num_Dupes = Num_Dupes + 1
					If list.item.Playcounter > Plays Then
						Set Add_me = list.item
						Plays = list.item.Playcounter
						SDB.ProcessMessages
					End If
					list.Next
					
					SDB.ProcessMessages
				Loop

				
				SDB.ProcessMessages

				If Plays >= 0 Then
					
					Playlist.AddTrack(Add_me)
					logme "--Was added"
				Else
					logme "--Was not found in database"
				End If

Peke
Posts: 12500
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: SDB.Database.Commit

Post by Peke » Sat Dec 12, 2009 10:41 pm

Are you using Playlist irect in DB Playlist or as SongList?

I would Suggest that you use new created Songlist DIM and when all is Done use AddTracks to Create new Playlist and Add all tracks at once. It will speed up Script and Lower Queries on MM Library.

Example (Not tested but it should be like that):

Code: Select all

DIM LastFavorites
'Case 1
'Set LastFavorites = CreateObject("SongsDB.SDBSongList")

'Case 2
'Set LastFavorites = SDB.NewSongList

Do While Not list.EOF
   Set Add_me = list.item
   LastFavorites.Add(Add_me)
   SDB.ProcessMessages
Loop

Playlist.AddTracks(LastFavorites)
SDB.ProcessMessages

LastFavorites = Nothing
Experiment and see which one is better/faster
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

Post Reply