B4J Question Why does jRDC work when included in the main app module, but not in another code module?

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I am using jRDC client modules.

If I define my request function and the associated variables in the main app module it works. If I place it in another code module it doesn't.

Why is this?>

B4X:
'Network Variables
Type DBResult (Tag As Object, Columns As Map, Rows As List)
Type DBCommand (Name As String, Parameters() As Object)
Private const rdcLink As String = "http://192.168.1.114:17178/rdc"


Sub getPowerDataForDisplayUpdate
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand
    
    If initFlag Then
        ' Get full data set from database for historical records and latest
        cmd = CreateCommand("getPwrDataWithAlarms_Raw_N7200_Ascn", Null)
    Else   
        'Get the lastest single record for the update
        cmd = CreateCommand("getPwrDataWithAlarmsLast_0001", Null)
    End If

    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)
        
        getRecords (res)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

Best regards

Rob
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hi Erel,

When the RDC Handler ExecuteQuery2 is called it fails on the Dim m as Map = ...

jRDC_sqlite Server Code:
Private Sub ExecuteQuery2 (con As SQL, in As InputStream,  resp As ServletResponse) As String
    Dim ser As B4XSerializator
    Dim m As Map = ser.ConvertBytesToObject(Bit.InputStreamToBytes(in)) ' Fails here
    Dim cmd As DBCommand = m.Get("command")
    Dim limit As Int = m.Get("limit")
    Dim rs As ResultSet
    Dim errFlag As Boolean = False
    Dim errMsg As String = ""
    Dim sqlStmt As String
    
    'Sanity check cmd.Name
    sqlStmt = Main.rdcConnector1.GetCommand(cmd.Name)
    If sqlStmt <> "" Then
        Try
            ' Call correct Query function based on cmd.Parameters setting
            If cmd.Parameters = Null Or cmd.Parameters.Length = 0 Then
                rs = con.ExecQuery(Main.rdcConnector1.GetCommand(cmd.Name))
            Else ...

I get a big long java error in the log. Something about SQL classes. I would have to go back to an old version and run it again as I didn't keep a copy of the error.

I suspect it's got something to do with events as DonManfred suggested, as the code refers to (Me, ...

Create request - Client Program:
'======================================================================================
Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, rdcLink)
    Return req
End Sub


It's not a problem for me as I have got it working OK, but I just wanted to get some insight into why the placement of the code should matter. I do a lot of bog standard C programming and the placement of functions can be completely arbitrary as long as you get your includes and externals sorted.

Best regards

Rob
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hi Erel,

I'll put this on the back burner as I don't have time at the moment to chase it.

I will use classes in the future.

Best regards

Rob
 
Upvote 0
Top