EMS.FireDACResource Sample
Contents
This sample is a server-client EMS demo that uses FireDAC components. The sample accesses an SQLite database. The connection parameters are defined in the TFDConnection component. If you experience problems with the connection verify these parameters.
It requires InterBase to be installed on the machine or to connect to a remote server. Make sure that the server is running before you run the example. InterBase is used to store the information about the server connections. You can use the RAD Server Console to display the statistics.
Location
You can find the FireDACResource sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to either:
- Object Pascal\DataBase\EMS\FireDACResource
- CPP\Database\EMS\FireDACResource
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
This sample demonstrates how to use an EMS package to extend the EMS Server to connect to an SQLite database using FireDAC components.
The first part consists of creating an EMS Package with a TDataModule where the FireDAC components are placed. It uses the TFDConnection component to establish the connection to the SQLite database. Once you run the package, the resource is registered on the EMS server and can be accessed by a client application using REST.
The FireDAC client needs a TEMSFireDACClient and a TEMSProvider to connect to the EMS Server and to retrieve the JSON data.
How to Use the Sample
Run the EMS Package
When you run the SampleEMSFireDACResourcePackage project, the EMSDevServer starts automatically. If the configuration file is missing, a wizard launches.
- Navigate to the location given above and open:
- Delphi: SampleEMSFireDACResourcePackage.dpk
- C++: SampleEMSFireDACResourcePackageCpp.cbproj
- Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
- The EMS Development Server opens. If it is the first time you are using EMS on the machine, you need to run the configuration wizard in order to create the EMS server configuration file.
- When the Confirm dialog opens, click Yes.
- Leave all the parameters by default and go through the different windows clicking Next.
- Click Finish to close the wizard.
- An Information window appears. Click OK.
- The server starts automatically. Minimize it.
Run the FireDAC Client Application
The client expects the EMSDevServer to be running at localhost:8080. If you are running the server at a different address, modify the properties of the TEMSProvider component.
- On the Project Manager, right-click on ProjectGroup1.
- Click Add Existing Project....
- Navigate to:
- Delphi: Start | Programs | Embarcadero RAD Studio Athens | Samples\Object Pascal\DataBase\EMS\FireDACResource\SampleEMSFireDACClient.dproj
- C++: Start | Programs | Embarcadero RAD Studio Athens | Samples\CPP\Database\EMS\FireDACResource\SampleEMSFireDACClientCpp.cbproj
- Press F9 or choose Run > Run.
- Click Get Tables to load the data from the SQLite database.
- Do some changes on the records and click Post Updates to commit the changes.
Implementation
EMS Package
The Resource Module has code to register a REST API resource. The resource is called "test". The resource defines a GET and a POST method.
Once you run the package and have the EMS server running, as a test, you can invoke the GET method using the browser http://localhost:8080/test
.
FireDAC Client
The client application has a TEMSProvider component. This component identifies the address of the RAD Server Engine (EMS Server) (<code>http://localhost:8080</code>).
The client application also has a TEMSFireDACClient . This component identifies the name of a resource (test).
- EMSFireDACClient1.GetData accesses
http://localhost:8080/test
with HTTP GET. JSON is returned by the GET.
- EMSFireDACClient1.PostUpdates accesses
http://localhost:8080/test
with HTTP POST. JSON is sent with the POST.
The TFDSchemaAdapter is able to load from JSON and save to JSON.
On the client side, TFDSchemaAdapter is responsible for loading JSON into TFDMemTable, and for saving delta packages into JSON.
On the server side, TFDSchemaAdapter is responsible for saving query results to JSON and for loading a JSON delta and applying inserts, updates, and deletes to the database.
Uses
- FireDAC.Comp.Client.TFDConnection
- FireDAC.Phys.SQLite.TFDPhysSQLiteDriverLink
- FireDAC.Comp.UI.TFDGUIxWaitCursor
- FireDAC.Comp.Client.TFDSchemaAdapter
- FireDAC.Comp.Client.TFDQuery
- Data.DB.TDataSource
- FireDAC.Comp.Client.TFDMemTable
- FireDAC.Comp.Client.TFDTableAdapter
- Vcl.ActnList.TActionList
- REST.Backend.EMSProvider.TEMSProvider
- REST.Backend.EMSFireDAC.TEMSFireDACClient