B4J Question Wait For on Mysql read

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I have a large Mysql data set and want to halt the read sub routine until the Mysql result is returned.
If I am not mistaken then the 'Wait For' will do this.

My question is how to do this?

B4X:
Sub getLocation(rec as int)as string

    Dim latlng As String = sql.ExecQuerySingleResult("SELECT location FROM address WHERE addrID = "&rec&"")

   Wait for sql_Success

   Return latlng

End Sub

Is Wait for sql_Success correct?

Thanks
 

OliverA

Expert
Licensed User
Longtime User
Tutorial: https://www.b4x.com/android/forum/threads/b4x-sql-with-wait-for.79532/

Please note that wait for is only for batch and asynchronous queries. Simple selects and single result are included/supported by wait for. You could call the query via the asynchronous function and process the resulting record set for your answer if necessary due to long running select query.

Looks like I have a reading comprehension issue: since you are using single result query, it blocks until you get the answer. No wait for needed.
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thanks OliverA,

I thought I had seen this post but I couldn't find it again.

Your answer confuses me a little. I need to halt my sub until the 'ExecQuerySingleResult' is returned.

Will study Erel's tutorial.

Thanks
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Yeah, not enough sleep...

If you just want to block the execution of your app and wait for the result, you have to do nothing. ExecQuerySingleResult is a synchronous function and therefore will not return until it has finished executing your query. Since you mentioned wait for, my mind read your question as wanting to not block. Instead of deleting my answer and just posting the correction, I left my original incorrect answer and then added the, hopefully, correct answer.

Edit (again):

All you need is

B4X:
Sub getLocation(rec as int)asstring

DimlatlngAsString = sql.ExecQuerySingleResult("SELECT location FROM address WHERE addrID = "&rec&"")

Return latlngEnd 

End Sub
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
OK, Understand now..

I wasn't sure if the ExecQuerySingleResult was synchronous or not.

My sub routine didn't appear to be returning all the correct items so I was investigating using the 'wait for'..

Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…