W wheretheidivides Active Member Licensed User Longtime User Jan 9, 2013 #1 . Last edited: May 24, 2020
D Dman Active Member Licensed User Longtime User Jan 9, 2013 #2 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
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
D Dman Active Member Licensed User Longtime User Jan 9, 2013 #3 Here's my global for the SQL1. Yours might be named something different Sub Process_Globals Dim SQL1 As SQL Upvote 0
Here's my global for the SQL1. Yours might be named something different Sub Process_Globals Dim SQL1 As SQL
D Dman Active Member Licensed User Longtime User Jan 9, 2013 #4 I'm not familiar with Margets class. Is dbtips.dat your database table name? Upvote 0
mangojack Expert Licensed User Longtime User Jan 9, 2013 #5 A database created with Margarets DB class sorts on the first field/column Cheers mj Upvote 0
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #6 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
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
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #7 You caused the error when you changed the ii = 0 to a 1. Change it back to a 0 and the change the two lines below like: Code: Copy NewRecord = NewRecord & db.GetField("var" & ii+1) & "," NewRecord = NewRecord & db.GetField("var" & ii+1) & CRLF Upvote 0
You caused the error when you changed the ii = 0 to a 1. Change it back to a 0 and the change the two lines below like: Code: Copy NewRecord = NewRecord & db.GetField("var" & ii+1) & "," NewRecord = NewRecord & db.GetField("var" & ii+1) & CRLF
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #8 In your case for a header you can add this just under the CSVList.Initialize: Code: Copy 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) Upvote 0
In your case for a header you can add this just under the CSVList.Initialize: Code: Copy 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)
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #9 Try putting them like: ("var" & (ii+1)) Upvote 0
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #10 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
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
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #11 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: Jan 9, 2013 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.
margret Well-Known Member Licensed User Longtime User Jan 9, 2013 #12 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. Upvote 0
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.
TomDuncan Active Member Licensed User Longtime User Apr 3, 2013 #13 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
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:
Erel B4X founder Staff member Licensed User Longtime User Apr 3, 2013 #14 Please start a new thread for this question. Upvote 0