Sub CsvSongBook_StreamFinish (Success As Boolean, TaskId As Int)
If Success = False Then 'This takes the .CSV file we just downloaded and puts it into a SQLite database
Msgbox("Error SongBook_StreamFinished Failed", "SongBook")
'need to exit here, no need to do the rest****************************************************************************************
End If
Dim List1 As List
Dim String1() As String
'Get a list of Favorites from 'main' and put it in a new table for later use
SQL1.ExecNonQuery("DROP TABLE IF EXISTS favor")
SQL1.ExecNonQuery("CREATE TABLE favor AS SELECT * FROM main WHERE fav = '1'")
List1 = StrUtl.LoadCSV(File.DirInternalCache, "SongBook.csv", ",")'This will take the .csv file and read it into a list,
'Each Row in file will be Array of Strings, one for each column
SQL1.ExecNonQuery("DROP TABLE IF EXISTS main") 'delete old song list
SQL1.ExecNonQuery("CREATE TABLE main (artist TEXT, title TEXT, fav INTEGER)")'create a new table
SQL1.BeginTransaction
Try
For i = 0 To List1.Size - 1
String1 = List1.Get(i) ' Get the Array of Strings from the list.
SQL1.ExecNonQuery("INSERT INTO main VALUES(" & QUOTE & String1(0) & QUOTE & ", " & QUOTE & String1(1) & QUOTE & ", 0);")
Next
SQL1.TransactionSuccessful
Catch
Log(LastException.Message)
Msgbox(LastException.Message, "Error")
End Try
SQL1.EndTransaction 'save all, if no error messages we are good
' Update the new database with our Favorites list
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT * FROM favor WHERE fav = 1")
For i = 0 To Cursor1.RowCount - 1 '"UPDATE main SET fav='1' WHERE title = " & QUOTE & Value & QUOTE & ";")
Cursor1.Position = i
SQL1.ExecNonQuery("UPDATE main SET fav = '1' WHERE artist = " & QUOTE & Cursor1.GetString("artist") & QUOTE & " AND title = " & QUOTE & Cursor1.GetString("title") & QUOTE & ";")
Next
SQL1.ExecNonQuery("DROP TABLE IF EXISTS favor") 'no need to keep this
Cursor1.Close
ProgressDialogHide
End Sub