Delphi Learn How Easy It Is To Map Dataset Columns With A Table Adapter In FireDAC For Delphi

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,203
Credits
4,034
Learn How Easy It Is To Map Dataset Columns With A Table Adapter In FireDAC For Delphi
March 6, 2021 By Konstantin Tomov

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

Location​

You can find the MappingColumns sample project at:
  • Start | Programs | Embarcadero RAD Studio Sydney | Samplesand then navigate to:
    • Object PascalDatabaseFireDACSamplesDApt LayerMappingColumns
  • Subversion Repository:
    • You can find Delphi code samples in Для просмотра ссылки Войди или Зарегистрируйся. Search by name into the samples repositories according to your RAD Studio version.

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.
1615152161634.png

Files​

File in DelphiContains
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;
    <em>// ...</em>
  begin
    <em>// create table adapter</em>
    FDCreateInterface(IFDDAptTableAdapter, oAdapt);

Assign command​

Код:
var
    oComm: IFDPhysCommand;
    <em>// ...</em>
  begin
    <em>// ...</em>
    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;
Please go to the link below if you want to check the original post of Embarcadero for this sample:

Для просмотра ссылки Войди или Зарегистрируйся
Для просмотра ссылки Войди или Зарегистрируйся