G GeoffT660 Active Member Licensed User Longtime User Jan 28, 2015 #1 I'm looking for the easiest most efficient way to read a text string or file into a device sqlLite table of the same structure as the server table. I have been able to receive either a text string or create a text file on the server and download it through httpUtils2 but am still unable to figure this out: 1) Save the downloaded file to a directory on the device 2) Parse the delimited text, whether streamed with Job.GetString or from the downloaded text file and append the records to a table. Please let me know how this can be done.
I'm looking for the easiest most efficient way to read a text string or file into a device sqlLite table of the same structure as the server table. I have been able to receive either a text string or create a text file on the server and download it through httpUtils2 but am still unable to figure this out: 1) Save the downloaded file to a directory on the device 2) Parse the delimited text, whether streamed with Job.GetString or from the downloaded text file and append the records to a table. Please let me know how this can be done.
KMatle Expert Licensed User Longtime User Jan 28, 2015 #2 Can you describe an example? Generally: Files are files and data ist the content of a file or a table. What I mean is: Is it's a file then store it as a file. Only the index is stored in a table (with the path). If you need contents of the file it, then get the contents and store it in a table: Get file from a folder on a server: Code: Dim GetImage As HttpJob GetImage.Initialize("GetImage", Me) GetImage.Tag=filename GetImage.Download(ServerPath & FTPFolder & "/" & filename) Save it to the device: Code: Dim out As OutputStream out = File.OpenOutput(mypath & "/" & myFolder& "/", Job.Tag, False) File.Copy2(Job.GetInputStream,out) out.close To read a file (to get the content) take a look to other examples in the forum. Upvote 0
Can you describe an example? Generally: Files are files and data ist the content of a file or a table. What I mean is: Is it's a file then store it as a file. Only the index is stored in a table (with the path). If you need contents of the file it, then get the contents and store it in a table: Get file from a folder on a server: Code: Dim GetImage As HttpJob GetImage.Initialize("GetImage", Me) GetImage.Tag=filename GetImage.Download(ServerPath & FTPFolder & "/" & filename) Save it to the device: Code: Dim out As OutputStream out = File.OpenOutput(mypath & "/" & myFolder& "/", Job.Tag, False) File.Copy2(Job.GetInputStream,out) out.close To read a file (to get the content) take a look to other examples in the forum.
G GeoffT660 Active Member Licensed User Longtime User Jan 28, 2015 #3 Thanks, I was able to download and save the file in the desired location. I did not find any references to reading the comma delimited file (csv) and appending the rows to a table of the same format in the links. Do you have any information or know where I can find examples on that. Upvote 0
Thanks, I was able to download and save the file in the desired location. I did not find any references to reading the comma delimited file (csv) and appending the rows to a table of the same format in the links. Do you have any information or know where I can find examples on that.
DonManfred Expert Licensed User Longtime User Jan 29, 2015 #4 Something like this Code: Dim List1 As List List1 = File.ReadList(File.DirDefaultExternal, "1.txt") For i = 0 To List1.Size - 1 Dim components() As String components = Regex.Split(",", List1.Get(i)) For u = 0 To components.Length-1 Log(components(u)) Next Next Upvote 0
Something like this Code: Dim List1 As List List1 = File.ReadList(File.DirDefaultExternal, "1.txt") For i = 0 To List1.Size - 1 Dim components() As String components = Regex.Split(",", List1.Get(i)) For u = 0 To components.Length-1 Log(components(u)) Next Next
Beja Expert Licensed User Longtime User Jan 29, 2015 #5 Generally: Files are files and data ist the content of a file or a table. Click to expand... @ KMatle, remember to a add the above section to Murphy's Law #26 Upvote 0
Generally: Files are files and data ist the content of a file or a table. Click to expand... @ KMatle, remember to a add the above section to Murphy's Law #26
Erel B4X founder Staff member Licensed User Longtime User Jan 29, 2015 #6 You can use StringUtils.LoadCSV to read CSV files. Upvote 0
G GeoffT660 Active Member Licensed User Longtime User Jan 30, 2015 #7 DonManfred said: Dim List1 As List List1 = File.ReadList(File.DirDefaultExternal, "1.txt") For i = 0 To List1.Size - 1 Dim components() As String components = Regex.Split(",", List1.Get(i)) For u = 0 To components.Length-1 Log(components(u)) Next Next Click to expand... Thanks. That did work fine I will start a new thread concerning appending to a SQL Lite Table. Upvote 0
DonManfred said: Dim List1 As List List1 = File.ReadList(File.DirDefaultExternal, "1.txt") For i = 0 To List1.Size - 1 Dim components() As String components = Regex.Split(",", List1.Get(i)) For u = 0 To components.Length-1 Log(components(u)) Next Next Click to expand... Thanks. That did work fine I will start a new thread concerning appending to a SQL Lite Table.
Erel B4X founder Staff member Licensed User Longtime User Jan 30, 2015 #8 Note that this code will fail if there are fields with commas. StringUtils.LoadCSV will work correctly. Upvote 0
Note that this code will fail if there are fields with commas. StringUtils.LoadCSV will work correctly.
G GeoffT660 Active Member Licensed User Longtime User Jan 30, 2015 #9 Thanks. I'll try LoadCSV. Upvote 0