FireDAC.VSE Demo Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample shows the use of a FireDAC database connection and how to populate a database with data using an XML document.

Location

You can find the Project1 project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\AddOn\VSE\Demo
  • 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 application creates a table (test_vs) and inserts data from an XML document using a FireDAC database connection.

Note: The connection to the database does not require authentication.

How to Use the Sample

  1. Navigate to the location given above and open Project1.dproj.
  2. Press F9 or choose Run > Run.
  3. Click the Button1 button and the grid will be populated with data.
  4. Click the Button1 button again to deactivate the TFDQuery component and stop showing the data.

Files

File Contains

Demo\Project1.dproj

Contains the project itself.

Demo\Unit1.dfm

Contains the code of the main form.

Demo\Unit1.pas

Contains the main form and the main code.

FireDAC.Comp.VSE.pas

Contains the code for the VSE class used for parsing the XML document.

FireDAC.Comp.VSEXML.pas

Contains the code for the VSEXML class used for XPath.

Implementation

  • When the TForm is created, a TFDConnection executes a DROP query against the test_vs table, creates the table, and populates it with data from an XML document.
  • The XML document is written at the beginning of the implementation part in the project.
 <Transaction>
   <Request>
      <OrderNumber>123456</OrderNumber>
      <ShippingMethod>123456</ShippingMethod>
   </Request>
   <Response>
      <StatusCode>200</StatusCode>
      <StatusMesg>Order accepted</StatusMesg>
      <RefNumber>S0123456</RefNumber>
   </Response>
 </Transaction>
  • The TFDQuery executes a SELECT query against the test_vs table and displays the results in a TDBGrid.
  • The project uses procedures which are found in the FireDAC.Comp.VSE.pas and FireDAC.Comp.VSEXML.pas units to interact with the XML document.
    • In the TForm creation procedure, a TFDVSEXMLManager (the FVS code variable) is instantiated and two TFDVSESchema (the oSch code variable) are created.
    • The two TFDVSESchema variables have the following TFDVSECMLFieldDefs fields: Name, DataType, Size, and XPathExpression. One TFDVSESchema is used for Request and the other one for Response. They are used for parsing the XML document.
    • The FVS Manager also adds a TFDVSESessions to allow the TFDQuery to execute the query.

Uses

Tutorials