| Both sides previous revision Previous revision Next revision | Previous revision |
| docs:2000_concepts:0600_data_retrieval:0100_config_queries [2026/07/08 05:36] – aware_admin | docs:2000_concepts:0600_data_retrieval:0100_config_queries [2026/07/09 10:22] (current) – aware_admin |
|---|
| ====== Configuring Queries ====== | ====== Configuring Queries ====== |
| |
| Queries can be defined at the configuration stage - a user can run such pre-configured queries in the Operation Mode. Pre-configured queries can also be referenced by rules (see ''[[a_f:a:find|FIND]]'' action). | AwareIM Queries are used to retrieve data from the system using specific search criteria and present results of the search to the user. Therefore AwareIM queries combine search with data presentation. Most queries are defined at the configuration stage (predefined queries, as oppsed to user-defined ones) - a configurator defines them in the Configuration Tool and a user runs them in the Operation Mode. Pre-configured queries can be referenced by rules - FIND. PICK FROM. DISPLAY and other actions of the Rule Language. |
| Queries can be implemented either by the ''[[a_f:a:find|FIND]]'' or ''[[a_f:a:exec_sp|EXEC SP]]'' or ''[[a_f:a:exec_sql;|EXEC SQL]]''actions of the Rule Language. The standard query that uses the FIND action should be suitable for most needs. However, some complex queries may require raw SQL. In this case a query can refer to a stored procedure or include a block of raw SQL that uses the SELECT SQL statement. When configurators create a new query, they specify whether they want a standard query that uses the FIND action, a stored procedure or an SQL SELECT statement. The concept of a query in **AwareIM** includes both data search criteria and a particular presentation of the found data to the user (grid, calendar, chart, tree etc). Irrespective of the implementation the options for data presentation are for the most part the same - whether it's a standard query, a stored procedure or raw SQL. | There are three types of queries as far as search criteria is concerned: |
| | - Those that use search criteria compatible with the ''[[a_f:a:find|FIND]]'' action (we will be calling them "standard queries") |
| | - Queries that use stored prcedures and map to the ''[[a_f:a:exec_sp|EXEC SP]]'' action |
| | - Queries that use the SQL SELECT statement and map to the ''[[a_f:a:exec_sql;|EXEC SQL]]''action. |
| | |
| | Standard queries should be suitable for most needs. However, some complex queries may require stored procedures or raw SQL. When configurators create a new query, they specify whether they want a standard query a stored procedure or an SQL SELECT statement. |
| | |
| | The concept of a query in **AwareIM** includes both data search criteria and a particular presentation of the found data to the user (grid, calendar, chart, tree etc). Irrespective of the implementation the options for data presentation are for the most part the same - whether it's a standard query, a stored procedure or raw SQL. |
| |
| When defining a query, the configurator has to indicate the business object, (or [[docs:2000_concepts:0200_basics:0600_business_object_groups|business object group]]) the instances of which the query will be searching. For standard queries the configurator has to either select the business object or group explicitly (if working in the Query Builder View) or provide it as part of the FIND action (if working with the Query Text View). For queries implemented as stored procedure the user has to specify the RETURN statement followed by the name of the business object or group. For queries implemented as an SQL SELECT statement, the name of the business object can be derived from the name of the table in the SELECT statement of the SQL. | When defining a query, the configurator has to indicate the business object, (or [[docs:2000_concepts:0200_basics:0600_business_object_groups|business object group]]) the instances of which the query will be searching. For standard queries the configurator has to either select the business object or group explicitly (if working in the Query Builder View) or provide it as part of the FIND action (if working with the Query Text View). For queries implemented as stored procedure the user has to specify the RETURN statement followed by the name of the business object or group. For queries implemented as an SQL SELECT statement, the name of the business object can be derived from the name of the table in the SELECT statement of the SQL. |
| </callout> | </callout> |
| |
| | ===== Defining Queries Implemented as Stored Procedures===== |
| | As explained before, queries implemented as stored procedures refer to a particular stored procedure defined in the AwareIM database. When such queries execute, **AwareIM** automatically executes the related stored procedure providing values of parameters if required. The results of the stored procedure are then presented to the user as defined by the query - either as a grid, a calendar or a chart. The query follows the format of the ''[[a_f:a:exec_sp|EXEC SP]]'' action. Some examples are described below: |
| |
| | <code>EXEC_SP 'AllCustomers' RETURN Customer</code> |
| | This query is implemented as a stored procedure called "AllCustomer". The stored procedure does not require any parameters and return results that are compatible with the structure of the Customer object (the stored procedure returns records of the table that the Customer object is mapped to in the database). |
| | |
| | <code>EXEC_SP 'TESTWITHPARAM' WITH 'ProspState'=ParamObject.State, 'ProspName'='Julie%' RETURN Prospect</code> |
| | This stored procedure has two parameters - the second is hardcoded and the first one is initialized from the object in Context (ParamObject). |
| | |
| | <callout type="primary" icon="true" title="note"> |
| | When a configurator defines a new **AwareIM** query implemented as stored procedure and the stored procedure already exists, a developer can initialize the new query from the list of stored procedures available in the database and generate an appropriate EXEC_SP statement. |
| | </callout> |
| | |
| | <callout type="primary" icon="true" title="note"> |
| | **AwareIM** automatically provides support for dynamic paging, dynamic sorting and dynamic filtering of records returned by queries implemented as stored procedures. However, you need to know the following: |
| | - Support for dynamic paging, sorting and filtering is only provided for MySQL and SQL Server databases. |
| | - If a stored procedure has multiple SELECT statements, **AwareIM** needs to know which one of the SELECT statements returns records compatible with the RETURN statement of the stored procedure. To do this, enclose this SELECT statement with BEGIN MAIN SELECT and END MAIN SELECT comments, for example: |
| | %%-- BEGIN MAIN SELECT%%\\ |
| | %%SELECT...%%\\ |
| | %%-- END MAIN SELECT%%\\ |
| | </callout> |
| | |
| | ===== Defining Queries Implemented as SQL SELECT Statements ===== |
| | Queries implemented as SQL SELECT statements should just include the SELECT statement in the query textual view. The SQL table that the SELECT statement operates with should be the table that stores records of a business object that the query queries on. Before AwareIM runs such a query it replaces any tag expressions used in the SELECT statement with values from Context, so the SELECT statement is allowed to include tag expressions. For example: |
| | <code>SELECT * FROM Customer WHERE Name=<<ParamObject.Name>></code> |
| |