Android Question App crashes importing lots of records from csv file while adding row to ListofMaps

GeoffT660

Active Member
Licensed User
Longtime User
I am trying to import over 6000 records from a csv file into a sqllite table on the device and it crashes after importing a little more then 2000 records without a log error. My code crashes while ListOfMaps.Add(m). All the smaller tables work fine under this method. Is there a better method I should be using to import large amounts of records?
 

Emme Developer

Well-Known Member
Licensed User
Longtime User
Can you post the revelant log?
Be sure you are using Transation meanwhile you are doing heavy operation on database and launching nonquery
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
Can you post the revelant log?
Be sure you are using Transation meanwhile you are doing heavy operation on database and launching nonquery
I'm very new at this and nothing posts to the log in the IDE when it crashes. Is there another log I can look at? This is the code I'm using and it fails while in the loop adding records to the map. Works fine on smaller tables. What do you mean by "using Transaction"?

Log("finished writing csv file to external default directory")
Dim ListOfMaps As List
ListOfMaps.Initialize
Dim existemap As Map
existemap.Initialize
Dim start, finish As Int
start = 0
finish = 9
Dim readcsv As List
Dim csv As StringUtils
readcsv.Initialize
'Read the saved csv file into a list
readcsv = csv.LoadCSV(File.DirDefaultExternal, strTableName, ",")
Dim columnlist As List
Dim cols() As String
columnlist.Initialize
'read the first line of the list which contains the column names into cols variable
cols = readcsv.Get(0)
'place the column names into another list to be able to build a map with column names and field values
For l = 0 To cols.Length - 1
columnlist.Add(cols(l))
Next
Dim cnt As Int
'build a map with column names and field values
For i = 1 To readcsv.Size - 1
Dim m As Map
m.Initialize
Dim reading() As String
'read each field value into an array of strings
reading = readcsv.Get(i)
For j = 0 To reading.Length - 1
'place the each column name and each field value in a map
m.Put(columnlist.Get(j), reading(j))
Next
'check if records exist, so we won't insert them again.
'Dim existe As Int
'existe = DBUtils.RecordExists(SQL1, "wcJobLog", m)
'If existe > 0 Then
'Log("Record already exists, skipping...")
'Else
'add the map into a list
ListOfMaps.Add(m)
cnt= cnt + 1
Log(cnt)
'End If
Next
If ListOfMaps.Size > 0 Then
DBUtils.InsertMaps(SQL1, strTable, ListOfMaps)
ProgressDialogHide
Else
ProgressDialogHide
End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…