FireDAC.InterBase Arrays Sample
This sample demonstrates how to use the TFDParam.ArrayType property to send arrays to a database server using FireDAC.
Contents
Location
You can find the Arrays project at:
- Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\DBMS Specific\InterBase\Arrays
- Subversion Repository:
Description
The Arrays sample shows you how to use the TFDParam.ArrayType property to send arrays to a database server. To this end the ArrayType property is set to atTable
.
- Note: This demo establishes a connection to the Interbase localhost server by default, using the
SYSDBA
user. You can change these parameters to connect to a different InterBase server using a valid user name and password.
How to Use the Sample
- Navigate to the location given above and open
IBArrays.dproj
. - Press F9 or choose Run > Run.
- Use the parameters by default to connect to the local InterBase server with the default
SYSDBA
user. - Press the IBwrite and IBread buttons to send/recive arrays to/from a databse server.
Files
File in Delphi | Contains |
---|---|
|
The project itself. |
|
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
IB_Demo
.
- A TFDQuery object named FDQuery1. This component implements a dataset capable of executing SQL queries. The sample sets its Connection property to
FDConnection1
in order to specify the FireDAC connection object.
- 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
.
- The DataSet property of DataSource is set to
When you run the application, you see a grid and two buttons labeled as: IBread and IBwrite. Both buttons have an OnClick event to do the following:
- IBwrite:
- Press this button to send arrays to a database server. When you press this button, the sample takes the following steps:
- Uses the Text property of SQL to set the SQL command that FDQuery1 will execute.
- Sets the TFDParam.DataTypeName to specify the field name as
<TableName>.<FieldName>
. - Sets the TFDParam.ArrayType property to
atTable
.- Note: If you set it to
atArray
it does not work.
- Note: If you set it to
- Sets the array size with the TFDParam.ArraySize property.
- Sets the arrays using the AsStrings property:
- Sends the arrays to the database server by executing the SQL command specified in the first step.
- IBread:
- Uses the Open method to read the arrays from the database server. The sample displays the arrays on the grid.
Uses
- FireDAC.Comp.Client.TFDConnection
- FireDAC.Comp.Client.TFDQuery
- Data.DB.TDataSource
- Vcl.DBGrids.TDBGrid
- FMX.StdCtrls.TButton