Android Question .

Not sure if you can put an order by clause in the statement or not. Haven't tried it.


Code: Copy
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
 
Upvote 0
Here's my global for the SQL1. Yours might be named something different

Sub Process_Globals

Dim SQL1 As SQL
 
Upvote 0
A database created with Margarets DB class sorts on the first field/column

Cheers mj
 
Upvote 0
You can use code something like this:

Code: Copy
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
 
Upvote 0
OK you now have:

Code: Copy
'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:

Code: Copy
'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
 
Upvote 0
If you look in the Class code, you will see this line in the Class_Globals sub:

Code: Copy
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.
 
Last edited:
Upvote 0
Loading from a CSV database

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.

Tom :sign0104:
 
Upvote 0
Back
Top