In C++Builder 10.2.2, Embarcadero has added a new component to the FireDAC BatchMove architecture, to support generating JSON data from database tables, in an easy and flexible way.
RAD Studio (Delphi and C++ Builder) has offered support for JSON in different ways and for a long time. From the JSON system unit (originally part of the DBX space) to the DataSnap table mapping (also via DBX) and to FireDAC tables to JSON mapping, there are many ways to interact with JSON data structures. As an enhancement, in the 10.2.2 release, we now added the capability to map a dataset to a custom JSON structure — the FireDAC JSON support produces a FireDAC specific structure,metadataa data, and record status information.
Important to note is the C++ Builder 10.2.2 Enterprise and above edition includes a RAD Server free deployment license ($5000 value) to allow you to use RAD Server as your backend, and consider using Sencha ExtJS for your Web Clients!
A RAD Server package Application
1. Create a File | New Items| C++ Builder Projects | EMS Package
2. Select “Create a package with resource”
3. Resource name = employee File type = select “Data Module”
4. Select only the GET Endpoint. For this example we will only show how to implement the GET endpoint to return data from a database table:
5. Click Finish.
6. On the generated Data Module form, add these 5 components from the tool palette:
FDConnection – to establish a connection to a DBMS and to manage associated datasets.
FDQuery – to execute SQL queries, browse the result sets, and edit the result set records.
FDBatchMove – to move data between text files and tables using datasets.
FDBAtchMoveDataSetReader – to define the source dataset from which to load information using TFDBatchMove.
FDBAtchMoveJSONWriter – is the base abstract class for all batch move JSON reader and JSON writer classes.
The above code is using the JSONWriter property. With this code the data is written directly to the HTML response, reducing the work and the memory consumption!
Start your C++ Builder RAD Server:
And call your REST Endpoint for the GET: http://localhost:8080/employee.
You will get this JSON Array returned for the InterBase Employee table data:
[DownloadButton Product=’RAD’ Caption=’Click here to get started with a Free Trial of RAD Studio ‘]
Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy. Start Free TrialUpgrade Today
Embarcadero’s users understand the scalability and stability of C++ and Delphi programming, and depend on the decades of innovation those languages bring to development. Ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero’s award-winning products over the past 30 years. Icons by Icons8.com.