Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDelphiRAD Studio

Learn How To Use Range Types On A PostgreSQL Database In Windows Using FireDAC With Delphi

 FireDAC represents a range type column as a ftADT field with 3 subfields:

  • lbound – lower range bound.
  • hbound – upper range bound.
  • flags – range flags.

Note: Columns of range type are read-only. This sample updates them using SQL commands.

To get range column attributes, this sample uses the following code:

Location

You can find the Ranges project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object PascalDatabaseFireDACSamplesDBMS SpecificPostgreSQLRanges
  • 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

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

Files

File in DelphiContains
PGRanges.dproj
PGRanges.dpr
The project itself.
fMain.pas
fMain.fmx
The main form.

Implementation

Before running the sample, the main components are configured at design time using the Object Inspector as follows:

  • TFDConnection object named FDConnection1. This is the FireDAC connection object that the sample uses to connect to a DBMS. The sample sets the ConnectionDefName property to PG_Demo.

Note: You can change the ConnectionDefName property to connect to a different PostgreSQL server using a valid user name and password.

  • TFDQuery object named FDQuery1. This component implements a dataset capable of executing SQL queries. The sample sets:
    • The Connection property to FDConnection1 in order to specify the FireDAC connection object.
    • The SQL property with the following SQL SELECT statements that define different integer ranges:

Notes:

  • The parentheses or brackets of the third argument indicate whether the lower and upper bounds are exclusive or inclusive. “[” represents an inclusive lower bound while “(” represents an exclusive lower bound. The same way, “]” represents an inclusive upper bound while “)” represents an exclusive upper bound.
  • If you omit the lower bound of a range, it means that all points less than the upper bound are included in the range. Likewise, if you omit the upper bound of the range, then all points greater than the lower bound are included in the range. If both lower and upper bounds are omitted, all values of the element type are considered to be in the range.
  • TDataSource object named DataSource1. 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 sample sets the following properties:
  • The DataSet property of DataSource is set to FDQuery1.
  • The DataSource property of DBGrid1 is set to DataSource1.

When you run the application, you see:

  • TDBGrid that is used to display the different data ranges defined on the SQL command.
  • Three TDBEdit components that are used to display the lbound,lbound and flags fields of the range type.
  • Two TLabel components that are used to display the type of the range bounds.

You can check the link below for more details about this sample:

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

Head over and check out the full source code for the PostgreSQL Ranges sample for Windows apps on GitHub or in your RAD Studio IDE samples section.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES