Problem with creating CSV files

Hero post

Member
Licensed User
Longtime User
I am trying to create csv files from my sql database to be able to transfer them to my PC.
The table contains information, and the cursor shows that all rows are found.
When i use StringUtils.SaveCSV, i get no errors. But I cannot find the resulting file(s) anywhere on my phone.
( I upladed the .apk to the phone and installed it. It works except for the csv creation.)
Any Ideas? Anyone?
:sign0163:
B4X:
Sub SaveWorkoutsToCSV

Dim WorkoutList As List
Dim ExerciseList As List
Dim ne As Int 'row counter to check
Dim qry As String
Dim StringUtils As StringUtils
WorkoutList.Initialize
ExerciseList.Initialize
'workoutlist=DBUtils.ExecuteMemoryTable(SQL1,qry,Null,0)
'Msgbox(File.DirInternal,"workouts")

qry = "Select * from Workouts" 

Dim cur As Cursor
   cur = SQL1.ExecQuery(qry)
Msgbox(cur.RowCount,"number") 'check if any rows are found

   For row = 0 To cur.RowCount - 1
      cur.Position = row
      Dim values(cur.ColumnCount) As String
      For col = 0 To cur.ColumnCount - 1
         values(col) = cur.GetString2(col)
      Next
      WorkoutList.Add(values)
      'Msgbox(values(2),"values") 'check if any data found in col 2
   Next
   cur.Close


StringUtils.SaveCSV(File.Dirinternal, "workouts.csv", ",",WorkoutList)


End Sub
 

Hero post

Member
Licensed User
Longtime User
Ok Thanks that works.
I can now find the with the filemanager on my phone.
(but not through the usb connection from my PC. Weird, but a minor inconvenience it hope.)
Hero
 
Upvote 0

Hero post

Member
Licensed User
Longtime User
New challenge

Not quite there yet.
It only stores one ( the first) row in the exproted file
.

Ooops problem with phone software.
Found file, copied it to pc readable location, loaded it in PC excel, and file is complete.
Thanks for your support. Couldn't do it without it
 
Last edited:
Upvote 0

Hero post

Member
Licensed User
Longtime User
New files not visible

A hint for all users.
With some devices it is necessary to reconnect the device with the PC (or even reboot the device) before file become availabel via a USB link.
(found several remarks about this on the internet)
 
Upvote 0

Hero post

Member
Licensed User
Longtime User
Still no luck

sorry,
does not seem to do the job. I changed the code to:
B4X:
WorkoutList.Initialize
   qry = "Select * from Workouts"
   WorkoutList=DBUtils.ExecuteMemoryTable(SQL1,qry,Null,0)
   StringUtils.SaveCSV(File.DirRootExternal&"/F4Mexports" , "workouts.csv", ",",WorkoutList)
   i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & File.Combine(File.DirRootexternal&"/F4Mexports", "workouts.csv"))
Phone.SendBroadcastIntent(i)
but still the file are only visible after rebooting then phone.
 
Upvote 0
Top