Android Question Supabase problem

Aldo's

Active Member
Licensed User
I created a database in the Supabase online tool.
I inserted the library and tried to initialize.
It can't find the database...or at least that's what I understand.
What values should be placed in the initialization? The web address of my database in the online tool? The password I created?

Please bear with me but I am absolutely new to realtime databases.
 

Aldo's

Active Member
Licensed User
I think I've made some progress.
I wrote this code:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    xSupabase.Initialize("https://qualcosa.supabase.co","miapassword")
    xSupabase.InitializeEvents(Me,"Supabase")
End Sub

Private Sub bttLogin_Click
Log("1")
    Dim sUserid As String = sdIconTxtUserId.Text
Log("2")
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
Log("3")
    Query.Columns("*").From("users")
Log("4")
    Query.Filter_Equal(CreateMap("userid":sUserid))
Log("5")
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
Log("6")
    xSupabase.Database.PrintTable(DatabaseResult)
Log("7")
    For Each Row As Map In DatabaseResult.Rows
Log("8")
        Log(Row.Get("mail"))
Log("9")
    Next
End Sub

The log numbers go up to 6 so it is conceivable that the problem is before Log("7").
How about?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Query.Columns("*").From("users")
Is the "users" table a table you created yourself? If it is not, then it is the one from the authentication and you cannot query it from outside the Auth class

What values should be placed in the initialization? The web address of my database in the online tool? The password I created?
You find the infos in the supabase dashboard:
1710012752111.png

First paramater is the number "3" and the second parameter is the number "4" at the picture
 

Attachments

  • 1710012469759.png
    1710012469759.png
    5.5 KB · Views: 69
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Moreover, it is usefull after every query, to check if the result was successful, like this:
B4X:
Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.From("workoutcalendar").Filter_Equal(CreateMap("wcdate":DateTime.Date(FirstDate),"id_gym":"3b48-4ca2-a580-180e23963380")).OrderBy("wctime.asc")
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    If DatabaseResult.Error.Success Then
        'Result was OK, so you can handle the result
        For Each Row As Map In DatabaseResult.Rows

        Next
    Else
        'There was an error. See your logs for the error description
        log(DatabaseResult.Error.ErrorMessage)
    End If
 
Last edited:
Upvote 0

Aldo's

Active Member
Licensed User
Update.
I wrote this code:
B4X:
Private Sub bttLogin_Click
    Dim sUserid As String = sdIconTxtUserId.Text
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.Columns("*").From("utenti")
    Query.Filter_Equal(CreateMap("userid":sUserid))
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    If DatabaseResult.Error.Success Then
        For Each Row As Map In DatabaseResult.Rows
            Log("8")
            Log(Row.Get("mail"))
            Log("9")
        Next
    Else
        'There was an error. See your logs for the error description
        Log(DatabaseResult.Error.ErrorMessage)
    End If
End Sub
and I get this error:
Error occurred on line: 67 (B4XMainPage)
java.lang.RuntimeException: Field: Error not found in: aldopanizzi.fantalega.supabase$_supabaseerror

Line 67 is:
B4X:
    If DatabaseResult.Error.Success Then

Is something missing from my Supabase project?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Is something missing from my Supabase project?
It works for me.

Make sure that you:
-The user must be logged in before you query the database
-Check that your RLS (Role Level Security) policies are set correctly in the table you are trying to query
 
Upvote 0

Aldo's

Active Member
Licensed User
You're right, the problem was in the authentication.
Now it authenticates me and gives me the correct authentication message.
However, I would like to run a query at the end of the authentication... but it doesn't give any results, not even an error.
My code is:
B4X:
Private Sub bttLogin_Click
    sUserid = sdIconTxtUserId.Text
    Dim sPassword As String = sdIconTxtPassword.Text
    Wait For (xSupabase.Auth.LogIn_EmailPassword(sUserid,sPassword)) Complete (User As SupabaseUser)
    If User.Error.Success Then
        Log("successfully logged in with " & User.Email)
    Else
        Log("Error: " & User.Error.ErrorMessage)
    End If
    
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Dim lID As Long
    Query.Columns("*").From("utenti")
    Query.Filter_Equal(CreateMap("mail":sUserid))
    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    If DatabaseResult.Error.Success Then
        For Each Row As Map In DatabaseResult.Rows
            lID=Row.Get("id")
            Log("lID:" & lID)
        Next
    Else
        Log(DatabaseResult.Error.ErrorMessage)
    End If
    Main.idUser=lID
End Sub
 
  • Like
Reactions: byz
Upvote 0
Top