PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN

  • Executing an asynchronous query
HExecuteQueryAsynchronous (Example)
Executing an asynchronous query
This example executes an SQL query and displays the result in a table, without blocking the user and offering the possibility to interrupt the query.
QRY_Customers is SQL Query
[
SELECT *
FROM CUSTOMER
where
CUSTOMER.LASTNAME LIKE = {pLASTNAME}
]
// Clear the result Table control
TableDeleteAll(TABLE_QRY_Customers)
TABLE_QRY_Customers.Caption = "Searching for customers..."
// Assign query parameters, if any:
QRY_Customers.pLASTNAME = "SMITH"
// Starting the query
IF NOT HExecuteQueryAsynchronous(QRY_Customers, hDefaultQuery, ...
 ProcessForEachRecord, ProcessEndQuery) THEN
Error(HErrorInfo())
END
 
// Procedure that will be called for each record
INTERNAL PROCEDURE ProcessForEachRecord(AResultRow is Record)
// where AResultRow is Record of QRY_Customers
TableAddLine(TABLE_QRY_Customers,...
             AResultRow.LASTNAME,...
             AResultRow.FIRSTNAME,...
             AResultRow.COMPANY,...
             AResultRow.POSTALCODE,...
             AResultRow.CITY,...    
             AResultRow.COUNTRY)
   
// Returns True to continue looping through the query results
// False to stop looping through the results, for example after reading
// a maximum number of records ...
    RETURN True
END
 
// Procedure that will be called at the end of the query
INTERNAL PROCEDURE ProcessEndQuery(MyRes is int)
// Query completed
SWITCH MyRes
CASE heqaOK:
TABLE_QRY_Customers.Caption = "Search completed."
 
CASE heqaCanceled:
TABLE_QRY_Customers.Caption = "Search canceled, show" ...
TABLE_QRY_Customers.Count + " first" + ...
PCS_SANS_TRADUCTION_US ...
" customer" + AddPluralIfNecessary(TABLE_QRY_Customers.Count) + ...
" found"
 
OTHER CASE: // heqaError
TABLE_QRY_Customers.Caption = "Error searching for customers"
ErrorAsynchronous("Error retrieving data.", HErrorInfo())
END
 
END
 
INTERNAL PROCEDURE AddPluralIfNecessary(nQty is int,
sPluralLetter is string = "s"): string
IF nQty <=1 THEN
RETURN ""
ELSE
RETURN sPluralLetter
END
END
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment