The Firebird getting started sample shows how to use FireDAC with Firebird databases. This sample allows the user to do:
- Temporary connection definition at run time.
- Master-details relationship between datasets using TFDQuery.
- Transactions handling with TFDTransaction.
- Management of Firebird database such as: managing users, creating database backup/restoring database from backup and validating a database.
Table of Contents
Location
You can find the Firebird sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\Getting Started\Firebird
- Subversion Repository:
- 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
GettingStarted.dproj
. - Press F9 or choose Run > Run.
Files
File in Delphi | Contains |
---|---|
GettingStarted.dproj GettingStarted.dpr | The project itself. |
fGettingStarted.pas fGettingStarted.fmx | The main form. |
Implementation
The sample implements the following features.
Creating temporary connection definition
The simplest way to configure connection to Firebird database at run time is to build a temporary connection definition:
[crayon-6768e773d3839659282502/]In the sample the temporary definition is created when the Connect button is clicked.
Master Details
In this sample, the Categories and Products tables have one-to-many relation by CategoryID
field. The qryCategories.SQL property is set up as follows:
In addition, the qryProducts.SQL property is set up as follows:
[crayon-6768e773d3847780144882/]Finally, the qryProducts.MasterSource property is set to dsCategories
, while the MasterFields property is set to CategoryID
. This creates a master-details relationship between the datasets.
Transaction handling
Handling of InterBase transactions is demonstrated using TFDTransaction + TFDConnection components. Both are configured as follows: trnMain.Connection property is set to dbMain connection
and dbMain.Transaction property is set to trnMain
.
Starting a transaction:
[crayon-6768e773d384b247677064/]Committing the transaction:
[crayon-6768e773d384d526578690/]Rolling back the transaction:
[crayon-6768e773d384f864559084/]Executing queries
Simple queries execution is demonstrated via ExecSQL method of TFDConnection.
Updating records:
[crayon-6768e773d3850387170031/]Getting a scalar value from the database:
[crayon-6768e773d3852454351336/]Service work with Firebird database
The sample performs the following management of databases:
- Security management.
- Database maintenance.
- Tracing server activity
All the management of databases is done using the following components TFDIBBackup, TFDIBRestore, TFDIBRestore, TFDIBSecurity, TFDIBTrace and TFDIBValidate.
This demo demonstrates work with TFDIBBackup, TFDIBRestore, TFDIBSecurity and TFDIBValidate components:
[crayon-6768e773d3854483522676/]In the link below you can find more information about this sample and links to other samples:
http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.Firebird_Sample