FireDAC.TFDLocalSQL.xDBMS Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use TFDLocalSQL to implement a SQLite-based Local SQL engine for a cross-DBMS query application (queryable datasets from different databases).


You can find the xDBMS sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\Comp Layer\TFDLocalSQL\xDBMS
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


The xDBMS sample shows you how use the TFDLocalSQL class to implement a cross-DBMS query application. To this end, each queryable dataset must be registered with the Local SQL engine using the DataSets collection property.

Note: The Local SQL feature allows executing SQL commands, where the TDataSet descendants are used instead of the database tables.

How to Use the Sample

  1. Navigate to the location given above and open xDBMS.dproj.
  2. Press F9 or choose Run > Run.


File in Delphi Contains


The project itself.


The main form.


To setup Local SQL engine for a cross-DBMS query application, the sample has to perform the following steps:

  • Set up an in-memory SQLite local connection (FDConnection1) as a query source from the Local SQL engine (FDLocalSQL1).
  • Perform a local SQL query (FDQuery1).
  • Connect the datasets (qOrders and qDetails) to the Local SQL engine.

To this end, the sample implement the following steps:

  1. Setup connection and query to "Orders" table in SQLite database and link the dataset to the Local SQL engine. To this end, the following components are needed:
  2. Setup connection and query to "Orders Details" table in MSAccess database and link the dataset to the Local SQL engine. To this end, the sample uses the following components:
  3. Setup SQLite in-memory connection. To this end, the sample sets up the following components:
  4. Execute a SELECT query on above datasets using:
    • A TFDQuery object named FDQuery1.
      • The Connection property is set to FDConnection1.
      • The SQL property set to SELECT QO.*, QD.* FROM qOrders QO LEFT JOIN qDetails QD ON QO.OrderID = QD.OrderID ORDER BY QO.OrderID
Note: All the configuration of these components is done using the Object Inspector at design time.

When you run the application, click on the Open/Close button in order to set the Active property of FDQuery1 to True. It executes the SELECT query on the datasets registered with this Local SQL engine. Then, the records from the registered datasets are displayed on a TDBGrid component.


See Also