Android Question Looping queries to JRDC

Discussion in 'Android Questions' started by proinko, Jun 14, 2018.

  1. proinko

    proinko Member Licensed User

    Hi all

    i am trying to send a loop of queries to the server (using JRDC2) but it seems that each query replaces the previous one.

    If i run the code in debug mode (pausing on each line) it executes ok, so i think that i let the answers comes back from the server before sending the next query

    This is the code

    1) the loop that send the queries

    Code:
    For i=0 To lst.Size-1
            
    wait For (CheckT(lst.Get(i))) complete (mresult As Map)
            
    If mresult.Get("ReqOK")=True Then
                ....
                
    Return
            
    End If
        
    Next
    2) the sub that send each query

    Code:
    Sub CheckT(P As String)As ResumableSub
        
    Dim m As Map
        m.Initialize
        m.Put(
    "ConnOk",False)
        m.Put(
    "ReqOK"False)

        
    Dim Req As DBRequestManager = CreateRequest
        
    Dim cmd As DBCommand = CreateCommand("QueryName",Array(P))
        
    Wait For (Req.ExecuteQuery(cmd, 0Null)) JobDone(j As HttpJob)
        
    If j.Success Then
            m.Put(
    "ConnOk",True)
            Req.HandleJobAsync(j, 
    "req")
            
    Wait For (Req) req_Result(res As DBResult)
            
    'Req.PrintTable(res)
            If res.Rows.Size>0 Then
                
    Dim record() As Object=res.Rows.Get(0)
                
    If record(res.Columns.Get("cTAG"))=0 Then
                         m.Put(
    "ReqOK"True)
                
    End If
            
    End If
        
    Else
            
    Log("ERROR: " & j.ErrorMessage)
            
    Msgbox(j.ErrorMessage,"Error")
        
    End If
        j.Release
        
    Return m
    End Sub

    I guess that i am missing something about resumable subs ...

    thanks!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What do you see?

    Add Log("Sending request") before the call to CheckT. Are the messages being sent sequentially?
     
  3. OliverA

    OliverA Well-Known Member Licensed User

    What do you mean by this?
    Code:
    For i=0 To lst.Size-1
            
    wait For (CheckT(lst.Get(i))) complete (mresult As Map)
            
    If mresult.Get("ReqOK")=True Then
                ....
                
    Return
            
    End If
        
    Next
    As this code stands:
    1) It will complete one Wait For before executing the next.
    2) The first mresult.Get("ReqOK") that returns True, ends your For loop (via Return), even if more items are in the list. I don't know if that is the effect you are desiring. Also, the Wait does a Return to the code after the call to whatever sub that contains the For loop is executed (unless you have another Wait For there).
     
    Erel likes this.
  4. proinko

    proinko Member Licensed User

    yes, adding Log("Sending request" & i) returns Sending Request0, Sending Request1, ... sequentially, until the last ítem of the list (there is no one left)
     
  5. proinko

    proinko Member Licensed User

    thanks for your replies

    ... sorry, trying to clean the code to post it, i left that "return" on the wrong place...

    What i am trying to do is to check if every ítem on the list has it corresponding record on the database (all of them exists int the examples i am checking)

    The code works sometimes (it returns that all of them exist), but , with the same queries, sometimes fails and returns that no one record exists. This is why i thought that maybe some of the queries are overwritting others, depending if the server is busy and the reply takes some time ...

    So, forgetting that "return" (sorry again), do you think that the code is right, and that all the queries should execute?
     
  6. OliverA

    OliverA Well-Known Member Licensed User

    They should. One thing to look out for is not to modify your list (lst) object while processing it, or you will experience unpredictable results.
     
  7. proinko

    proinko Member Licensed User

    Ok, thanks for your time Oliver and Erel

    Knowing that the code corresponding to the queries loop is not wrong, i will check on the rest of the code (the list items are not modified during the loop)
     
  8. OliverA

    OliverA Well-Known Member Licensed User

    You may already be doing this, but you could run you jRDC server from the command line. Then launch your application and let it process the loop. You should be seeing corresponding log outputs to the console window by jRDC. Example output:
     
  9. proinko

    proinko Member Licensed User

    I am watching at the jRDC server now, but in the last n+1 executions, all the queries are working ok ...

    I have added just one line in the code, instead of

    Code:
    If record(res.Columns.Get("cTAG"))=0 Then
                         m.Put(
    "ReqOK"True)
                
    End If
    the code is now

    Code:
    Dim N as int=record(res.Columns.Get("cTAG"))   
                
    If N=0 Then
                         m.Put(
    "ReqOK"True)
                
    End If
    the queries do not fail now (so far), but i do not think that this is the solution to be sure in the next queries

    Thanks for your help
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice