Android Question SaveCSV2() skips some records [SOLVED]

Didier9

Well-Known Member
Licensed User
Longtime User
Nor sure how to formulate it differently.
I call SaveCSV2() with a list that has 276 records but I get only 175 records in the CSV file.

I start from an SQLite database. I enter the code below with a Cursor containing the entire database.
B4X:
Dim LogList, hdr as List
LogList.Initialize
hdr.Initialize2( Array As String( "Date", "Amount","Business" ,"Category", "Description", "Vendor", "Bank", "Picture" ))
Log( "ExportDB.CSV.Log.RowCount: " & Cursor1.RowCount
' now save data
For row = 0 To Cursor1.RowCount - 1
    Private RowData( Cursor1.ColumnCount ) As String
    Cursor1.Position = row                                'set the Cursor to each row
    ' save the date
    RowData( 0 ) = DateTime.Date( Cursor1.GetLong2( 0 ) )
    ' then save the data columns
    For col = 1 To Cursor1.ColumnCount-1
        If Cursor1.GetString2( col ) <> Null Then
             RowData( col ) = Cursor1.GetString2( col ).Replace( CRLF, " " ) ' eliminate new line that may be embedded in Description field
        Else
             RowData( col ) = ""
        End If
    Next
    LogList.Add( RowData )
Next
Log( "ExportDB.CSV.LogList.Size = " & LogList.Size )
hdr.Initialize2( Array As String( "Date", "Amount","Business" ,"Category", "Description", "Vendor", "Bank", "Picture" ))
su.SaveCSV2( Starter.DownloadPath, FileName, ",", LogList, hdr )
I check the rowcount of the cursor and it indicates 276.
I check the size of the list right before calling SaveCSV2() and it shows 276.
Yet the file only has 175 records.
The missing records are not at the beginning or the end, they are anywhere in between. I have the feeling that it may be content related, but as the code shows, I check that all the fields have non-null content and I also remove the CRLF that may be in some fields.
I am surprised that the SaveCSV2() function skips records without complaining about something.
Any help as to where to start looking would be appreciated.

PS: I did earlier testing of the code with a short database (a dozen records) and everything was working fine, so I did not expect this :)
 

Didier9

Well-Known Member
Licensed User
Longtime User
I would try removing the Replace method and then check the result.

SaveCSV (and Load, of course) uses LF as end of line, as far I know.

I had to add it because some fields had a new line and that caused extra lines in the csv file. I cannot remove it unless I update the entire database first.
I also added the Null check because that was crashing SaveCSV2().
Why do you think it is causing problems?
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I would try removing the Replace method and then check the result.

SaveCSV (and Load, of course) uses LF as end of line, as far I know.

The reduced CSV file I get is otherwise properly formatted. SaveCSV2() takes a list for input, I am not sure where I should place an LF.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Problem resolved, it was squarely between my ears :)
Sorry for the bandwidth...

tl;dr: I was looking at an earlier version of the csv file because the mail app was attaching a file from the wrong folder
 
Upvote 0
Top