Android Question JRDC2 and JobDone

luisro

Member
Licensed User
Hi, how do I add a HttpJob or name to a Job, then call them on the JobDone?

Ex:

B4X:
Sub button1_Click
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "select_animal"
    reqManager.ExecuteQuery(cmd, 0, Null)
End Sub

Sub Button2_Click 
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "insert_animal"
    cmd.Parameters = Array As Object("1","imagen", reqManager.FileToBytes(File.DirAssets, "icon.png"))
    reqManager.ExecuteBatch(Array(cmd), Null)
End Sub

B4X:
Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object)
    Dim ser As B4XSerializator
    Dim data() As Byte = ser.ConvertObjectToBytes(CreateMap("command": Command, "limit": Limit,  "version": VERSION))
    SendJob(data, Tag, "query2")
End Sub

Private Sub SendJob(Data() As Byte, Tag As Object, Method As String)
    Dim j As HttpJob
    j.Initialize("DBRequest", mTarget)
    j.Tag = Tag
    j.PostBytes(link & "?method=" & Method , Data)

Public Sub ExecuteBatch(ListOfCommands As List, Tag As Object)
    Dim ser As B4XSerializator
    ser.Tag = Tag
    ser.ConvertObjectToBytesAsync(CreateMap("commands": ListOfCommands,  "version": VERSION), "ser")
End Sub

B4X:
Sub JobDone(Job As HttpJob)
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
    Else
        Dim result As DBResult = reqManager.HandleJob(Job)
           Select Job.JobName
         
            Case case1
         
            Case case2
           
           
            End Select
    End If
    Job.Release
End Sub

I have 2 commands, one to insert and one to consult. One uses ExecuteQuery and another uses ExecuteBatch, as I give them a name and then call them on the JobDone?
 

luisro

Member
Licensed User
I myself answer,

Commands are sent with a name and parameters.

Name (SQL query in config.properties) Parameters (data to be entered or methods to be implemented).

And each method that is assigned to the cmd adds a tag.

Then in JobDone we call with Job.Tag the called work with a label.

I hope this is useful for someone else and I'm not the only dummy. :oops:

B4X:
Sub button1_Click
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "select_animal"
    reqManager.ExecuteQuery(cmd, 0, "select")
End Sub

Sub Button2_Click  
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "insert_animal"
    cmd.Parameters = Array As Object("1","imagen", reqManager.FileToBytes(File.DirAssets, "icon.png"))
    reqManager.ExecuteBatch(Array(cmd), "insert")
End Sub


B4X:
Sub JobDone(Job As HttpJob)
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
    Else
        Select Job.Tag
            Case "insert"
            Log("Correcto!")
            Case "select"
                Dim result As DBResult = reqManager.HandleJob(Job)
                    For Each records() As Object In result.Rows
                Dim a,b As String
                a = records(result.Columns.Get("nombre"))
                b = records(result.Columns.Get("apellido"))
                Log(a&" "&b)
                Next
            End Select
    End If
    Job.Release
End Sub
 
Upvote 0
Top