Android Question Export SQLITE DATA to Text file (.txt)

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Help,
Can i export data sqlite to txt file ?
give me sample program or source code .
Thanks

Something like this:

B4X:
Sub Cursor2CSV(Cursor1 As Cursor, strFolder As String, strCSVFileName As String)
 Dim i As Long
 Dim c As Long
 Dim lstCSV As List
 Dim UB As Long
 Dim UB2 As Int
 UB = Cursor1.RowCount - 1
 UB2 = Cursor1.ColumnCount - 1
 Dim arrFields(UB2 + 1) As String
 lstCSV.Initialize
 Cursor1.Position = 0
 For c = 0 To UB2
  arrFields(c) = Cursor1.GetColumnName(c)
 Next
 lstCSV.Add(arrFields)
 For i = 0 To UB
  Dim Cols(UB2 + 1) As String 'needs to be in the loop, to add new array at every iteration
  Cursor1.Position = i
  For c = 0 To UB2
   Cols(c) = Cursor1.GetString2(c)
   If Cols(c) = Null Then 'to avoid an error at su.SaveCSV
    Cols(c) = ""
   End If
  Next
  lstCSV.Add(Cols)
  Next
 sUtils.SaveCSV(strFolder, strCSVFileName, ",", lstCSV)
 General.ShowMsg("Finished exporting to .csv:" & CRLF & CRLF & _
   strFolder & "/" &  strCSVFileName, "Export to CSV", 0, 0, Null, General.bmpIcon32, True)
End Sub

Public Sub ShowMsg(strPrompt As String, _
         strTitle As String, _
         iTitleColour As Int, _
         iPromptColour As Int, _
         csPrompt As CSBuilder, _
         bmpIcon As Bitmap, _
         bCancelable As Boolean)
 Dim csTitle As CSBuilder
 'so like optional colour argument
 If iTitleColour = 0 Then
  iTitleColour = Colors.RGB(0, 0, 0)
 End If
 If iPromptColour = 0 Then
  iPromptColour = Colors.RGB(0, 0, 0)
 End If
 csTitle.Initialize.Color(iTitleColour).Append(strTitle).Pop
 'so csPrompt is like an optional argument, passing Null works fine
 If csPrompt.IsInitialized = False Then
  csPrompt.Initialize.Color(iPromptColour).Append(strPrompt).Pop
 End If
 'can pass Null for no icon
 Msgbox2Async(csPrompt, csTitle, "OK", "", "", bmpIcon, bCancelable)
End Sub

Needs to set a reference to the StringUtils library (declared as sUtils here).

RBS
 
Upvote 0
Top