FireDAC Components for Presto

Build 22.0.8462

Connection Definitions

The TFDPhysCDataPrestoConnectionDefParams class hooks into compiler syntax checking and Code Insight hints to enable you to quickly and accurately define connections. However, there are several other ways to define connections from code, also explored here.

See Establishing a Connection to define connections with GUI tools.

Understanding Connection Types

The following examples show how to create three kinds of connections:

Persistent
  • Saved in an INI file and thus can be accessed by multiple applications.
  • Can be defined in the Data Explorer, FDManager, or directly in the INI file.
  • Connections have a unique name.
  • Specified with the ConnectionDefName property of a TFDConnection.
Private
  • Not saved in a file, so connections cannot be accessed outside the application.
  • Must be defined in code.
  • Defined in the FDManager function.
  • Connections have a unique name.
  • Specified with the ConnectionDefName property of a TFDConnection.
Temporary
  • Can be defined with the FireDAC Connection Editor or in code.
  • Not managed by the FDManager function -- defined for a single TFDConnection instance.
  • Cannot be referenced by name.
  • Defined in TFDConnection.Params or TFDConnection.ConnectionSTring

Using TFDManager

You can use TFDManager to create private connections or persistent connections. To define a persistent connection in code, set the last input in the method signature to true. Otherwise, the connection is private.

Additionally, save the persistent connection.

var
  oDef: IFDStanConnectionDef;
  oParams: TFDPhysCDataPrestoConnectionDefParams;
begin
  oDef := FDManager.ConnectionDefs.AddConnectionDef;
  oDef.Name := 'FDManagerTest';

  oParams := TFDPhysCDataPrestoConnectionDefParams(oDef.Params);
  oParams.DriverID := 'CDataPresto';
  oParams.AStringParam := 'AStringValue';
  ...
  oDef.MarkPersistent; //Set this for a persistent connection
  oDef.Apply;
end;
To assign the connection to a TFDConnection object, set the ConnectionDefName property:
FDConnection1.ConnectionDefName := 'CDataPrestoConn';
FDConnection1.Connected := True;

Using TFDConnection

You can set connection properties directly in TFDConnection objects to create temporary connection definitions. The following method enables you to take advantage of Code Insight and compiler syntax checking.

FDConnection1.DriverName := 'CDataPresto';
with FDConnection1.Params as TFDPhysCDataPrestoConnectionDefParams do begin
    ParamName := ParamValue; 
    ...
end;
FDConnection1.Connected := True;
However, you can also simply set the ConnectionString property of a TFDConnection object:
FDConnection1.ConnectionString := 'DriverId=CDataPresto;Server=127.0.0.1;Port=8080;';
FDConnection1.Connected := True;

Using Connection Definition Files

You can also define persistent connections in configuration files. The section name of the file defines the connection name. The section consists of the connection properties in name-value pairs. For example:

[Presto_Demo]
DriverID=CDataPresto
...
To create connections based on the entries, set the ConnectionDefFileName property of FDManager to the configuration file's path. This path can be relative to the folder containing the application's .exe file.

You can then assign the connection to a TFDConnection object by setting its ConnectionDefName property.

FDManager.ConnectionDefFileName := ExtractFilePath(Application.ExeName) + 'prestoconnections.ini';
FDConnection1.ConnectionDefName := 'CDataPrestoConn';
FDConnection1.Connected := True;

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462