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

Easily Establish an InterBase Temporary Connection Definition at Run-Time With Delphi

The InterBase getting started sample shows how to create a temporary connection definition at run-time with InterBase database. This sample allows the user to do:

Location

You can find the InterBase 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.
  3. In the Database field, open the following database: C:ProgramDataEmbarcaderoInterBasegds_dbexamplesdatabaseemployee.gdb.

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 InterBase database at run-time is to build a temporary connection definition:

[crayon-676c635b19d60221620694/]

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-676c635b19d68125453326/]

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

[crayon-676c635b19d6a275061301/]

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

The 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-676c635b19d6b922964545/]

Committing the transaction:

[crayon-676c635b19d6c467036893/]

Rolling back the transaction:

[crayon-676c635b19d6d012801132/]

Executing queries

Simple queries execution is demonstrated via ExecSQL method of TFDConnection.

Updating records:

[crayon-676c635b19d6e177447554/]

Getting a scalar value from the database:

[crayon-676c635b19d6f952567229/]

Management of InterBase database

The sample application provides the following features:

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

Please refer to the link below for more information and external links about the sample:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.InterBase_Sample

Head over and check out the full source code for the FireDAC InterBase sample for Delphi on GitHub.

 

 
Exit mobile version