In my app, there's an Activity called Search. In it, there's a search button, here's the code which executes on the button's click event.
And I have added a code module named Common which contains code regarding connecting to an online MySQL database and retrieving results.
The ExecuteRemoteQuery sub gets executed but the hc_ResponseSuccess event does not run. The execution halts at the end of btnSearch_Click sub.
What should I do to correct this?
Thank you
B4X:
Sub btnSearch_Click
Dim selection, search_string As String
Dim range As CostRange
selection = spnrSearchBy.SelectedItem.Trim
search_string = txtSearch.Text.Trim
range.FromCost = txtFrom.Text.Trim
range.ToCost = txtTo.Text.Trim
If selection = "Cost" Then
Common.ChooseQuery(selection, Null, range.FromCost, range.ToCost)
Else
Common.ChooseQuery(selection, search_string, Null, Null)
End If
End Sub 'end of btnSearch_Click
And I have added a code module named Common which contains code regarding connecting to an online MySQL database and retrieving results.
B4X:
Sub Process_Globals
Dim hc As HttpClient
Dim SEARCH_RESULTS = 1
End Sub
Sub ChooseQuery (param As String, str As String, fc As String, tc As String)
ProgressDialogShow2("Please wait", False)
If param = "Area" Then
ExecuteRemoteQuery("SELECT T.SID, Name, Cost FROM locations L INNER JOIN service_locations SL ON L.Code = SL.Loc_Code LEFT JOIN taxi_services T ON T.SID = SL.SID WHERE Location LIKE '%" & str.Trim & "%' AND Active = 1 GROUP BY T.SID ", SEARCH_RESULTS)
Else If param = "Cost" Then
ExecuteRemoteQuery("SELECT SID, Name, Cost FROM taxi_services WHERE Cost >= '" & fc & "' AND Cost <= '" & tc & "' AND Active = 1 ", SEARCH_RESULTS)
Else If param = "Service Name" Then
ExecuteRemoteQuery("SELECT SID, Name, Cost FROM taxi_services WHERE Name LIKE '%" & str.Trim & "%' AND Active = 1 ", SEARCH_RESULTS)
Else If param = "Hotline" Then
ExecuteRemoteQuery("SELECT S.SID, Name, Cost, Phone_No FROM hotlines H INNER JOIN taxi_services S ON H.SID = S.SID WHERE Phone_No LIKE '%" & str.Trim & "%' AND Active = 1 ", SEARCH_RESULTS)
End If
End Sub
Sub ExecuteRemoteQuery (Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2("http://mysite.com/service.php", Query.GetBytes("UTF8"))
hc.Initialize("hc")
hc.Execute(req, TaskId)
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String
res = Response.GetString("UTF8")
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select TaskId
Case SEARCH_RESULTS
Dim ressulset As List
ressulset = parser.NextArray
If ressulset.Size = 0 Then
StartActivity(NoResults)
Else
StartActivity(Results)
End If
'ProgressDialogHide
End Select
Response.Release
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
The ExecuteRemoteQuery sub gets executed but the hc_ResponseSuccess event does not run. The execution halts at the end of btnSearch_Click sub.
What should I do to correct this?
Thank you
Last edited: