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.
You can find the FireDACResource sample project at:
- Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to either:
- Object Pascal\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.
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 Alexandria | Samples\Object Pascal\DataBase\EMS\FireDACResource\SampleEMSFireDACClient.dproj
- C++: Start | Programs | Embarcadero RAD Studio Alexandria | 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.
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
The client application also has a TEMSFireDACClient . This component identifies the name of a resource (test).
- EMSFireDACClient1.GetData accesses
http://localhost:8080/testwith HTTP GET. JSON is returned by the GET.
- EMSFireDACClient1.PostUpdates accesses
http://localhost:8080/testwith HTTP POST. JSON is sent with the POST.
The TFDSchemaAdapter is able to load from JSON and save to 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.