SQLite to csv

lawboy

Member
Licensed User
Longtime User
Hello,
Is there a quick simple way to write the entire sqlite table (including headers) to a txt file using b4a?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
fecha=DateTime.Date(DateTime.Now)
hora=DateTime.GetHour(DateTime.Now)&":"&DateTime.GetMinute(DateTime.Now)
mes=DateTime.GetMonth(DateTime.Now)
año=DateTime.GetYear(DateTime.Now)

Dim su As StringUtils
    Dim Cursor1 As Cursor
    Cursor1 = informes.ExecQuery("SELECT FECHA, HORA, FASE, FRECUENCIA, FACTOR_DE_POTENCIA, VOLTAJE, CORRIENTE, POTENCIA, POTENCIA_REACTIVA, POTENCIA_APARENTE, ENERGIA, hola, TENSION_COMPUESTA FROM informe")
    Dim list1 As List
    list1.Initialize
    For i = 0 To Cursor1.RowCount - 1
        Dim cols() As String ' Try to move this line into the for-loop
        Cursor1.Position = i
        cols = Array As String(Cursor1.GetString2(0), Cursor1.GetString2(1), Cursor1.GetString2(2), Cursor1.GetString2(3), Cursor1.GetString2(4), Cursor1.GetString2(5),Cursor1.GetString2(6), Cursor1.GetString2(7), Cursor1.GetString2(8), Cursor1.GetString2(9), Cursor1.GetString2(10), Cursor1.GetString2(11),Cursor1.GetString2(12))
        list1.Add(cols)
    
    Next
    Cursor1.Close
    If list1.Size > 0 Then
       su.SaveCSV2(File.DirRootExternal, "Informes_"&mes&"-"&año&".csv", ",", list1, Array As String("FECHA", "HORA", "FASE","FRECUENCIA", "FACTOR DE POTENCIA", "VOLTAJE","CORRIENTE", "POTENCIA", "POTENCIA REACTIVA","POTENCIA APARENTE", "ENERGIA", " ", "TENSION COMPUESTA"))
    Else

    ToastMessageShow("No hay datos suficientes",True)
    End If

If that does not work you probably need to create a testproject and export it as zip (including database) and a description on how to get the error.
 
Last edited:
Upvote 0

delozoya

Member
Licensed User
Longtime User
If i create both a DB and the CSV i dont have problem, but when there is already create, the csv have problem, But in other test I have yet a DB and Create well the CSV with the same code
 
Upvote 0
Top