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!
Embarcadero’s first step in simplifying the use of Delphi and C++ Builder RAD Server as a backend for Sencha EXTJS JavaScript applications is offering a better way to produce the JSON data from a database table.
While we have built this support for the scenario of using RAD Server, FireDAC, and ExtJS, the same component and technology can be used for any web service architecture written in Delphi and C++Builder (even pure and simple WebBroker), any dataset other than FireDAC, and any JavaScript client. It is a completely open and a fairly flexible solution. But it certainly works great for our specific scenario of RAD Server backend and Sencha ExtJS Web Client!
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.
With this configuration in place, all you need to do to produce the JSON is connect the output to the JSON writer and execute the batch move operation!
C++ Builder implementation
So far we added to an EMS package an “employee” resource, and we can implement its Get operation with the following C++ stream-based code:
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:
This is great that C++ Builder 10.2.2 added this new DataSet Mapping to JSON for JavaScript client support! And this is only a first initial step of the support that Embarcadero RAD Studio, C++ Builder, and Delphi is planning to simplify the use of C++ Builder and RAD Server as the backend for JavaScript and ExtJS applications. More support will be made available soon. Stay tuned!
[DownloadButton Product=’RAD’ Caption=’Click here to get started with a Free Trial of RAD Studio ‘]
Register for Python GUI Apps Con 2023 today!
Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy. Start Free TrialUpgrade Today
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.