Setting Options (FireDAC)

From RAD Studio
Jump to: navigation, search

Go Up to Working with Connections (FireDAC)


Describes why the set of options makes FireDAC a flexible database framework and how to use the options. FireDAC provides a wide range of options organized into a hierarchical options system. Most of the options may be left with their default values.

Topics

Topic Description
Data Type Mapping FireDAC provides a flexible adjustable data type mapping system, which allows you to simplify migration to FireDAC or optimize data representation.

Description

The FireDAC options are organized into five groups:

  • FetchOptions - Fetch options that control how the components and Phys layer commands fetch data from a DBMS. For example, it is possible to fetch all records at once or fetch records on demand.
  • FormatOptions - Format options that control how the DBMS data types are mapped to the FireDAC data types and backward. For example, a programmer may set up a mapping for Oracle NUMBER (38) onto dtBCD or onto dtInt64. For more details, read Data Type Mapping.
  • UpdateOptions - Update options that control how FireDAC posts updates to DBMS. For example, during an update, FireDAC can update all fields in a table or only the changed ones.
  • ResourceOptions - Resource options that control how system resources are used, dataset persistence and other. For example, a FireDAC Phys layer command can be performed asynchronously or blocked.
  • TxOptions - Transaction options that control how transactions are performed. For example, perform them in a ReadCommitted isolation mode. Note that TxOptions does not use option value inheritance.

Because FireDAC introduces a lot of options, setting up each dataset or command may make the programming complex and error-prone. FireDAC solves this issue by introducing a parent-child option values inheritance model. The option values are propagated from a parent to a child (top-down). If a lower level has no option value assigned explicitly, a value is taken from a higher level, where a value is assigned or from the topmost level. FireDAC has the following levels:

A Manager is the topmost level, a Connection is the intermediate level, and a Command / Dataset is the bottom level. Therefore, by setting any particular Manager or Connection option, all Datasets inherit its value. This is true as long as a programmer has not explicitly assigned a value to the Dataset option.

The TxxxOptions.AssignedValues flag controls the inheritance. If an option is changed at this level, then a corresponding flag is included into AssignedValues. If a flag is not included, then an option value is inherited from the higher level. If the flag is excluded from AssignedValues, then the option inherits its value from the higher level again.

The options can be set up for a persistent connection definition using FDExplorer. After the connection is established, the options setup is applied to the TFDCustomConnection options.

Example 1

The mapping of data types, from the DBMS types to the client types defined in FormatOptions, is inherited by all Commands from their Connection.

with oConnection.Options.FormatOptions do begin
  OwnMapRules := True;
  MapRules.Clear;
  with MapRules.Add do begin
    PrecMax := 19;
    PrecMin := 4;
    SourceDataType := dtFmtBCD;
    TargetDataType := dtCurrency;
  end;
end;

Example 2

A Data Warehouse application may set up the high-speed fetching mode, using the FetchOptions of the Manager level. In this way, all connections and all their commands inherit these options.

with FDManager.FetchOptions do begin
  Items := [];
  Cache := [];
  RowsetSize := 1000;
end;

See Also