Android Question RDC and 2 Queries problem

Oldmanenzo

Member
Licensed User
Longtime User
I'm starting to use the RDC to connect to my mysql database on my server.
I changed the various connection parameters to fit both my server and the content of my database and everything works perfectly.
The problem that feedback and that I can not run two queries simultaneously. I try to explain.
I have to fill a spinner with the contents of a table (regions) and stop the program if the spinner displays correctly with fields we picked up from the table, but if after the execution of the first spinner, I run a second query, with selected cmbRegioni .selectedItem the query returns an error of OutOfBoundMemory because the spinner is still empty and therefore can not find the index 0. I approached recently to Basic4 and assume that the function jobdone, is performed in the background so that ground when sending the second query execution in the data are not yet available to be manipulated.
I enclose only a part of the code to figure out where I run the two requests and how I can control when the function jobdone has completed its cycle and make a second request.
thanks
google translation ..... sorry

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Scroll As ScrollView
    Dim CmbRegione As Spinner
    Dim Cmbprovince As Spinner
    Dim cd As ColorDrawable
    Dim PanelHeight As Int : PanelHeight=80dip
    Dim REGIONE  ="Regione", PROVINCIA ="Province", PNL ="Panel", COUNT="Conteggio" As String
    Dim prov(20) As String
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout ("frmricercaview")
    Scroll.Initialize (100%x)
    Activity.AddView (Scroll, 0, 40dip, 100%x, 100%y)
    Scroll.Color =Colors.Black
    CmbRegione.Left =Activity.Width /2 - CmbRegione.Width /2
    CmbRegione.Prompt ="Regione"
    FetchCountriesRegione
    CmbRegione.SelectedIndex =0
    FetchProvince
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub FetchCountriesRegione
'Utilizzato per riempire ilcombox delle regioni
    ProgressDialogShow("Sto caricando le informazioni")
    'Gets all the available countries
    ExecuteRemoteQuery("SELECT Regione FROM regioni ORDER BY Regione", REGIONE)
End Sub

Sub FetchProvince
'Utilizzato per riempire la variabile delle province secondo la regione selezionata
    ProgressDialogShow("Sto caricando le informazioni")
    'Gets all the available countries
    ExecuteRemoteQuery("SELECT Provincia FROM province WHERE Regione ='" & CmbRegione.SelectedItem &"' ORDER BY Provincia", PROVINCIA)
    'Here goes wrong because cmbregione not initialized
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
without seeing what you do in jobdone it is hard to help.
probably you need to wait for the call of "FetchProvince". Do the call in JobDone of your "FetchCountriesRegione". So they become an order

EDIT:
Ecactly you need to place
B4X:
CmbRegione.SelectedIndex =0
FetchProvince
in the jobdone of FetchCountriesRegione. You can not set an selectedindex when there are no items loaded at this time...
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Just to write something (I have a warehouse full of ink to be consumed :D)


If your code is a Class Module or Code Module, writing:
B4X:
'Utilizzato per riempire ilcombox delle regioni
Sub FetchCountriesRegione

instead of:
B4X:
Sub FetchCountriesRegione
'Utilizzato per riempire ilcombox delle regioni

you could read the description/comment of the routine:
B4X:
MyCodeModule.FetchCountriesRegione

it would show "Utilizzato per riempire ilcombox delle regioni" while typing.


W Google Translate ;)


[P.S. it also works in Activities but calls to routines of modules or classes are more frequent]
 
Last edited:
Upvote 0

Oldmanenzo

Member
Licensed User
Longtime User
Maybe we have not understood, even certainly not, because it makes the translation of the words, but it certainly was not this my request.
Quite simply, because JopDone works in the background, how do I know when the routine jobdone has completed its cycle before you actually run another search?
this is the function jobdone although I think it is not necessary to post it as it works very well with first spinner
B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www.caravan-forum.it/portolano/portolano.php", Query)
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
            Case REGIONE
                Utility.ExecuteSpinner (parser, CmbRegione, "Regione")
            Case PROVINCIA
                prov(19)=Utility.ExecuteLoadProvince (parser, prov, "Provincia")
        End Select
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
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
            Case REGIONE
                Utility.ExecuteSpinner (parser, CmbRegione, "Regione")
               ' 
              CmbRegione.SelectedIndex =0
              FetchProvince
            Case PROVINCIA
                prov(19)=Utility.ExecuteLoadProvince (parser, prov, "Provincia")
        End Select
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 
Upvote 0

Oldmanenzo

Member
Licensed User
Longtime User
DonManfred I understand.
The return of the function utility.executespinner I have the certainty that at that time the spinner was filled and then you can use its Item
Thanks
 
Upvote 0
Top