The OnUpdateRecord sample shows you how to cache the user changes when using read-only dataset and then, how to apply updates on behalf of queries that cannot post updates directly. To this end, the sample uses the OnUpdateRecord event of TFDQuery and the TFDUpdateSQL object.
Table of Contents
Location
You can find the CentralizedCachedUpdates sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object PascalDatabaseFireDACSamplesComp LayerTFDQueryCachedUpdatesOnUpdateRecord
- Subversion Repositories:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
How to Use the Sample
- Navigate to the location given above and open
Qry_CachedUpdates.dproj
. - Press F9 or choose Run > Run.
Files
File in Delphi | Contains |
---|---|
Qry_CachedUpdates.dproj Qry_CachedUpdates.dpr | The project itself. |
fCachedUpdates.pas fCachedUpdates.fmx | The main form. |
Implementation
Before running the sample, the main components are configured at design time using the Object Inspector as follows:
- A TFDQuery object named qryProducts. This component is used to implement a dataset capable of executing SQL queries. The following setup is needed:
- The Connection property is configured to specify the FireDAC connection object that is used to connect to a DBMS.
- The SQL property of qryProducts is set to:
Note: In the RDBMS it has one-to-many relation between Categories and Products tables.
- The CachedUpdates property is set to
True
. It means that the dataset will log data changes without immediately applying them to the database.
- Two TFDUpdateSQL objects named usProducts and usCategories. Both objects are used to provide SQL statements for posting updates from TFDQuery. To this end, the following setup is needed:
- The ModifySQL property of usProducts is set to:
- The ModifySQL property of usCategories is set to:
- A TDataSource objects named dsProducts. This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the dataset and the grid where the dataset is displayed. To this end, the following properties are set:
- The DataSet property of dsProducts is set to
qryProducts
. - The DataSource property of DBGrid1 is set to
dsProducts
.
For more details, please follow the link to the original post:
http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDQuery.OnUpdateRecord_Sample
Head over and check out the OnUpdateRecord sample source code for Delphi over on GitHub.