Not sure if you can put an order by clause in the statement or not. Haven't tried it.
B4X:
Dim table1 As List
table1 = DBUtils.ExecuteMemoryTable(SQL1, "SELECT * FROM database1", Null, 0)
Dim si As StringUtils
si.SaveCSV(File.Whereveryouwanttosaveit, "whatever.csv", ";", table1)
table1.Clear
Sub ExportToCSV
Dim CSVList As List
CSVList.Initialize
db.FirstRecord
For i = 0 To db.Record_Count -1
Dim NewRecord As String
For ii = 0 To db.ActiveFields -1
If ii < db.ActiveFields -1 Then
NewRecord = NewRecord & db.GetField("var" & ii) & ","
Else
NewRecord = NewRecord & db.GetField("var" & ii) & CRLF
End If
Next
CSVList.Add(NewRecord)
db.NextRecord
Next
File.WriteList(File.DirRootExternal, "newlist.csv", CSVList)
End Sub
In your case for a header you can add this just under the CSVList.Initialize:
B4X:
For ii = 0 To db.ActiveFields -1
Dim Header As String
If ii < db.ActiveFields -1 Then
Header = Header & "var" & ii+1 & ","
Else
Header = Header & "var" & ii+1 & CRLF
End If
Next
CSVList.Add(Header)
'Create header on top row of CSV
For ii = 1 To db.ActiveFields
Dim Header As String
If ii < db.ActiveFields Then
Header = Header & "var" & ii & ","
Else
Header = Header & "var" & ii
End If
Next
Change it to this:
B4X:
'Create header on top row of CSV
Dim Header As String
For ii = 1 To db.ActiveFields
If ii < db.ActiveFields Then
Header = Header & "var" & ii & ","
Else
Header = Header & "var" & ii
End If
Next
The Dim statement should been before the For Next, Sorry
If you look in the Class code, you will see this line in the Class_Globals sub:
B4X:
Type DataDetails (WAFileName As String, WAFilePath As String, WAField(30) As String, WAPointer As Int, WARecordCount As Int)
1..Just change the WAField(30) to what ever number you want. This is just a default I stuck in there.
2..Yes, that's correct
3..The list sorts by field1 + field2 + field3, etc. So each field is part of the sort order. No easy way to change this.
4..This is not a problem anymore and the answer to number 1, fixes this issue.
Also, I am working on a new Sub you can add to the class for the Header names so you will not need a select case. I'll post it as soon as I have it. You just will add this sub to the class module.
The number will use up some memory but not much. I would try to keep it as low as possible. Say, you may need 100, set it to 150 and you should be fine. Even then the strings are not used and are null so I don't think it will really use that much memory.
Hi,
What is the easiest method to import a csv file into your database along with the headers from the first row.
I am using a '|' as a seperator.
BTW the file has around 6000 records and 70 fields, so I will need to expand the field count.
Is this done globally or on a file by file basis.
The finished project will be using about 8 databases.
These will then be imported into my Delphi project on demand.
Is the easiest method just to copy the database files from the Android to the pc then import.
I have used an ftp server on the pc and this works quiet well.