Android Question jRDC2 DBRequestManager Multiple Sequential Query Completion

A Z M JANNAT UL KARIM

Member
Licensed User
Hi, I am running 3 ExecuteQuery sequentially with Tag to retrieve data from Database like follows ...
reqManager.ExecuteQuery(cmd, 0, "D")
reqManager.ExecuteQuery(cmd, 0, "G")
reqManager.ExecuteQuery(cmd, 0, "R")

Based on the tag it will retrieve data from three tables and insert data to the SQLLite DB for Offline Access. After that I populate the ListView from the SQLLite DB.
Now I want to know when the job process completed? I think I need to use CallSubDelayed but the problem is where should I use it to get the final job done response to Fill the ListBox. Please check the last line to FillList call event after Job.Release. It call three times whereas I want to call it once.

My codes are as follows ...
B4X:
Sub Activity_Create(FirstTime As Boolean)
            GetPartyInfo("D")
            Wait for GetPartyInfo_Complete
            GetPartyInfo("G")
            Wait for GetPartyInfo_Complete
            GetPartyInfo("R")
            Wait for GetPartyInfo_Complete
End Sub

Sub GetPartyInfo(PartyType As String)
    Dim cmd As DBCommand
    cmd.Initialize
    If PartyType = "D" Then
        cmd.Name = "select_dealer"
        cmd.Parameters = Array As Object(manager.GetString("mobPhone"))
        reqManager.ExecuteQuery(cmd, 0, "D")
    Else If PartyType = "G" Then
        cmd.Name = "select_golden"
        cmd.Parameters = Array As Object(manager.GetString("mobPhone"))
        reqManager.ExecuteQuery(cmd, 0, "G")
    Else If PartyType = "R" Then
        cmd.Name = "select_retailer"
        cmd.Parameters = Array As Object(manager.GetString("mobPhone"))
        reqManager.ExecuteQuery(cmd, 0, "R")
    End If
    CallSubDelayed(Me, "GetPartyInfo_Complete")
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
    Else
        If Job.JobName = "DBRequest" Then
            Dim result As DBResult = reqManager.HandleJob(Job)
            Starter.sqlLiteDB.BeginTransaction
            Try
                For Each records() As Object In result.Rows
    ' Do Some Database Stuff Here
                Next
                Starter.sqlLiteDB.TransactionSuccessful
            Catch
                Msgbox("Error Occured When Updating Data !!!", "Error")
            End Try
            Starter.sqlLiteDB.EndTransaction
        End If
    End If
    Job.Release
    FILL_LIST
End Sub
 
Last edited:
Top