remote query fails at first attempt

slowtime

Active Member
Licensed User
Longtime User
I always must call twice ExecuteRemoteQuery, because at first attempt ' ResponseSuccess ' returns nothing, at the second attempt it always correctly returns the data stored in sql database.

Am I wrong in my basic 4 android code ?

I'am thinking about a problem in the server (PHP 5 or MYSQL) too.

Can someone help me ? please.

Thank you.

webwrite = 1
webread = 2



ExecuteRemoteQuery("comando=leggitutto", webread)

Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.initializeGet ("http://XXXXXXXXXX.it/codice.php?user=YYYYYYYY&password=ZZZZZZZZZZZ&" & Query )


hc.Execute(req, TaskId)

End Sub


Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log("Error: " & Reason & ", StatusCode: " & StatusCode)
If Response <> Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
ProgressDialogHide
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String

res = Response.GetString("UTF8")

webfields=0


Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select TaskId
Case 2 'webread
Dim countries As List
countries = parser.NextArray 'returns a list with maps
webfields=countries.Size
For i = 0 To countries.Size - 1
Dim m As Map
m = countries.Get(i)
wdb(i).cat=m.get("alfa")
wdb(i).subcat=m.get("beta")
wdb(i).user=m.get("gamma")
......
......
Next
End Select
ProgressDialogHide

response.Release
End Sub
 

slowtime

Active Member
Licensed User
Longtime User
Hi,

this is 1st attempt log ( at the end of all lines two squares ( I think CRLF)).

I don't understand because fields is ZERO because at 2nd attempt it is in the right and all run well.

Thank you.

fields: 0
res:
GC_FOR_MALLOC freed 2594 objects / 135824 bytes in 771ms
Grow heap (frag case) to 3.380MB for 87396-byte allocation
GC_FOR_MALLOC freed 72 objects / 3328 bytes in 206ms
GC_FOR_MALLOC freed 440 objects / 19952 bytes in 186ms
Grow heap (frag case) to 3.442MB for 87396-byte allocation
GC_FOR_MALLOC freed 0 objects / 0 bytes in 150ms
 
Upvote 0

slowtime

Active Member
Licensed User
Longtime User
Hi Erel,

thank you for help.

hc_ResponseSuccess works right, I used breakpoint.

But, every var (declared in Sub Globals) as webfields, wdb(i).cat etc.. lost its value outside ' hc_ResponseSuccess '

In fact, if I move functions that use global variables (webfields, wdb(i).cat etc.. ) inside ' hc_ResponseSuccess ' everything works perfectly.

Where am I wrong ?

Thank you again.
 
Upvote 0

slowtime

Active Member
Licensed User
Longtime User
Hi,

tank you again.

I'm trying http utils, if I don't solve my problem I'll update source.

Ciao.

ps: I am very happy to use Basic4Android and the forum help is sharp and fast.
 
Upvote 0
Top