StatusLbl.Text = "Importing data. Please wait..."
StatusLbl.Invalidate ' Force redraw
OurLoc = CopyFileFromAssets(G.TFName) 'Get data file from assets
' Download data file to simulated SD card)
G.SQL1.Initialize(G.DBFileDir, G.DBFileName, True)
G.SQL1.ExecNonQuery("Drop table if exists DEntries")
'None of the following should need default values as they will only be read, not written
G.SQL1.ExecNonQuery("Create table DEntries(Dt Text Primary Key, Tm Text, Weather Text, Mood Integer, Entry Text, Travelling Text, TKey Text, Mood2 Integer, Mood3 Integer, CertX Integer)")
StatusLbl.Text = "Importing data. Please wait..."
StatusLbl.Invalidate ' Force redraw
' Note that text file currently needs to be copied to the emulator
Try ' Load all the data into memory
'Comma is no good as separator because it includes commas WITHIN entries
Table = SU.LoadCSV(File.DirRootExternal, G.TFName, "|")
For X = 0 To Table.Size - 1
Recd = Table.Get(X) ' Get a row of the text file
For N = 0 To Recd.Length - 1
If X <= 10 Then
Log("Record " & X & " Item " & N & ": " & Recd(N)) ' Show some of the import in log viewer
End If
Next 'N
Next 'X
X = Table.Size
Log("Finished loading data into memory. " & X & " entries.")
' Now add data from list in memory to table
Try
G.SQL1.BeginTransaction
For i = 0 To Table.Size - 1
Dim sColumn() As String
sColumn = Table.Get(i)
' Log("Record number " & i & " " & Table.Get(i))
G.SQL1.ExecNonQuery2("INSERT INTO DEntries (Dt, Tm, Weather, Mood, Entry, Travelling, TKey, Mood2, Mood3, CertX) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", sColumn)
Next
G.SQL1.TransactionSuccessful
Catch
Msgbox ("Error populating table: " & LastException, G.AppName)
End Try