The Advanced Query element allows you to execute standard SQL queries over your application's Entities. Before using an advanced query, consider using Simple Queries instead since they are highly optimized and future-proof.

Advanced Query Interface

Advanced queries are black-boxes, meaning that they can only have access to data that is sent through input parameters, and other logic can only access what they return through the output parameter.

As such, an advanced query can have:

Since the OutSystems Platform has a strongly typed language, you need to define the structure (data types of the columns) that your query  returns. For example if you perform a query over the User entity, that selects the attributes Id, Name, Email, PhoneNumber, you need to specify that your query has an output structure that has the User Record type.

This makes the List output parameter of the advanced query have the User Record List data type. Learn more about the Advanced Query Output Structure.

Execute an Advanced Query

To execute an advanced query use the following steps:

What you Should Know

When defining, testing, and executing an advanced query, there are some details that you should be aware of:

Re-executing a Query

There are scenarios in which you might need to execute the same query twice. For example fetching the data in the Preparation, before the screen loads, and then execute the same logic after the end-user has executed an action. In such situations you can place your query in the Preparation of the Web Screen and use the Refresh Query tool on the flow of the screen action where you need to re-execute the query.

Query Time-out

To ensure the scalability of your infrastructure, queries are only allowed to run for a specified time: if the query does not return results within that time frame, the query is aborted ensuring your database performance is not compromised, an exception is thrown and the error is logged in Service Center.

By default, the query time-out is 30 seconds, but you can adjust this value to your needs as follows:

Due to limitations of the database connector used in the .Net version of the Agile Platform, queries executed over Oracle databases don't have a timeout, even if one is specified. In these scenarios you should ensure that your queries are carefully designed, to avoid deteriorating the performance of the database server.

Improving Runtime Performance

To improve the runtime performance of your Simple Queries, you can use cache, to avoid fetching twice the same data from the database. To do so, simply set a value in the Cache in Minutes property of the advanced query.

Learn more about caching contents.

See Also

Advanced Query Properties | Advanced Query Editor | About Refreshing a Query | Manage Entities | Handling Transactions with External Systems