Android Question Use ExecQueryAsync or ExecQuery2 with B4XFloatTextField1_TextChanged

Mahares

Expert
Licensed User
Longtime User
I use the below code with ExecQueryAsync and a search using B4XFloatTextField1_TextChanged. Since the xCLV data is updated frequently and every character entered, is it more appropriate to use ExecQuery/ExecQuery2 as opposed to ExecQueryAsync.
B4X:
Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    Dim SenderFilter As Object
    If New.Length = 0 And Old.Length > = 1  Then
        SenderFilter = Starter.sql.ExecQueryAsync("SQL", $"SELECT DISTINCT Num FROM ${TableName} "$, Null)
    Else if New.Length > = 1 Then
        SenderFilter = Starter.sql.ExecQueryAsync("SQL", $"SELECT DISTINCT Num
         FROM ${TableName} WHERE lower(Num) LIKE ? ORDER BY Num, Name"$, Array As String($"%${New.ToLowerCase}%"$) )
    End If
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs1 As ResultSet)
I saw in another thread, that it was recommended not to use the Async method when data is updated, frequently.
 

Pendrush

Well-Known Member
Licensed User
Longtime User
ExecQuery - run on Main thread, blocking code execution until it finish.
ExecQueryAsync - run on other thread without blocking main thread (UI) and do not block code execution, also UI will not "lag/freeze".
I think on multiple ExecQueryAsync execution order of execution can be compromised. Second ExecQueryAsync can be executed before first one, depend on how complex is query.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top