B4J Question Get error when request data from jRDC server

Sifu

Active Member
Hello,

Some strange is happening, I can't figure out what, it must be something very small or it is a bug.

I have a few buttons,which are to do something else, but I misuse them for now to figure something out.
Strange thing is that I get errors depending on who knows what. I'm just testing the reading and writing now.
But eventually I want things encrypted in DB. But for now, first have to solve this.

B4X:
sub Class_Globals
Private clientname,contactname,address,housenr,postcode,place,state,country,email,phonenr1,phonenr2,vat As String 'these are VARCHAR in DB
Private idcl,clientnr,activecl As Int 'these are INT in DB
End Sub
    
Private Sub getclient_btn1_MouseClicked (EventData As MouseEvent)
    Private clntnr As Int
    clntnr = nr_client_txt3.Text
    GetClientRecord(clntnr) 'gives wrong clientname or java error
End Sub

Private Sub updateclient_btn2_MouseClicked (EventData As MouseEvent)
    GetClientOneRecord 'test fixed id
End Sub

Private Sub createclient_btn3_MouseClicked (EventData As MouseEvent)
    Private clntnr As Int 'test
    clntnr = nr_client_txt3.Text 'test
    GetClientTestRecord(clntnr) 'test works
End Sub

Using a few subs of which the last 2 test subs are actually copy paste from the first, but removed what I did not need for the test.
B4X:
'this was the original sub, I've shortened some columns we do not need for the test
Sub GetClientRecord (clntnr As Int)
    Log ("clientnr is " & clntnr)
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_client", Array(clntnr))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        Dim row() As Object = res.Rows.Get(0) 'first row index = 0
        Log(row(0)) 'id
        idcl = row(0)
        clientnr = row(1)
        clientname = row(2)
        Log(clientname)
        'contactname = row(3)
        'address = row(4)
        'housenr = row(5)
        'postcode = row(6)
        'place = row(7)
        'state =row(8)
        'country = row(9)
        'phonenr1 = row(10)
        'phonenr2 = row(11)
        'email = row(12)
        'vat =row(13)
        'activecl =row(14)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
    id_client_txt1.Text = idcl
    nr_client_txt3.Text =  clientnr
    name_client_txt2.Text = clientname
    'contact_client_txt4.Text = contactname
    'email_client_txt5.Text = email
    'phone_client_txt6.Text = phonenr1
    'phone2_client_txt7.Text = phonenr2
    'address_client_txt8.Text = address
    'huisnr_client_txt9.Text = housenr
    'postcode_client_txt10.Text = postcode
    'place_client_txt11.Text = place
    'state_client_txt12.Text = state
    'country_client_txt13.Text = country
    'vat_client_txt14.Text = vat
End Sub
this uses in jRDC configuration: (and further below I explain why some lines are coment out)
B4X:
sql.select_client=SELECT id,clientnr,clientname,contactname,address,housenr,postcode,place,state,country,phonenr,phonenr2,email,vat,active FROM clients WHERE clientnr = ?

a test sub which is in fact similar but less items and using a fixed id
B4X:
Sub GetClientOneRecord 
    ' just for test
    Log ("clientnr is " & "one")
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_clientone", Null)
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        Dim row() As Object = res.Rows.Get(0) 'first row index = 0
        Log(row(0)) 'id
        idcl = row(0)
        clientnr = row(1)
        clientname = row(2)
        Log(clientname)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
    id_client_txt1.Text = idcl
    nr_client_txt3.Text =  clientnr
    name_client_txt2.Text = clientname
End Sub

using this:
B4X:
sql.select_clientone=SELECT id,clientnr,clientname FROM clients WHERE clientnr = 1

last test sub:
B4X:
Sub GetClientTestRecord (clntnr As Int)
    'just for test
    Log ("clientnr is " & clntnr)
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_clienttest", Array(clntnr))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        Dim row() As Object = res.Rows.Get(0) 'first row index = 0
        Log(row(0)) 'id
        idcl = row(0)
        clientnr = row(1)
        clientname = row(2)
        Log(clientname)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
    id_client_txt1.Text = idcl
    nr_client_txt3.Text =  clientnr
    name_client_txt2.Text = clientname
End Sub

using this:
B4X:
sql.select_clienttest=SELECT id,clientnr,clientname FROM clients WHERE clientnr = ?

Now the last two test subs work perfectly. Both give the id, the clientname and the clientnr.
The first original sub gives as result 1, 1 and 1. So now suddenly the clientname is a 1.
If I uncomment all lines from the first SUB to get the values it gives a JAVA error on the line where it says
B4X:
email = row(12)

error:
B4X:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.

clientnr is one
1
somecompany

clientnr is 1
1
somecompany

clientnr is 1
1
1

Fout op regel: 138 (B4XMainPage)
java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 12
    at b4j.example.b4xmainpage$ResumableSub_GetClientRecord.resume(b4xmainpage.java:887)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
    at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:369)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:181)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:504)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:484)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:558)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

Seems to me that whatever data is returned from DB, should not give error.
Nor do I understand why the 2 last SUB seem to work ok.

Hope someone has some clue.

Thank you.
 

Sifu

Active Member
@Erel, You may close this or remove it, whatever you like.
I found bug, it's me.

I copy pasted a sql line in config file without changing the select_clients to another name, so there where 2 the same.
Pffff, how long can someone just look at it and just not see it šŸ¤£ See I thought it was something small...
 
Upvote 0
Top