TdxDashboard.EnableCustomSql Property
Specifies if custom SQL queries are enabled for the loaded layout definition.
Declaration
property EnableCustomSql: TdxDefaultBoolean read; write; default bDefault;
Property Value
| Type | Default | Description |
|---|---|---|
| TdxDefaultBoolean | bDefault | Specifies if the current TdxDashboard container executes a custom SQL query created within the current layout definition:
|
Remarks
A layout definition loaded using the Layout property may include a SQL query if the TdxDashboard container connects to a relational database system using the TdxBackendDatabaseSQLConnection component.
Important
Custom SQL queries specified within the dashboard layout definition are initially disabled.
Enable custom SQL queries only if you ensure that you follow best practices and implement user read/write privileges at the database level using the tools available for your relational database management system.
You can set the EnableCustomSql property to bTrue or bFalse to explicitly enable or disable custom SQL queries for the current TdxDashboard container.
Code Examples
Enable Custom SQL Queries at the Dashboard Container Level
The following code example configures a TdxBackendDatabaseSQLConnection component and enables custom SQL queries at the TdxDashboard container level:
uses
dxDashboard, // Declares the TdxDashboard component
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
procedure TMyForm.cxDisplayDesignerButtonClick(Sender: TObject);
begin
ADashboard.EnableCustomSql := bTrue; // Enables custom SQL queries at the container level
dxBackendDatabaseSQLConnection1.Active := False; // Terminates the current connection (if one exists)
// Specify a user-friendly data connection name (for end-user dialogs) and a valid connection string:
dxBackendDatabaseSQLConnection1.DisplayName := 'PostgreSQL Database Connection';
dxBackendDatabaseSQLConnection1.ConnectionString :=
'XpoProvider=Postgres;' + // Specifies the database engine type
'Server=127.0.0.1;' + // Specifies the database host IP address
'User ID=myuser;' + // Specifies a valid user name
'Password=123;' + // Specifies the corresponding password for the user name
'Database=dashboard_test;' + // Specifies the target database name
'Encoding=UNICODE'; // Sets UTF-8 as the required encoding
dxBackendDatabaseSQLConnection1.Active := True; // Connects to the test database
ADashboard.ShowDesigner; // Displays the Dashboard Designer dialog
end;
Enable Custom SQL Queries Globally at Startup
The code example demonstrated in this section changes the TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql class property value to True in the initialization section of the main application unit for all TdxDashboard/TdxDashboardControl and TdxReport components in the project.
To open the main application unit of your project, you can use one of the following options:
- Select Project → View Source in the main menu of your RAD Studio IDE.
- Select the target project in the Projects Window and press Ctrl + V (alternatively, you can display the context menu and select the View Source option).
uses
Forms,
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
begin
TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql := True; // Enables custom SQL queries globally
Application.Initialize;
Application.MainFormOnTaskBar := True;
Application.CreateForm(TMyForm, MyForm);
Application.Run;
end.
Default Value
The EnableCustomSql property’s default value is bDefault.
The default EnableCustomSql property value indicates that the TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql property determines if custom SQL queries are enabled.