FireDAC.MappingColumns Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to map columns.

Location

You can find the MappingColumns sample project at:

Description

The Commands sample shows you how to set up column mappings.

How to Use the Sample

  1. Navigate to the location given above and open MappingColumns.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.

Files

File in Delphi Contains

MappingColumns.dproj
MappingColumns.dpr

The project itself.

fMappingColumns.pas
fMappingColumns.fmx

The main form.

Implementation

To set up the columns mapping, the sample implements the following steps.

Create table adapter

  var
    oAdapt: IFDDAptTableAdapter;
    // ...
  begin
    // create table adapter
    FDCreateInterface(IFDDAptTableAdapter, oAdapt);

Assign command

  var
    oComm: IFDPhysCommand;
    // ...
  begin
    // ...
    with oAdapt do begin
      FConnIntf.CreateCommand(oComm);
      SelectCommand := oComm;
      SelectCommand.Prepare('select * from {id FDQA_map1}');

Set source result set name

      SourceRecordSetName := EncodeName('FDQA_map1');

Set the DatSTable name

Set the DatSTable name where the rows are fetched.

      DatSTableName := 'mapper';

Set the UpdateTable name

      UpdateTableName := EncodeName('FDQA_map2');

Set the UpdateTable name

      UpdateTableName := EncodeName('FDQA_map2');

Setup column mappings

      ColumnMappings.Add('id1', 'num', 'id2');
      ColumnMappings.Add('name1', 'title', 'name2');

Fetch rows

      Define;
      Fetch;

Update changes to RDBMS

To append rows, implement the following code:

      for i := 0 to 9 do
        DatSTable.Rows.Add([i, 'first' + IntToStr(i)]); // Note that new rows will be added to the FDQA_map2(id2, name2) table.

Then, the sample updates the changes to the RDBMS.

      Update;

Uses

The sample uses the following units:

  • FireDAC.DApt.Intf
  • FireDAC.DApt

See Also

Samples

Personal tools
Assistance