FireDAC.DAptLayerGettingStarted Sample
This sample shows how to work with table adapters.
Contents
Location
You can find the GettingStarted sample project at:
- Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\DApt Layer\GettingStarted
- Subversion Repository:
Description
The GettingStarted sample implements some functionalities working with table adapters using the TFDSchemaAdapter and the TFDTableAdapter classes.
How to Use the Sample
- Navigate to the location given above and open
GettingStarted.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
The sample implements the following features related with table adapters.
Create schema manager
It is not required, you can create stand-alone table adapter.
FDCreateInterface(IFDDAptSchemaAdapter, oSchAdapt);
Create and assign DatSManager to schema adapter
It is not required. If it is not assigned, FireDAC automatically allocates DatSManager. Moreover, you may assign the already existing DatSManager.
var
oSchAdapt: IFDDAptSchemaAdapter;
begin
// create and assign DatSManager to schema adapter
oSchAdapt.DatSManager := TFDDatSManager.Create;
// ...
Create table adapter
It will handle hippers result set and put it into MappedShippers DatSTable.
var
oAdapt: IFDDAptTableAdapter;
begin
// create table adapter
oAdapt := oSchAdapt.TableAdapters.Add(EncodeName('Shippers'), 'MappedShippers');
// ...
Map result set columns to DatSTable columns
It is not required. By default, FireDAC handles all result set columns using their names.
oAdapt.ColumnMappings.Add('ShipperID', 'MappedShipperID');
oAdapt.ColumnMappings.Add('CompanyName', 'MappedCompanyName');
oAdapt.ColumnMappings.Add('Phone', 'MappedPhone');
Create and assign command to table adapter
To this end, the sample uses the CreateCommand and SelectCommand properties.
FConnIntf.CreateCommand(oComm);
oAdapt.SelectCommand := oComm;
oAdapt.SelectCommand.Prepare('select * from {id Shippers}');
Create DatSTable to fetch result set
The sample uses the Define method to create a DatSTable.
oAdapt.Define;
Fetch result set
The sample uses the Fetch method.
oAdapt.Fetch(True);
Get DatSTable and print it
var
oTab: TFDDatSTable;
begin
// ...
oTab := oAdapt.DatSTable;
PrintRows(oTab, Console.Lines);
// ...
Uses
See Also
Samples
- FireDAC DApt Layer Commands sample
- FireDAC DAptLayer Mapping Columns sample
- FireDAC Oracle Stored Procedures sample
- FireDAC Autoinc Fields sample