Android Question Export SQL Lite to TEXT File

Discussion in 'Android Questions' started by Marlou Fin, Feb 11, 2019.

  1. Marlou Fin

    Marlou Fin Member Licensed User

    Hi Everyone,

    Do we have clear sample for sql lite to text file format?

  2. DonManfred

    DonManfred Expert Licensed User

    You need to write it by yourself as it can not be encapsulated in an Example.

    The Export depends on the Databasestructure YOU defined.
  3. MarkusR

    MarkusR Well-Known Member Licensed User

    pseudo code
    Dim sql1 As SQL = ... open database
    Dim rs As ResultSet = sql1.ExecQuery2("SELECT * FROM TableName WHERE PhotoId = ?",Array As String(PhotoId))
    Do While rs.NextRow

    'build a string here with the fields rs.GetString(index)
        'and use a sub around to replace the delimiter char
        'read sql docu
    '... Close database
    sql/resultset docu access all field names

    read "[B4X] Smart String Literal"


    save csv

    i believe u can get all tables names with a query.
    Last edited: Feb 11, 2019
  4. klaus

    klaus Expert Licensed User

    Why do you need a database converted into a text file, sounds very strange to me !?
    MarkusR likes this.
  5. Mashiane

    Mashiane Expert Licensed User

    As an example, for my needs, I need to embed an existing sqlite db as a JSON text string for 'read' only access to a webapp im using, for example, banano without having to re-create the whole thing.

    I however have been experimenting with sql.js in this instance. #just regressing.
  6. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Something like this should do it:

    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 - 
     UB2 = Cursor1.ColumnCount - 
    Dim arrFields(UB2 + 1As String
     Cursor1.Position = 
    For c = 0 To UB2
      arrFields(c) = Cursor1.GetColumnName(c)
    For i = 0 To UB
    Dim Cols(UB2 + 1As 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
     sUtils.SaveCSV(strFolder, strCSVFileName, 
    ",", lstCSV)
    End Sub
    Needs a reference to StringUtils.

    AnandGupta and Mashiane like this.
  7. Marlou Fin

    Marlou Fin Member Licensed User

    Hi Guys,

    Already have idea for csv with delimiter. My issue now if do we have some sample to export data from my sqlite to text format fix length.

  8. MarkusR

    MarkusR Well-Known Member Licensed User

    u need to process this data later?
    if not u can count each column size and fill it with spaces.
    i not saw any field size commands in the sql class but maybe u can get the field size with a query.
  9. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    select max(length(field1)) from table1

    Works on integer and real (double) data as well.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice