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:
[crayon-6741b286eaae4246855291/]Table of Contents
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
- Navigate to the location given above and open
PGRanges.dproj
. - Press F9 or choose Run > Run.
Files
File in Delphi | Contains |
---|---|
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:
- A 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.
- A 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:
- The Connection property to
[crayon-6741b286eaaeb182742511/]
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.
- A 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:
- A 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