- Reading data during query initialization
- Adding records and using the hModifyFile constant
- Why should the hQueryWithoutCorrection constant be used
- Passing parameters to the query
- Freeing the resources of the query
- Optimizing the queries on HFSQL data files
- Running a query and Table control based on this query
- Executing a query and a report based on this query
- SQL queries (HExecuteQuery or execution of SQL queries created in the query editor)
HExecuteQuery (Function) In french: HExécuteRequête
Not available with this kind of connection
Declares a query to the HFSQL engine and runs this query. This query can correspond to: - a query created in the query editor.
- an SQL Query variable.
Then, the query result can be read. If a query with the same name already exists, this query is replaced. The result is recalculated. Attention: To position yourself on the first record in the query result, use the HReadFirst function, for example. To free the resources of a query created in the query editor, use: Note: A query cannot be initialized if: - the query name is already used in the current analysis (data file name or name defined by one of the following functions: HDeclare, HDeclareExternal, HDescribeFile).
- a syntax error is found in the query.
HExecuteQuery(QRY_Customer_84)
HExecuteQuery(QRY_MyQuery, hQueryDefault, 5)
sQueryFile is string
sQueryFile = fReportsAndQueriesDir() + ["\"] + "QRY_List_Products.WDR"
QRY_List_Products is Data Source
HExecuteQuery(sQueryFile, hQueryDefault, FAMILY_CODE)
FOR EACH QRY_List_Products
TableAddLine(TABLE_PRODUCT, sQueryFile.PRODUCT_NAME, ...
sQueryFile.DESIGNATION, sQueryFile.PriceBT)
END
Syntax
Executing a query (without connection) Hide the details
<Result> = HExecuteQuery(<Query name> [, <Mode> [, <Parameter 1> [... [, <Parameter N>]]]])
<Result>: boolean - True if the query was initialized,
- False otherwise. HErrorInfo returns more details about the problem.
<Query name>: Character string Name of the query to run: - Name and full path of query (".WDR" file) to initialize.
- Logical name of the query to be initialized.
If a query with the same name is already declared, it is replaced with the new query. - Name of a variable of type SQL query.
<Mode>: Optional Integer constant Option for initializing the query: | | hCheckDuplicates | Enables the management of duplicates during the query execution. The query is not run if a duplicate error occurs. This constant forces the hWithTransaction constant. A transaction is started, the records are locked in read/write during the execution of the query and they are unlocked at the end of its execution, regardless of the result (failure or success). If the application is stopped during the query execution (power outage for example), the transaction will be canceled when the data files of query are used for the next time. Note: The execution of the query can be significantly slowed down.
| hCheckIntegrity | Enables the management of integrity during the query execution. The query is not run if an integrity error occurs. This constant forces the hWithTransaction constant. A transaction is started, the records are locked in read/write during the execution of the query and they are unlocked at the end of its execution, regardless of the result (failure or success). If the application is stopped during the query execution (power outage for example), the transaction will be canceled when the data files of query are used for the next time. Note: The execution of the query can be significantly slowed down.
| hModifyFile (option that can be combined with the other constants) | On HFSQL data files When modifying the query result (functions HAdd, HWrite, HModify, HCross, HDelete), these modifications will be transferred to the data files contributing to the query. If this option is not specified, only the query result is modified. For more details on modifying the result of a query, see Modifying the query content. On non-HFSQL data filesfiles, the constant hModifiesFile is useless: data files contributing to the query are automatically modified when the query result is modified.
| hNoHourglass | When reading the query result, this read operation may be locked and an hourglass appears by default. This constant is used not to display the hourglass in this case.
| hQueryBreakable | The query initialization can be interrupted by the ESC key. Note: This constant can only be used with a selection query (SELECT).. Other query types (INSERT, UPDATE, DELETE, etc.) are not interruptible.. | hQueryDefault (default value) | The query is initialized without interruption. | hQueryWithoutCorrection | | hQueryWithoutHFCorrection | | hWithFilter (option that can be combined with the other constants) | If this parameter is specified:- the query result corresponds to a selection of filter records if the HFSQL engine allows it. Otherwise, the query result corresponds to an HFSQL view
- the following operations are not possible: search on the result of the query, query on query, view on query, query on view.
- the browse items specified when looping through the result are ignored.
- the magnifier is not available for the tables linked to a query.
- HNbRec cannot be used on the queries.
Warning: if this option is specified, the constant hChangeFile constant is automatically used. If this parameter is not specified (by default):- the query result corresponds to an HFSQL view
- the following operations can be performed on the queries: search on the result of the query, query on query, view on query, query on view.
- the browse items specified when looping through the result are taken into account.
- the magnifier is available on tables linked to a query.
- HNbRec can be used on the queries.
| hWithTransaction | The query is run in a transaction. A transaction is started, the records are locked in read/write during the execution of the query and they are unlocked at the end of the query execution, regardless of the query result. If the query cannot end properly (locked records, power failure, etc.), the transaction is canceled and the data files are restored to their previous status (before the query execution). Note: The execution of the query can be significantly slowed down.
| hYield | For the UPDATE and DELETE queries performed on an important number of records and being quite long, this constant is used to give control back to the other applications that use the data files. In this case:- the query runs a little slower,
- the file server is not saturated,
- the other users of data files can still access them without being locked.
|
<Parameter 1>: Type of parameter Values of query parameters in their initialization order (visible in the query editor). Each parameter must correspond to the expected type. The different parameters are separated by a comma. Remarks:- Passing parameters in HExecuteQuery is kept for backward compatibility. It is recommended to pass parameters using the following notation: <Query name>.<Parameter name> = <Value>.
- To specify the query parameters, the <Mode> parameter must be specified.
- The value of each parameter can be specified or not.
- You can specify a list of values or a list of parameters.
For more details, see Passing parameters.
This parameter is not available if <Query name> corresponds to an SQL Query variable. <Parameter N>: Type of parameter Values of query parameters in their initialization order (visible in the query editor). Each parameter must correspond to the expected type. The different parameters are separated by a comma. Remarks:- Passing parameters in HExecuteQuery is kept for backward compatibility. It is recommended to pass parameters using the following notation: <Query name>.<Parameter name> = <Value>.
- To specify the query parameters, the <Mode> parameter must be specified.
- The value of each parameter can be specified or not.
- You can specify a list of values or a list of parameters.
For more details, see Passing parameters.
This parameter is not available if <Query name> corresponds to an SQL Query variable. Remarks Reading data during query initialization Depending on the query (sorts, groups, etc.), the data can be read (or not) when initializing the query. Note: The ExecutionCompleted property indicates whether the query has completed filling (and can therefore be read without blocking).. Passing parameters to the query Several methods can b e used to pass parameters to a query: - Passing parameters with the following notation: <Query name>.<Parameter name> = <Value> (recommended)
- Passing parameters in HExecuteQuery (kept for backward compatibility, compatible with PHP).
Let's present these two methods: - Passing parameters with the following notation: <Query name>.<Parameter name> = <Value> (recommended)
To pass parameters to a query with parameters before executing it, you can also use the following syntax:
<Query name>.<Name of parameter 1> = xxx <Query name>.<Name of parameter 2> = xxx <Query name>.<Name of parameter 3> = xxx HExecuteQuery(<Query name>) IF ErrorOccurred = True THEN ... Remarks:- This syntax makes it easier to pass parameters. Indeed, if the parameters are directly passed to HExecuteQuery, the order of parameters must be complied with.
- The structure of the query parameters is reset each time the query is executed.
- Passing parameters in HExecuteQuery (kept for backward compatibility)
In this case, the values of query parameters must be specified in their initialization order (visible in the query editor). Each parameter must correspond to the expected type. The different parameters are separated by a comma. The value of each parameter can be specified or not. A parameter can be ignored by using the Null value. In this case, the selection conditions that uses this parameter will be ignored.
You can specify a list of values or a list of parameters. If the selection condition for one of the query parameters is "is included in the list" or "is not included in the list", you must specify a list of values or parameters. To specify a list of values or a list of parameters, the different values or parameters must be separated by a semi-colon (';'), a carriage return ('CR') or a tabulation ('TAB'). For example:
HExecuteQuery(QueryName, hQueryDefault, "34000;34200;34400")
ouHExecuteQuery(QueryName, hQueryDefault, "34000 "+ CR + "34200" + CR + "34400")
ouHExecuteQuery(QueryName, hQueryDefault, "34000" + TAB + "34200" + TAB + "34400")
Note If one of the values or parameters contains a semicolon, a carriage return or a tab, it is necessary to surround this value or parameter with quotes. For example:
HExecuteQuery(QueryName,hQueryDefault, "'A;A';'A;B';'A;C'")
Note: Not all query parameters need to be specified.. The query conditions that use unspecified parameters will be ignored. Example: Let the query "Customers_first_name" have the following SQL code:
SELECT * FROM CUSTOMER WHERE LASTNAME = {Param1} AND FIRSTNAME = {Param2} - The 2 parameters are specified:
HExecuteQuery(QRY_Customers_LastName_FirstName, hQueryDefault, "Smith", "John")
will execute the querySELECT * FROM CUSTOMER WHERE LASTNAME = 'Smith' AND FIRSTNAME = 'John' - Only the last name is specified:
HExecuteQuery(QRY_Customers_LastName_FirstName, hQueryDefault, "Smith")
will execute the querySELECT * FROM CUSTOMER WHERE LASTNAME= 'Smith' - Only the first name is specified:
sName is TO Variant = Null
HExecuteQuery(QRY_Customers_LastName_FirstName, hQueryDefault, sLastName, "John")
OR
HExecuteQuery(QRY_Customers_LastName_FirstName, hQueryDefault, Null, "John")
will execute the querySELECT * FROM CUSTOMER WHERE FIRSTNAME= 'John'
Freeing the resources of the query To free the resources of a query, use: If this operation is not performed, the query is still found in the current HFSQL context and it can be accessed from any process. Remarks: - The query resources are not automatically released when the window that executed the query is closed (via HExecuteQuery).
- The SQL Query variables are automatically freed at the end of variable scope. For more details, see SQL queries in WLanguage.
Business / UI classification: Business Logic
This page is also available for…
|
|
|