Android Question ExecuteRemoteQuery And Service

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
i have one question. when i update DB and after few second i retry with SELECT date the service give me OLD VALUE.

This is code Service:

B4X:
Sub Service_Start
    'Rileggo dal DB
    sPhonenum = pId.GetLine1Number
    ExecuteRemoteQuery("SELECT numeroconsole from spy where numerospy  ='" & sPhonenum & "'", SPY)
End Sub

.......
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
    Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
        Select Job.JobName
      

      
      
        'Seleziono Lista Numeri
        Case SPY
            Dim l As List
                l = parser.NextArray
                If l.Size = 0 Then
                    numero_autorizzato = "000000000"
                Else
                    Dim m As Map
                    m = l.Get(0)
                    numero_autorizzato = m.Get("numeroconsole")
                    'Prelevo i secondi sul conto
                    ExecuteRemoteQuery("SELECT secondi from ricarica_spy where numero ='"& numero_autorizzato &"'", RICARICA_SPY)

                End If
      
            'Prelevo tramite la query di sopra i secondi rimasti
        Case RICARICA_SPY
            Dim l As List
                l = parser.NextArray
                If l.Size = 0 Then
                    secondi_disponibili = 0
                Else
                    Dim m As Map
                    m = l.Get(0)
                    secondi_disponibili = m.Get("secondi")
                    secondi_disponibili = secondi_disponibili * 1000
                    ToastMessageShow("MilliSecondi rimasti: "& secondi_disponibili, True)
                End If

                  
        End Select
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage & "Errore Internet", True)
    End If
    Job.Release
End Sub

i execute the firsrt Query in Start_service
B4X:
ExecuteRemoteQuery("SELECT numeroconsole from spy where numerospy  ='" & sPhonenum & "'", SPY)

This query excute another query (
B4X:
ExecuteRemoteQuery("SELECT secondi from ricarica_spy where numero ='"& numero_autorizzato &"'", RICARICA_SPY
) the first time all work. After also if i update DB comeback OLD VALUE.
Any Idea ??
Thank you
 

MarcoRome

Expert
Licensed User
Longtime User
if restart Service...Work. Seem that Service after start also if excute SELECT does not update the data.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
did you dim a new job each time in ExecuteRemoteQuery??? If no; you should do that
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Thank DonManfred i resolve with Stop and Restart Service after that i update DB.

B4X:
    StopService("Listener")
    CancelScheduledService("Listener")
    StartService("Listener")
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
did you dim a new job each time in ExecuteRemoteQuery??? If no; you should do that

Hi DonManfred. I have again the problem ( seemed resolved but it is not so ).
When you say: "did you dim a new job each time in ExecuteRemoteQuery ? " what mean ?

Example now i have this code:

B4X:
Sub Service_Start
 
    sPhonenum = pId.GetLine1Number
    ExecuteRemoteQuery("UPDATE spy SET imei ='ONLINE' where numerospy  ='" & sPhonenum & "'","")
    ExecuteRemoteQuery("SELECT numeroconsole from spy where numerospy  ='" & sPhonenum & "'", SPY_LISTENER)
End Sub
 
Sub ExecuteRemoteQuery(Query AsString, JobName AsString)
Dim job AsHttpJob
job.Initialize(JobName, Me)
job.PostString("http://www.XXXXXX.eu/database/db.php?hst="&ipserver&"&db="&dbname&"&usr="&userdb&"&pwd="&dbpw&"", Query)
job.GetRequest.Timeout = 60000   '60 seconds
End Sub
 
 
Sub JobDone(Job AsHttpJob)
If Job.Success Then
Dim res AsString
res = Job.GetString
Log("Response from server: " & res)
Dim parser AsJSONParser
parser.Initialize(res)
Select Job.JobName
 
Case  SPY_LISTENER
Dim l As List
l = parser.NextArray
If l.Size = 0Then
numero_autorizzato = "000000000"
Else
Dim m AsMap
m = l.Get(0)
numero_autorizzato = m.Get("numeroconsole")
'Prelevo i secondi sul conto
ExecuteRemoteQuery("SELECT secondi from ricarica_spy where numero = '"& numero_autorizzato &"'", RICARICA_SPY_LISTENER)
EndIf
'Prelevo tramite la query di sopra i secondi rimasti
Case RICARICA_SPY_LISTENER
Dim l AsList
l = parser.NextArray
If l.Size = 0Then
secondi_disponibili = 0
Else
Dim m AsMap
m = l.Get(0)
secondi_disponibili = m.Get("secondi")
secondi_disponibili = secondi_disponibili * 1000
Ifsecondi_disponibili > 7000Then
secondi_totale = secondi_disponibili
Else
secondi_totale = 20000
EndIf
' ToastMessageShow("MilliSecondi rimasti DB Inizio: "& secondi_disponibili, True)
' ToastMessageShow("Secondi Totali: "& secondi_totale, True)
EndIf
Case  SALVA_CREDITO_LISTENER
mfl.deletecalllogs(numero_autorizzato)
' ToastMessageShow("**Riparto con il servizio", True)
StartServiceAt("", DateTime.Now,True)
EndSelect
Else
' ToastMessageShow("Error: " & Job.ErrorMessage & "Errore Internet", True)
EndIf
Job.Release
End Sub

Thank you in advance
Marco
 
Last edited:
Upvote 0
Top