|
|
|
|
|
- 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
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|