Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Learn How To Use FireDAC To Work With A Firebird Database In Delphi

The Firebird getting started sample shows how to use FireDAC with Firebird databases. This sample allows the user to do:

Location

You can find the Firebird sample project at:

How to Use the Sample

  1. Navigate to the location given above and open GettingStarted.dproj.
  2. Press F9 or choose Run > Run.

Files

File in DelphiContains
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-672a2e5fc89a4206484359/]

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:

[crayon-672a2e5fc89ac735569221/]

In addition, the qryProducts.SQL property is set up as follows:

[crayon-672a2e5fc89af317585071/]

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-672a2e5fc89b0405561864/]

Committing the transaction:

[crayon-672a2e5fc89b2581190102/]

Rolling back the transaction:

[crayon-672a2e5fc89b3050555591/]

Executing queries

Simple queries execution is demonstrated via ExecSQL method of TFDConnection.

Updating records:

[crayon-672a2e5fc89b5544600681/]

Getting a scalar value from the database:

[crayon-672a2e5fc89b6479709475/]

Service work with Firebird database

The sample performs the following management of databases:

All the management of databases is done using the following components TFDIBBackupTFDIBRestoreTFDIBRestoreTFDIBSecurityTFDIBTrace and TFDIBValidate.

This demo demonstrates work with TFDIBBackupTFDIBRestoreTFDIBSecurity and TFDIBValidate components:

[crayon-672a2e5fc89b7599080470/]

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

Exit mobile version