FireDAC.IFDPhysCommand.FetchTables Sample
This sample demonstrates how to use the Phys Layer command interface of FireDAC to fetch data from a database.
Contents
Location
You can find the FetchTables sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\Phys Layer\IFDPhysCommand\FetchTables
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
The FetchTables sample shows you how to use the Fetch property of the IFDPhysCommand interace. The sample uses the IFDPhysCommand interace to fetch rows from the current command cursor in the DatS table. To this end, the sample creates a command interface to:
- Prepare a
SELECT
command. - Define the structure of the DatS table.
- Open the command interface.
- Fetch the table.
- Print the fetched rows
How to Use the Sample
- Navigate to the location given above and open
FetchTables.dproj
. - Press F9 or choose Run > Run.
- Click on the Use Connection Definition combo box and select an option.
Files
File in Delphi | Contains |
---|---|
|
The project itself. |
|
The main form. |
Implementation
When you run the application, you see the following components that are configured on run time:
- A TComboBox object labeled as Use Connection Definition.
- When you click the Use Connection Definition combo box, the menu shows all the persistent connections defined on the file
C:\Users\Public\Documents\Embarcadero\Studio\FireDAC\FDConnectionDefs.ini
. Select an option in order to define a connection to a database. When the connection is defined, the sample uses the CreateCommand method of IFDPhysConnection to create a command interface. Then, the sample use some methods of this command interface to fetch rows from a table. Finally, the sample displays the fetched data using a TMemo object. - To fetch data from a table, the sample implements the following steps:
- First, the sample uses the Prepare method in ordert to prepare the following SQL
SELECT
command:'select * from {id Shippers}'
. - Secondly, the sample uses the Define method in order to define the structure of the DatS table.
- Thirdly, the sample calls the Open method to open the command interface created by the CreateCommand method of IFDPhysConnection.
- Finally, the sample calls the Fetch method in order to fetch rows from the DatS table.
- First, the sample uses the Prepare method in ordert to prepare the following SQL
- When you click the Use Connection Definition combo box, the menu shows all the persistent connections defined on the file
- A TMemo object named Console.
- The sample uses this object to display the data fetched from the table.