Android Question Supabase result to b4xtable

Please let me know how to show the result of supabase 'DatabaseResult' (which is apparently a string) in b4xtable which requires the data as a list?
 
Solution
I have noticed that my library is quite different from the jrdc2 class. The following should work.

Full Example:
B4X:
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.Columns("*").From("dt_Tasks")
    'Query.Filter_Equal(CreateMap("Tasks_Name":"Task 02"))
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    If DatabaseResult.Error.Success Then
        xSupabase.Database.PrintTable(DatabaseResult)
   
        B4XTable1.AddColumn("Tasks_Id", B4XTable1.COLUMN_TYPE_NUMBERS)
        B4XTable1.AddColumn("Tasks_Name", B4XTable1.COLUMN_TYPE_TEXT)
   
        Dim data As List
        data.Initialize  
        For Each Row As Map In DatabaseResult.Rows  
            Dim Tasks_Id As...

Alexander Stolte

Expert
Licensed User
Longtime User
Have a look at this thread:
I have implemented this in Supabase in the same way as in jrdc2, so it should work in the same way as in the code shown there.
 
Upvote 0
Have a look at this thread:
I have implemented this in Supabase in the same way as in jrdc2, so it should work in the same way as in the code shown there.
Thank you. I tried the following but I am getting error: 'java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error) (Line 9) and in second routine, I get java.lang.ClassCastException: class anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to class [Ljava.lang.Object; (anywheresoftware.b4a.objects.collections.Map$MyMap is in unnamed module of loader 'app'; [Ljava.lang.Object; is in module java.base of loader 'bootstrap') error (line 15):

B4X:
Private Sub Button1_Click
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.Columns("GenderCode, TotalSecurityValue,TotalSecurityValueClass").From("cyberSec")
    Query.Filter_GreatherThanOrEqual(CreateMap("TotalSecurityValue":39))
    Query.Filter_Equal(CreateMap("GenderCode":"Male"))
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    xSupabase.Database.PrintTable(DatabaseResult)
    Log($"Result:${DatabaseResult}"$)
    tbl_res.SetData(DatabaseResult.Rows) 'java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
End Sub
======
If I try this, I get java.lang.ClassCastException: class anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to class [Ljava.lang.Object; (anywheresoftware.b4a.objects.collections.Map$MyMap is in unnamed module of loader 'app'; [Ljava.lang.Object; is in module java.base of loader 'bootstrap')
Dim data As List
    data.Initialize
    For Each row() As Object In DatabaseResult.Rows' Error
        Dim val1 As String = row(DatabaseResult.Columns.Get("GenderCode"))
        Dim val2 As Int = row(DatabaseResult.Columns.Get("TotalSecurityValueClass"))
        data.Add(Array(val1, val2))
    Next
    tbl_res.SetData(data)
 
Last edited:
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I have noticed that my library is quite different from the jrdc2 class. The following should work.

Full Example:
B4X:
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.Columns("*").From("dt_Tasks")
    'Query.Filter_Equal(CreateMap("Tasks_Name":"Task 02"))
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    If DatabaseResult.Error.Success Then
        xSupabase.Database.PrintTable(DatabaseResult)
   
        B4XTable1.AddColumn("Tasks_Id", B4XTable1.COLUMN_TYPE_NUMBERS)
        B4XTable1.AddColumn("Tasks_Name", B4XTable1.COLUMN_TYPE_TEXT)
   
        Dim data As List
        data.Initialize  
        For Each Row As Map In DatabaseResult.Rows  
            Dim Tasks_Id As Int = Row.Get("Tasks_Id")
            Dim Tasks_Name As String = Row.Get("Tasks_Name")
            data.Add(Array(Tasks_Id, Tasks_Name))      
        Next
       
        Wait For (B4XTable1.SetData(data)) Complete (Unused As Boolean)
   
    End If

You can also shorten it a little:
B4X:
        Dim data As List
        data.Initialize   
        For Each Row As Map In DatabaseResult.Rows   
            data.Add(Array(Row.Get("Tasks_Id").As(Int), Row.Get("Tasks_Name").As(String)))
        Next
 
Upvote 1
Solution
Works perfectly!:)
B4X:
Private Sub Button1_Click
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.Columns("GenderCode, TotalSecurityValue,TotalSecurityValueClass").From("cyberSec")
    Query.Filter_GreatherThanOrEqual(CreateMap("TotalSecurityValue":40))
    Query.Filter_Equal(CreateMap("GenderCode":"Male"))
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    xSupabase.Database.PrintTable(DatabaseResult)
    tbl_res.AddColumn("GenderCode", tbl_res.COLUMN_TYPE_TEXT)
    tbl_res.AddColumn("TotalSecurityValueClass", tbl_res.COLUMN_TYPE_TEXT)
    Dim data As List
    data.Initialize
    For Each Row As Map In DatabaseResult.Rows
        Dim Gcode As String = Row.Get("GenderCode")
        Dim TSVC As String = Row.Get("TotalSecurityValueClass")
        data.Add(Array(Gcode, TSVC))
    Next     
    Wait For (tbl_res.SetData(data)) Complete (Unused As Boolean)
End Sub
 
Upvote 0
Top