This sample shows how to redirect inserting, deleting and updating records using standalone table adapter.
Table of Contents
Location
You can find the Commands sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object PascalDatabaseFireDACSamplesDApt LayerCommands
 - Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
 
 
Files

| File in Delphi | Contains | 
|---|---|
Commands.dprojCommands.dpr | The project itself. | 
fCommands.pasfCommands.fmx | The main form. | 
Implementation
The sample implements the following standalone table adapter features.
Create table adapter
| 
					 1 2 3 4 5  | 
						  <strong>var</strong>     oAdapt: IFDDAptTableAdapter;   <strong>begin</strong>     <em>// create table adapter</em>     FDCreateInterface(IFDDAptTableAdapter, oAdapt);  | 
					
Selecting data
| 
					 1 2 3 4 5 6 7  | 
						  <strong>with</strong> oAdapt <strong>do</strong> <strong>begin</strong>     FConnIntf.CreateCommand(oComm);     SelectCommand := oComm;     SelectCommand.Prepare('select * from {id FDQA_map1}');     Define;     Fetch;   <em>//...</em>  | 
					
Redirect records
Redirect all record inserts into FDQA_map2 table instead FDQA_map1:
| 
					 1 2 3  | 
						  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:
| 
					 1 2 3  | 
						    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:
| 
					 1 2 3  | 
						  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
| 
					 1 2  | 
						  <strong>for</strong> i := 0 <strong>to</strong> 4 <strong>do</strong>       DatSTable.Rows.Add([i, 'string' + IntToStr(i)]);  | 
					
Post changes to RDBMS
| 
					 1  | 
						  Update;  | 
					
For more details and links to other posts, you can refer to the link below:
http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.DAptLayerCommands_Sample
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition






