Android Question Wait for, need help on how to use it

Oscarin

Member
Hi, I am using this tutorial on how to connect to MySQL DB
But I have a problem because I need to wait for the query to finish before proceeding on to the next process.
I send a SELECT * FROM and I need to wait for the result because depending on the result I will do an UPDATE or an INSERT, I know about the WAIT FOR, but unfortunately I don't know how to use it.
I am using the exact same code as the tutorial, just modified to my needs
Thanks for any help.
 

Ertan

Active Member
Licensed User
The SQL library supports asynchronous select queries and asynchronous batch inserts. Asynchronous means that the task will be processed in the background and an event will be raised when the task completes. This is useful when you need to issue a slow query and keep your application responsive. The usage is quite simple:


B4X:
SQL1.ExecQueryAsync("SQL1", "SELECT * FROM table1", Null)
...
Sub SQL1_QueryComplete (Success As Boolean, ResultSet1 As ResultSet)
If Success Then
Do While ResultSet1.NextRow
Log(ResultSet1.GetInt2(0))
Loop
Else
Log(LastException)
End If
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Hi, I am using this tutorial on how to connect to MySQL DB
1. The thread is 11 Years old. The first sentence points to JRDC2 which is the suggested method to use.
Setup jRDC2 on your server, let jRDC2 connect to the Database.
Use the Client-Methods to connect to your jRDC2 to fetch data.

2. 'It is NOT recommended to connect directly to MySQL from B4A. But here is the link for an example: https://www.b4x.com/android/forum/threads/jdbcsql-directly-connect-to-remote-databases.84016/

The TO is asking about MySQL, NOT SQLite!
The SQL library supports asynchronous select queries and asynchronous batch inserts.
The TO is asking about MySQL, NOT SQLite!
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
B4X:
 I know about the WAIT FOR, but unfortunately I don't know how to use it.

Just in case the previous replies have not made this clear, the important thing about "Wait For ..." is that when the program flow reaches the "Wait For" it does not actually "wait". Using "Wait For" creates a ResumeableSub, meaning that the subroutine returns control to the caller while it is waiting for an event. When the event occurs then the ResumeableSub immediately resumes (takes control) and then returns control again when it is finished. So this will not work ...
B4X:
    ...
    getFile(filename)                ' "getfile" contains a Wait For ...
    File.ReadString(xui.DefaultFolder, filename)
    ...
 
Upvote 0

Similar Threads

Replies
36
Views
104K
Replies
120
Views
178K
  • Locked
  • Article
Android Tutorial SQL tutorial
Replies
161
Views
278K
Top