Back to Devexpress

TdxCustomDashboardControl.EnableCustomSql Property

vcl-dxdashboard-dot-control-dot-tdxcustomdashboardcontrol-e800fe42.md

latest9.0 KB
Original Source

TdxCustomDashboardControl.EnableCustomSql Property

Specifies if custom SQL queries are enabled at the control level.

Declaration

delphi
property EnableCustomSql: TdxDefaultBoolean read; write; default bDefault;

Property Value

TypeDefaultDescription
TdxDefaultBooleanbDefault

Specifies if the current TdxDashboardControl component executes a custom SQL query created within the current layout definition and allows users to input custom SQL queries in the UI:

bDefault

The TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql property specifies if the custom SQL query-related functionality is enabled.

Tip

This is a strongly recommended option that ensures the safety of SQL queries if the TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql property value is not modified.

bTrue

Custom SQL queries are explicitly enabled for the TdxDashboardControl component.

Warning

This option disables safety-related limitations on SQL queries at the control level. Ensure that you set all necessary user read/write privileges at the database level.

bFalseCustom SQL queries are explicitly disabled for the TdxDashboardControl container. |

Remarks

A layout definition loaded using the Layout property may include a SQL query if the TdxDashboardControl component connects to a relational database system using the TdxBackendDatabaseSQLConnection component.

Important

Custom SQL queries specified within the dashboard layout definition are initially disabled and custom SQL query-related functionality is disabled in the UI.

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 and corresponding UI elements for the current TdxDashboardControl component.

Code Examples

Enable Custom SQL Queries at the Control Level

The following code example configures a TdxBackendDatabaseSQLConnection component and enables custom SQL queries at the TdxDashboardControl control level:

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(Sender: TObject);
begin
  dxDashboardControl1.EnableCustomSql := bTrue; // Enables custom SQL queries at the control 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
  dxDashboardControl1.ShowDesigner; // Displays the Dashboard Designer dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.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)
{
  dxDashboardControl1->EnableCustomSql = bTrue; // Enables custom SQL queries at the control 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
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

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.

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 ProjectView 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).

  • Delphi

  • C++

delphi
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.
cpp
#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();
}

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.

See Also

TdxDashboard.EnableCustomSql Property

TdxReport.EnableCustomSql Property

TdxCustomDashboardControl Class

TdxCustomDashboardControl Members

dxDashboard.Control Unit