FireDAC.DAptLayerCommands Sample
This sample demonstrates how to use standalone table adapter to redirect inserting, deleting and updating records.
Contents
Location
You can find the Commands sample project at:
- Start | Programs | Embarcadero RAD Studio 10 Seattle | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\DApt Layer\Commands
- Subversion Repository:
Description
The Commands sample shows how to redirect inserting, deleting and updating records using standalone table adapter.
How to Use the Sample
- Navigate to the location given above and open
Commands.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 standalone table adapter features.
Create table adapter
var
oAdapt: IFDDAptTableAdapter;
begin
// create table adapter
FDCreateInterface(IFDDAptTableAdapter, oAdapt);
Selecting data
with oAdapt do begin
FConnIntf.CreateCommand(oComm);
SelectCommand := oComm;
SelectCommand.Prepare('select * from {id FDQA_map1}');
Define;
Fetch;
//...
Redirect records
Redirect all record inserts into FDQA_map2 table instead FDQA_map1:
FConnIntf.CreateCommand(oComm);
InsertCommand := oComm;
InsertCommand.CommandText := 'insert into {id FDQA_map2}(id2, name2) values(:NEW_id1, :NEW_name1)';
Redirect all record deletes into FDQA_map3 table instead FDQA_map1:
FConnIntf.CreateCommand(oComm);
DeleteCommand := oComm;
DeleteCommand.CommandText := 'delete from {id FDQA_map3} where id3 = :OLD_id1';
Redirect all record updates into FDQA_map4 table instead FDQA_map1:
FConnIntf.CreateCommand(oComm);
UpdateCommand := oComm;
UpdateCommand.CommandText := 'update {id FDQA_map4} set id4 = :NEW_id1, name4 = :NEW_name1 where id4 = :OLD_id1';
Add new rows
for i := 0 to 4 do
DatSTable.Rows.Add([i, 'string' + IntToStr(i)]);
Post changes to RDBMS
Update;
Uses
The sample uses the following units:
- FireDAC.DApt.Intf
- FireDAC.DApt
See Also
Samples
- FireDAC DAptLayer Getting Started sample
- FireDAC DAptLayer Mapping Columns sample
- FireDAC Oracle Stored Procedures sample
- FireDAC Autoinc Fields sample