SQL query tool

SAFE X3 technology includes a Query tool function (GESALH) designed to create inquiry screens from queries expressed as lists of fields drawn from database tables. These tables are linked either by default or through explicitly defined relationships. This approach enables you to quickly build queries without needing to learn a specific query language, requiring only a basic understanding of the database structure. Such knowledge can be supported by technical documentation (such as the MCD pages).

The tool also provides a user-friendly interface with multi-column inquiry screens and supports navigation through tunnels. However, it has limitations when handling complex queries that cannot be represented as simple lists of fields. For technically skilled users familiar with SQL, this tool may not deliver the desired flexibility or results.

To address this, this additional SQL query tool was introduced, allowing you to write queries using standard SQL syntax. This tool differs from the standard query tool only in its setup screen. The resulting inquiry screens are executed through the same View queries function (EXEALH). Like the standard tool, it operates by temporarily extracting data into a table for consultation. However, inquiries are limited to a single level, and features such as breaks and totals are not supported at this stage.

As with the classic query tool, the temporary table structure ensures that each user retains the results of their last executed query. Using this functionality involves three steps:

  1. Define the query using the function, then validate it to generate the corresponding inquiry screen.

  2. Run the query by clicking the Run button.

  3. Consult the results if the query has already been executed.

Prerequisites

Refer to the implementation documentation.

Screen management

The screen is defined in 3 tabs:

The header provides information to identify the query, along with general configuration settings.

Setup tab

You can use the first block to define the query and specify general parameters.

In the Columns grid, you can provide details to refine the presentation of the results. When the query is executed, it returns a list of values displayed in a grid. If no additional information is provided:

  • The grid columns have no titles.

  • Data types default to generic formats (alphanumeric, numeric, or date) based on the returned values.

A fixed SQL query offers limited flexibility. To make the query dynamic, you need to include parameters that can be entered at runtime. Use the Parameters grid to do so.

Graph tab

You can edit this tab only if a graphical representation is available for the query. It allows you to define how the data displays in the chart.

The SQL query tool does not apply any authorization-based filters (whether by role, site, or access codes).

To ensure security:

  • Protect these queries with an access code to restrict both display and execution rights.

  • Limit access to this function to a restricted list of users.

Specific buttons

Error messages

Other than the generic messages, the following error messages can appear when entering data:

Incorrect query

Your query is incorrect.

[Error description returned by the database]

From the database perspective, the query is invalid. This can be due to a syntax error or because a referenced element does not exist. The error description corresponds to the message returned by the database.

Not possible to access this record

An attempt was made to access a query created with the classic query tool using the SQL query tool. This is not allowed because query codes are tool-specific:

  • You cannot use codes from an SQL query to reference a classic query.

  • Likewise, you cannot use codes from a classic query for an SQL query.

Too many fields

The query has returned too many columns. The SQL query tool supports a maximum of 120 columns. Reduce the number of columns in your query and try again.

Tables used

Refer to the implementation documentation.