Android Question [B4XPages] [SOLVED] jRDC2 Client Code Should All be in Main Activity?

Mashiane

Expert
Licensed User
Longtime User
Ola

I have a couple of B4XPages that will speak to JRDC2. The commands and things that each page will do will be different depending on the purpose of the page. Should all the methods be defined on the Main Activity.

For example GetRecord/InsertRecord. Is it possible to have such methods per page where its needed to execute different functions?

Thanks.
 

Mashiane

Expert
Licensed User
Longtime User
K thanks

Pasted this on B4XMainPage Class_Globals

B4X:
Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
    Private const rdcLink As String = "(redacted)"

Added this on B4XMainPage

B4X:
public Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, rdcLink)
    Return req
End Sub

public  Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters = Parameters
    Return cmd
End Sub

In one of my pages, I have defined..

B4X:
Sub GetMemberProfileByMobileNo (id As String)
    'sql.select_user_bytelnumber = Select * FROM user WHERE tel1= ?
    Dim req As DBRequestManager = MP.CreateRequest
    Dim cmd As DBCommand = MP.CreateCommand("select_user_bytelnumber", Array(id))
    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
        req.PrintTable(res)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

GetMemberProfileByMobileNo works on button click..

Its returning..

1611061507005.png


Do you perhaps have any clue what could this CLEARTEXT mean and how to solve it. We are running Windows 10 WebServer, running IIS.

Thanks
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Do you perhaps have any clue what could this CLEARTEXT mean and how to solve it. We are running Windows 10 WebServer, running IIS.
I believe this has been asked many times in the forum. It is due to okHttpUtils2 not connecting to https protocol. It can be solved by adding a macro in manifest editor.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
I believe this has been asked many times in the forum.
Thanks @aeric , me my my forum searching skills. Just started with B4XPages and jRDC2 today, its still a fuzzy learning curve.

Yes I found your response in one of the posts..

B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)

Went through app crashes after that and finally it passed that stage.

Just need to figure out the cause of this following error now.

1611063457526.png
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Thanks @aeric , me my my forum searching skills. Just started with B4XPages and jRDC2 today, its still a fuzzy learning curve.

Yes I found your response in one of the posts..

B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)

Went through app crashes after that and finally it passed that stage.

Just need to figure out the cause of this following error now.

View attachment 106516
I think all the while you are more concentrating on B4J and server development. Welcome back to B4A development. ?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Just need to figure out the cause of this following error now.

1611063457526.png
Do you have this code in your B4J JRDC Main?
B4X:
Sub Process_Globals
    Public srvr As Server
    Public rdcConnector1 As RDCConnector
    Public const VERSION As Float = 2.22
    Type DBCommand (Name As String, Parameters() As Object)
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
End Sub
Edit: Sorry, I just realized this is a B4J client
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Nothing should be implemented in the Main activity
I think the
B4X:
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
must be in Main Process_Globals, unless Erel says it's not right.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Relooking at the error like again...

B4X:
<title>Error 500 java.lang.ClassNotFoundException: b4j.example.b4xmainpage$_dbcommand</title>

Its like its expecting to find b4j.example.b4xmainpage because my subs are being called from the b4xmainpage. In B4J there is only Main with these types defined.
I think you are missing DBRequestManager.bas
It is attached in the first post of https://www.b4x.com/android/forum/t...ation-of-rdc-remote-database-connector.61801/
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
must be in Main Process_Globals
Ok, I mistook Erel's statement to say even the Types should be moved to B4XMainPage. I've put them back, error disappeared. Thanks guys.

I think you are missing DBRequestManager.bas

This has all been done. Thanks.

Now for the next steps, displaying the result and other CRUD functionality. This isnt that bad.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
No log from the
B4X:
req.PrintTable(res)
line? Are you sure your sql returns data?
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Ok, finally, after some thoughts I decided to try something out and its returning some results. #Pending Erels look at the RAF issue.

1. Leave This in Main Process_Globals

B4X:
Type DBResult (Tag As Object, Columns As Map, Rows As List)
Type DBCommand (Name As String, Parameters() As Object)

2. In B4XMainPage, I have made a slight mod to CreateRequest, will pass it the module name e.g. Page3 for example.
B4X:
public Sub CreateRequest(Target As Object) As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Target, rdcLink)
    Return req
End Sub

And

B4X:
    Private const rdcLink As String = "(redacted)"
End Sub

public Sub CreateRequest(Target As Object) As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Target, rdcLink)
    Return req
End Sub

public  Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters = Parameters
    Return cmd
End Sub

Then in one of my pages...

B4X:
Private Sub btnRegister_Click
    'get the entered user details
    Dim up As Map = CreateMap()
    up.Put("firstname", txtFirstName.Text)
    up.Put("lastname", txtLastName.Text)
    up.Put("tel1", txtMobile.Text)
    up.Put("tel2", txtNextOfKin.Text)
    up.Put("deviceid", txtDeviceID.Text)
    'check if blank and warn user
    Log(up)
    GetMemberProfileByMobileNo(txtMobile.Text)
End Sub


Sub GetMemberProfileByMobileNo (id As String)
    'sql.select_user_bytelnumber = Select * FROM user WHERE tel1= ?
    Dim req As DBRequestManager = MP.CreateRequest(Me)
    LogColor("GetMemberProfileByMobileNo.CreateRequest...", xui.Color_Cyan)
    Dim cmd As DBCommand = MP.CreateCommand("select_user_bytelnumber", Array(id))
    LogColor("GetMemberProfileByMobileNo.CreateCommand...", xui.Color_Cyan)
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    LogColor("GetMemberProfileByMobileNo.Wait For ExecuteQuery...", xui.Color_Cyan)
    LogColor("GetMemberProfileByMobileNo.Success Result..." & j.success, xui.Color_Cyan)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_result(res As DBResult)
        Log(res.Columns)
       
        Log(res)
        'work with result
        req.PrintTable(res)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

Hooraa!


1611069699719.png
 
Upvote 0
Top