Sample Read and Write Method(s): Difference between revisions

From MediaMonkey Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
  '
  '
  ' Template Author: MoDementia
  ' Template Author: MoDementia
' Generated by MMWiki page {{PAGENAME}}
  ' Time, DATE :  22:31, 09 April 2008
  ' Time, DATE :  {{CURRENTTIME}}, {{CURRENTDAY2}} {{CURRENTMONTHNAME}} {{CURRENTYEAR}}
  '
  '
  'Sample of Scripting Code for inclusion into MMWiki pages
  'Sample of Scripting Code Read and Write Method(s)
  'A working script to show database results using various selection methods
  'A working script to show database results using various selection methods
  '
  '
Line 24: Line 23:
   
   
  Sub WikiSample
  Sub WikiSample
<span style="color: #b1b100;">Sub</span>
  Dim SelectMethod, SampleID, <span style="background:#CCFFCC;">Value Type</span>New<span style="background:#FFCC99;">Value Name</span>
  Dim SelectMethod, SampleID, {{{3|-}}}New{{{2|-}}}
{{#ifeq:{{{3|-}}}|Object| |  Dim SQLString                                                            'SelectMethod 3}}
{{#ifeq:{{{3|-}}}|Object| |  Dim SQLString                                                            'SelectMethod 3}}
   Dim objSongList                                                          'SelectMethod 2
   Dim objSongList                                                          'SelectMethod 2
Line 36: Line 34:
    
    
   SampleID = 13123
   SampleID = 13123
   {{{3|-}}}New{{{2|-}}} = "Mamma Mia"
   <span style="background:#CCFFCC;">Value Type</span>New<span style="background:#FFCC99;">Value Name</span> = "Mamma Mia"
   Set objSongList = SDB.NewSongList                                        'SelectMethod 2 and 3 [[ISDBApplication::NewSongList|SDB.NewSongList]]
   Set objSongList = SDB.NewSongList                                        'SelectMethod 2 and 3 [[ISDBApplication::NewSongList|SDB.NewSongList]]
    
    
Line 45: Line 43:
       Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) '[[ISDBDatabase::QuerySongs|SDB.Database.QuerySongs]]
       Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) '[[ISDBDatabase::QuerySongs|SDB.Database.QuerySongs]]
{{#ifeq:{{{3|-}}}|Object| |    Case 3}}
{{#ifeq:{{{3|-}}}|Object| |    Case 3}}
{{#ifeq:{{{3|-}}}|Object| |      SQLString = "SELECT {{{5|-}}} FROM {{{4|-}}} WHERE {{{4|-}}}.ID = " & SampleID}}
{{#ifeq:{{{3|-}}}|Object| |      SQLString = "SELECT <span style="background:#CC99FF;">Field Name</span> FROM <span style="background:#CC99FF;">Database Table</span> WHERE <span style="background:#CC99FF;">Database Table</span>.ID = " & SampleID}}
{{#ifeq:{{{3|-}}}|Object| |      Set objSongListiterator = SDB.Database.OpenSQL(SQLString)            '[[ISDBDatabase::OpenSQL|SDB.Database.OpenSQL]]}}
{{#ifeq:{{{3|-}}}|Object| |      Set objSongListiterator = SDB.Database.OpenSQL(SQLString)            '[[ISDBDatabase::OpenSQL|SDB.Database.OpenSQL]]}}
     Case 4
     Case 4
Line 61: Line 59:
       objSongList.Add(objSongData)                                        'SelectMethod 2
       objSongList.Add(objSongData)                                        'SelectMethod 2
       Set objSongData = objSongList.Item(iCounter)                        'SelectMethod 4
       Set objSongData = objSongList.Item(iCounter)                        'SelectMethod 4
       {{{3|-}}}{{{2|-}}} = objSongData.{{{2|-}}}{{#ifeq:{{{3|-}}}|Object|.Member}}                                      'SelectMethod 1, 2 and 4
       <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> = objSongData.<span style="background:#FFCC99;">Value Name</span>{{#ifeq:{{{3|-}}}|Object|.Member}}                                      'SelectMethod 1, 2 and 4
       SDB.MessageBox "Value = '" & {{{3|-}}}{{{2|-}}} & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)
       SDB.MessageBox "Value = '" & <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)
{{#ifeq:{{{3|-}}}|Object| |      {{{3|-}}}{{{2|-}}} = objSongListiterator.StringByIndex(0)                  'SelectMethod 3}}
{{#ifeq:{{{3|-}}}|Object| |      <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> = objSongListiterator.StringByIndex(0)                  'SelectMethod 3}}
     objSongListiterator.Next                                              'SelectMethod 2 and 3
     objSongListiterator.Next                                              'SelectMethod 2 and 3
     Wend                                                                  'SelectMethod 2 and 3
     Wend                                                                  'SelectMethod 2 and 3
Line 69: Line 67:
   Set objSongListiterator=Nothing                                          'SelectMethod 2 and 3
   Set objSongListiterator=Nothing                                          'SelectMethod 2 and 3
   
   
   SDB.MessageBox "Value = '" & {{{3|-}}}{{{2|-}}} & "'", mtError, Array(mbOK)
   SDB.MessageBox "Value = '" & <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> & "'", mtError, Array(mbOK)
   
   
  '  objSongData.{{{2|-}}}{{#ifeq:{{{3|-}}}|Object|.Member}} = {{{3|-}}}New{{{2|-}}} 'Commented Out For Safety 'SelectMethod 1, 2 and 4
  '  objSongData.<span style="background:#FFCC99;">Value Name</span>{{#ifeq:{{{3|-}}}|Object|.Member}} = <span style="background:#CCFFCC;">Value Type</span>New<span style="background:#FFCC99;">Value Name</span> 'Commented Out For Safety 'SelectMethod 1, 2 and 4
  '  objSonglist.UpdateAll              'Commented Out For Safety            '[[SDBSongData|UpdateAll]]
  '  objSonglist.UpdateAll              'Commented Out For Safety            '[[SDBSongData|UpdateAll]]
                           'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
                           'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
  End Sub
  End Sub

Revision as of 06:20, 10 April 2008

'
' MediaMonkey Script
'
' NAME: WikiSample.vbs
'
' Template Author: MoDementia
' Time, DATE :  22:31, 09 April 2008
'
'Sample of Scripting Code Read and Write Method(s)
'A working script to show database results using various selection methods
'
'MediaMonkey\Scripts\Scripts.in entry
'
'[WikiSample]                                                             'Format of the Scripts.ini file
'Filename=WikiSample.vbs
'Procname=WikiSample
'Order=99
'DisplayName=WikiSample
'Description=Displays the raw database value of the MMWikipage item
'Language=VBScript
'ScriptType=0


Sub WikiSample
  Dim SelectMethod, SampleID, Value TypeNewValue Name

Dim SQLString 'SelectMethod 3

  Dim objSongList                                                          'SelectMethod 2

  SelectMethod = 1
  ' SelectMethod NowPlaying = 1
  ' SelectMethod UseSQLQuery = 2

' SelectMethod UseSQL = 3

  ' SelectMethod SelectedSongs = 4
  
  SampleID = 13123
  Value TypeNewValue Name = "Mamma Mia"
  Set objSongList = SDB.NewSongList                                        'SelectMethod 2 and 3 SDB.NewSongList
  
  Select Case SelectMethod
    Case 1
      Set objSongData = SDB.Player.CurrentSong                             'SDB.Player.CurrentSong
    Case 2
      Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs

Case 3 SQLString = "SELECT Field Name FROM Database Table WHERE Database Table.ID = " & SampleID Set objSongListiterator = SDB.Database.OpenSQL(SQLString) 'SDB.Database.OpenSQL

    Case 4
      Set objSongList = SDB.SelectedSongList                               'SDB.SelectedSongList
'       Set objSongList = SDB.CurrentSongList                              'SDB.CurrentSongList
'       Set objSongList = SDB.AllVisibleSongList                           'SDB.AllVisibleSongList
    Case Else
      SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK)      'SDB.MessageBox
      Exit Sub
  End Select
  
  For iCounter = 0 to objSongList.count - 1                                'SelectMethod 4 SongLists
    While Not objSongListiterator.EOF                                      'SelectMethod 2 and 3 Iterator
      Set objSongData = objSongListiterator.Item                           'SelectMethod 2
      objSongList.Add(objSongData)                                         'SelectMethod 2
      Set objSongData = objSongList.Item(iCounter)                         'SelectMethod 4
      Value TypeValue Name = objSongData.Value Name                                      'SelectMethod 1, 2 and 4
      SDB.MessageBox "Value = '" & Value TypeValue Name & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)

Value TypeValue Name = objSongListiterator.StringByIndex(0) 'SelectMethod 3

    objSongListiterator.Next                                               'SelectMethod 2 and 3
    Wend                                                                   'SelectMethod 2 and 3
  Next                                                                     'SelectMethod 4
  Set objSongListiterator=Nothing                                          'SelectMethod 2 and 3

  SDB.MessageBox "Value = '" & Value TypeValue Name & "'", mtError, Array(mbOK)

'  objSongData.Value Name = Value TypeNewValue Name 'Commented Out For Safety 'SelectMethod 1, 2 and 4
'  objSonglist.UpdateAll              'Commented Out For Safety            'UpdateAll
                         'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
End Sub