Creating Tables Hangs MediaMonkey on Subsequent Start

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

Moderator: Gurus

Creating Tables Hangs MediaMonkey on Subsequent Start

Postby AngrySpade » Fri Jun 10, 2011 8:36 pm

I'm attempting to create some tables in MediaMonkey's database.
Forgiving my reasons for doing this, it seems that every time I do, MediaMonkey hangs on the subsequent startup.

If I remove the tables I've created with a program like SQLite Maestro, MediaMonkey will startup again.

Maybe someone can instruct me as to what I'm doing wrong.

Code: Select all
Function CheckTableExists (tableName)
   Dim tableResult
   Set tableResult = SDB.Database.OpenSQL("SELECT name FROM sqlite_master WHERE type='table' AND name='" + tableName + "'")
   
   Dim found
   found = False
   
   While Not tableResult.EOF
      found = True
   WEnd
   
   Set tableResult = Nothing

   CheckTableExists = found
End Function

Sub EnsureSystemTablesExist
   If Not CheckTableExists("SpadeAlbumCollections") Then   
      SDB.Database.ExecSql("CREATE TABLE SpadeAlbumCollections (ID integer PRIMARY KEY AUTOINCREMENT, Name text COLLATE IUNICODE)")
   End If
   
   If Not CheckTableExists("SpadeAlbumCollectionList") Then   
      SDB.Database.ExecSql("CREATE TABLE SpadeAlbumCollectionList (ID integer PRIMARY KEY AUTOINCREMENT, AlbumCollection_ID integer, Artist text COLLATE IUNICODE, Album text COLLATE IUNICODE, AlbumOrder integer, AlbumID integer)")
   End If
End Sub

Sub OnStartUp()
   EnsureSystemTablesExist
End Sub
AngrySpade
 
Posts: 21
Joined: Fri Jun 10, 2011 8:31 pm

Re: Creating Tables Hangs MediaMonkey on Subsequent Start

Postby Bex » Sat Jun 11, 2011 6:22 am

You need to use MM's API to create the tables then it would work fine. Have a look at my Duplicate script and you'll see how to do it.

Also, check out my SQL-Viewer script, with that you can query and run DML/DDL statements without any problems since it's using MM's API.
viewtopic.php?f=2&t=24841

Tip!
In SQLite you can use IF NOT EXISTS so you don't need to check if table exists or not, i.e.
Code: Select all
CREATE TABLE IF NOT EXISTS SpadeAlbumCollectionList (ID integer PRIMARY KEY AUTOINCREMENT, AlbumCollection_ID integer, Artist text COLLATE IUNICODE, Album text COLLATE IUNICODE, AlbumOrder integer, AlbumID integer)
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Bex
 
Posts: 6268
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: Creating Tables Hangs MediaMonkey on Subsequent Start

Postby AngrySpade » Sat Jun 11, 2011 1:15 pm

Thanks for the IF NOT EXISTS tip...

My code above was freezing for other reasons... mostly cause I haven't programmed vbscript in years.
AngrySpade
 
Posts: 21
Joined: Fri Jun 10, 2011 8:31 pm


Return to Addons developer forum

Who is online

Users browsing this forum: No registered users and 0 guests