vcl-dxdashboard-dot-tdxdashboard-4661bf35.md
Specifies if custom SQL queries are enabled for the loaded layout definition.
property EnableCustomSql: TdxDefaultBoolean read; write; default bDefault;
| Type | Default | Description |
|---|---|---|
| TdxDefaultBoolean | bDefault |
Specifies if the current TdxDashboard container executes a custom SQL query created within the current layout definition:
The TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql property specifies if the TdxDashboard container executes custom SQL queries.
Tip
This is a strongly recommended option that ensures the safety of SQL queries if the TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql property value is not modified.
Custom SQL queries are explicitly enabled for the TdxDashboard container.
Warning
This option disables safety-related limitations on SQL queries at the TdxDashboard container level. Ensure that you set all necessary user read/write privileges at the database level.
bFalseCustom SQL queries are explicitly disabled for the TdxDashboard container. |
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.
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;
#include "dxDashboard.hpp" // Declares the TdxDashboard component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component
// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard" // Required to use dxDashboard.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
#pragma link "dxBackend.ConnectionString.SQL.o"
#else
#pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...
void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
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 =
L"XpoProvider=Postgres;" // Specifies the database engine type
L"Server=127.0.0.1;" // Specifies the database host IP address
L"User ID=myuser;" // Specifies a valid user name
L"Password=123;" // Specifies the corresponding password for the user name
L"Database=dashboard_test;" // Specifies the target database name
L"Encoding=UNICODE"; // Sets UTF-8 as the required encoding
dxBackendDatabaseSQLConnection1->Active = true; // Connects to the test database
ADashboard->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}
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.
Open the Project Source to Edit the Main Function
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.
#include <vcl.h>
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------------------
USEFORM("Unit1.cpp", MyForm);
//---------------------------------------------------------------------------------------
int WINMAIN _tWinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
TdxBackendDatabaseSQLConnection::DefaultEnableCustomSql = true; // Enables custom SQL queries globally
Application->Initialize();
Application->MainFromOnTaskBar = true;
Application->CreateForm(__classid(TMyForm), &MyForm);
Application->Run();
}
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.
See Also
TdxCustomDashboardControl.EnableCustomSql Property