Android Question MSMySQL Async SELECTS and results

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello my friends,
I use MSMySQL lib from @DonManfred. I use a for-loop to get about 10 Async Selects.
B4X:
                    For i = 0 To dateList.Size-1
                        Log(startDate)
                        startDate=dateList.Get(i)
                        Main.db.QueryASync("SELECT astynomikos.agms, convert(cast(convert(ypiresies_db.ypiresia using  latin1) as binary) using utf8) as ypiresia, ypiresies_db.orario, daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias  FROM astynomikos, ypiresies_db, daily.ypiresiaid_" & startDate.Replace("-","_") & " WHERE astynomikos.agms=" & Main.agms & " AND astynomikos.agms=daily.ypiresiaid_" & startDate.Replace("-","_") & ".agms AND ypiresies_db.ypiresia_id=daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias;","allData")
                        'Sleep(500)
                    Next
If a user has low internet ("E"-Edge), async results are not sorted well. So i use a Sleep(500). But neither Sleep always get results at correct order. I think this problem occurs because all queries are async. Maybe thats why are different order every time i try this code.
 

Lahksman

Active Member
Licensed User
Longtime User
I've never used this lib.
But i reccon you could try to add an ORDER BY to order the result.

B4X:
Main.db.QueryASync("SELECT astynomikos.agms, convert(cast(convert(ypiresies_db.ypiresia using  latin1) as binary) using utf8) as ypiresia, ypiresies_db.orario, daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias  FROM astynomikos, ypiresies_db, daily.ypiresiaid_" & startDate.Replace("-","_") & " WHERE astynomikos.agms=" & Main.agms & " AND astynomikos.agms=daily.ypiresiaid_" & startDate.Replace("-","_") & ".agms AND ypiresies_db.ypiresia_id=daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias ORDER BY [field1],[field2],...;","allData")
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
I've never used this lib.
But i reccon you could try to add an ORDER BY to order the result.

B4X:
Main.db.QueryASync("SELECT astynomikos.agms, convert(cast(convert(ypiresies_db.ypiresia using  latin1) as binary) using utf8) as ypiresia, ypiresies_db.orario, daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias  FROM astynomikos, ypiresies_db, daily.ypiresiaid_" & startDate.Replace("-","_") & " WHERE astynomikos.agms=" & Main.agms & " AND astynomikos.agms=daily.ypiresiaid_" & startDate.Replace("-","_") & ".agms AND ypiresies_db.ypiresia_id=daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias ORDER BY [field1],[field2],...;","allData")
In order to get all results from different tables i need to use FOR loop. Always i get single results. Thats why ORDER BY is not usefull at this case.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
,"allData"
you can set a different "Tag" in your queries... In the result you can distinguish the results with the Tag-String...
for ex

B4X:
For i = 0 To dateList.Size-1
                        Log(startDate)
                        startDate=dateList.Get(i)
                        Main.db.QueryASync("SELECT astynomikos.agms, convert(cast(convert(ypiresies_db.ypiresia using  latin1) as binary) using utf8) as ypiresia, ypiresies_db.orario, daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias  FROM astynomikos, ypiresies_db, daily.ypiresiaid_" & startDate.Replace("-","_") & " WHERE astynomikos.agms=" & Main.agms & " AND astynomikos.agms=daily.ypiresiaid_" & startDate.Replace("-","_") & ".agms AND ypiresies_db.ypiresia_id=daily.ypiresiaid_" & startDate.Replace("-","_") & ".id_ypiresias;","allData"&i)
                        'Sleep(500)
                    Next

in the result you can check the tag and put the result in a global list based on the Tag.
Or a map and you put each result list into the map with the Tag. At the end you have one big list resp. Map of Lists...
 
Upvote 0
Top