Android Question PostString repeats last command

AHilberink

Well-Known Member
Licensed User
Longtime User
Hi,

I am using PostString within a loop. The server receives the correct counts of posts, but all have the last command.

I check using Log(..) the command given: They are correct.
I check the receive on the server-side: They all are the last command.

Could it be a timing issue?

This is what I am using:
B4X:
Sub InsertMaps(TableName As String, ListOfMaps As List)
    Dim columns, values As StringBuilder
    Dim Commando As String
  
    Opslaan.Release
    Opslaan.JobName = TableName

    AantalTeVerzenden=ListOfMaps.Size-1

    Try
        For i1 = 0 To ListOfMaps.Size - 1
            columns.Initialize
            values.Initialize
            Commando="INSERT INTO " & TableName & " ("
            Dim l As Map
            l.Initialize
            l = ListOfMaps.Get(i1)
            For i2 = 0 To l.Size - 1
                Dim col As String
                Dim value As Object  
                col = l.GetKeyAt(i2)
                value = l.GetValueAt(i2)
                If i2 > 0 Then
                    columns.Append(", ")
                    values.Append(", ")
                End If
                columns.Append(col)
                If value <> Null Then
                    values.Append(Chr(34)).Append(value).Append(Chr(34))
                Else
                    values.Append(value)
                End If
            Next
            Commando = Commando &columns.ToString&") VALUES ("&values.ToString&");"
            Log(Commando)
            Opslaan.PostString(Main.MainUrl&"&target=action",Commando)
        Next
    Catch
        Fouten = True
    End Try
End Sub

Sub JobDone (Job As HttpJob)
    If (Job.Success == True) Then
        If(Job.JobName == "werktijden") Then
            TellerVerzending=TellerVerzending+1
            If(TellerVerzending==AantalTeVerzenden) Then
                Log("UPDATE ["&(Main.DBWerkdagen)&"] SET [Verzonden] = 1 WHERE Verzonden=0")
                Main.SQL1.ExecNonQuery("UPDATE ["&(Main.DBWerkdagen)&"] SET [Verzonden] = 1 WHERE Verzonden=0")
                Msgbox("Alles is verzonden", "")
                Job.Release
                Activity.Finish
            End If
        End If
        If(Job.JobName == "werkdagen") Then
            TellerVerzending=TellerVerzending+1
            If(TellerVerzending==AantalTeVerzenden) Then
                TellerVerzending=0
                Verzend_Werktijden
            End If
        End If
    Else
        ToastMessageShow("Fout: " & Job.ErrorMessage, True)
        Fouten = True
    End If
End Sub

Can someone tell me what is wrong?

Best regards,
André
 
Last edited:

AHilberink

Well-Known Member
Licensed User
Longtime User
You need to dim each post job

Thanks for your reply.

Which variables do I have to re-dim? The Commando-String or Opslaan-HttpJob or both or others? I think you mean after the for i1=0 to .... statement?

Does this mean the functions Poststring is not Multi-thread?

Best regards,
André
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
each download should be dimmed (de opslaan) otherwise you just send the same request again and that's your problem.

nothing to do with multi thread or not, you use the same object over and over again.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Additionally: You can put all the single "calls" into one. Just put the single data in a map, add all the maps to ONE list and send it ONE TIME to your server. On the php side you can extract it in a loop and do what you need (insert, etc.).
 
Upvote 0
Top