B4J Question [ABMaterial][Supabase] Can we use them both?

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello team,

Last month i created a webapp using both of them. Everything working fine in debug and release mode in my pc (localhost:8081). When i upload at my ubuntu VPS, i encounter many errors. Here is a sample code that i use to store personal data to Supabase:
B4X:
Sub btnSave_Clicked(Target As String, SubTarget As String)
 
    page.PauseDelayed(500)

    'I get all data from inputs(edittexts)
    Dim etSurname As ABMInput = page.Component("etSurname")
    Dim etName As ABMInput = page.Component("etName")
    Dim etMail As ABMInput = page.Component("etMail")
    Dim comboSex As ABMCombo = page.Component("comboSex")
    Dim etPhone As ABMInput = page.Component("etPhone")
    Dim etPhoneEme As ABMInput = page.Component("etPhoneEme")
    Dim etTown As ABMInput = page.Component("etTown")
    Dim etPostal As ABMInput = page.Component("etPostal")
    Dim etStreet As ABMInput = page.Component("etStreet")
    Dim etNumber As ABMInput = page.Component("etNumber")
 
    'i create update statement in order to update the correct columns
    Dim Update As Supabase_DatabaseUpdate = Main.xSupabase.Database.UpdateData
    Update.From("users")
    Update.SelectData
    Update.Update(CreateMap("surname":etSurname.Text.Trim,"name":etName.Text.Trim,"email":etMail.Text.Trim, "sex": comboSex.GetActiveItemId, _
                         "town":etTown.Text.Trim,"postal":etPostal.Text.Trim,"street":etStreet.Text.Trim, _
                        "number":etNumber.Text.Trim,"phone":etPhone.Text.Trim,"phone_eme":etPhoneEme.Text.Trim))
    Update.Eq(CreateMap("id":Main.userData.id))
    Wait For (Update.Execute) Complete (Result As SupabaseDatabaseResult)
    If Result.Error.Success Then
  
        For Each Row As Map In Result.Rows
            'If everything with supabase update was ok, I update the "userData" type. (userData is a type where i store all user data in order to access them from all pages)
            Main.userData.surname = Row.Get("surname")
            Main.userData.name = Row.Get("name")
            Main.userData.email = Row.Get("email")
            Main.userData.sex = Row.Get("sex")
            Main.userData.town = Row.Get("town")
            Main.userData.postal = Row.Get("postal")
            Main.userData.street = Row.Get("street")
            Main.userData.number = Row.Get("number")
            Main.userData.phone = Row.Get("phone")
            Main.userData.phone_eme = Row.Get("phone_eme")
      
        Next
  
        page.ShowToast("updateUser","toastgreen","Profile updated!",2000,False)
    Else
        page.ShowToast("updateUser","toastorange",Result.Error.ErrorMessage,2000,False)
    End If
 
    page.Resume
 
End Sub

I get this error:
B4X:
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:142)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
    at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:207)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:522)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:476)
    at b4j.example.profile._page_parseevent(profile.java:643)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 10 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:513)
    ... 17 more
Caused by: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.keywords.Common.WaitFor(Common.java:1073)
    at b4j.example.supabase_databaseupdate$ResumableSub_Execute.resume(supabase_databaseupdate.java:118)
    at b4j.example.supabase_databaseupdate._execute(supabase_databaseupdate.java:75)
    at b4j.example.profile$ResumableSub_btnSave_Clicked.resume(profile.java:115)
    at b4j.example.profile._btnsave_clicked(profile.java:41)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 18 more

Wait For throws this error.

Why at local release everything working fine and in VPS not? JDK versions are the same, WWW folder is uploaded, copymewithjar.needs is uploaded.

Moreover, in VPS server i get this error:
B4X:
ResponseError. Reason: , Response: {"message":"No API key found in request","hint":"No `apikey` request header or url param was found."}
But, if i click the same button couple of time and throw me the same error, then supabase update happens! Like magic!

edit: Supabase is initialized in main


******SOLUTION:
Long story short, ABMaterial and Supabase does not work well together. Yuo should switch back in SQL (DBM Class)
 
Last edited:
Solution
Thank you again for all these clarifications. I will try to contact with Alexander tomorrow, if he knows something about this behavior and if it is fixable, or i have to switch to SQL db.
Please note: If you use SQL where you use one user account to connect to the DB and then use queries against user tables to login a user (do not actually log them into their own DB account), then you can use Supabase the same way. Have one account log into Supabase and then use separate user tables to authenticate your users. If you go that route, Supabase should work. The issue here is that Supabase is not really designed to run in a multi-threaded environment with each user having their own Supabase connection. Again, even in an SQL...
Top