3.11. Conclusion
FireDac™ is a standard set of data-access and data-aware visual components for developing with various database systems, including Firebird, starting from Delphi™ XE3. FireDac™ ships with the higher-end versions of Delphi. Many independent sets of data access and data-aware visual components are available for working with Firebird, some commercial, others distributed under a variety of licences, including open source and freeware. They include FibPlus, IBObjects, UIB, UniDAC, IBDac, Interbase Express (IBX) and more. The principles for developing Firebird applications in Delphi™ are the same, regardless of the components you choose.
All queries to a database are executed within a transaction. To guarantee that applications will work correctly and efficiently with Firebird databases, it is advisable to manage transactions manually, by explicit calls to the StartTransaction
, Commit
and Rollback
methods of the TFDTransaction
component. Transactions should be as short as possible and you can use as many as the logic of your application requires.
The recommended configuration for a long-running, read-only transaction to view datasets is to use READ COMMITTED
isolation with REC_VERSION
for conflict resolution. An application can run many datasets in one such transaction or one for each dataset, according to the requirements of the design.
To avoid holding an uncommitted transaction during an editing session, either use visual components that are not data-aware or use the CachedUpdates
mode. With CachedUpdates
you can restrict writes to short bursts of activity, keeping the read/write transaction active only for as long as it takes to post the most recent changes to the database.
The TFDUpdateSQL
component is necessary for editing most datasets. Update queries are governed by its InsertSQL
, ModifySQL
, DeleteSQL
and FetchRowSQL
properties. The queries for those properties can be generated automatically by a wizard but manual corrections or adjustments are often required.
Acquiring values for auto-incrementing primary keys can be handled in one of two ways:
Getting the value from the generator beforehand by specifying the
UpdateOptions.GeneratorName
andUpdateOptions.AutoIncFields
properties for theTFDQuery
component. This method cannot be used for auto-incrementing fields of theIDENTITY
type that was introduced in Firebird 3.Getting the value by adding a
RETURNING
clause to theInsertSQL
query. For this method you need to specifyRequired=False
andReadOnly=True
for the field because the value is not entered directly.
It is convenient and sometimes necessary to implement more complex business logic with stored procedures. Using the TFDCommand
component to execute stored procedures that do not return data reduces resource consumption.