FireDAC.MappingColumns Sample
This sample demonstrates how to map columns.
Contents
Location
You can find the MappingColumns sample project at:
- Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\DApt Layer\MappingColumns
- Subversion Repository:
Description
The Commands sample shows you how to set up column mappings.
How to Use the Sample
- Navigate to the location given above and open
MappingColumns.dproj
. - Press F9 or choose Run > Run.
- Click on the Use Connection Definition combo box and select an option.
Files
File in Delphi | Contains |
---|---|
|
The project itself. |
|
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
- FireDAC DAptLayer GettingStarted sample
- FireDAC DApt Layer Commands sample
- FireDAC Oracle Stored Procedures sample
- FireDAC Autoinc Fields sample