FireDAC.TFDLocalSQL InMemDB Sample

From RAD Studio Code Examples
Jump to: navigation, search

The Local SQL uses TDataSet descendants as query sources. It is based on the SQLite engine and supports most of the SQLite SQL dialect. FireDAC uses the SQLite driver to implement the Local SQL engine.

The sample shows how to use the TFDLocalSQL component to execute SQL commands on in-memory database, represented by several TFDMemTables.

Location

You can find the In-memory DB sample project at:

Description

This sample uses a TFDConnection to connect to the SQLite in-memory database (with empty Database parameter value). The TFDLocalSQL component is for the Local SQL engine. The TFDMemTable components are used to load and show the Brands and Models information.

The Brands and Models TFDMemTables are in-memory tables loaded on the form creation. The FieldDefs is filled on code, so there are no external tables or database. The Active property is set to True to open the dataset. The LocalSQL property is set to FDLocalSQL1 to register the dataset with the Local SQL engine.

TFDLocalSQL serves as a central hub to the Local SQL engine and provides the registered datasets. The Connection property is set to FDConnection1 SQLite connection, which will be used to query the datasets.

The TFDQuery connects to FDConnection1 and executes a query over the TFDLocalSQL connection and shows the result of the SQL query on the TDBGrid.

How to Use the Sample

  1. Navigate to the location given above and open:
    • Delphi: InMemDB.dproj
  2. Press F9 or choose Run > Run.
  3. Move to the different tabs and navigate through the records with the TDBNavigators.

Implementation

The sample is divided on tabs. The TFDMemTables are defined and filled with data by code.

MemTab1

It shows on the TDBGrid the result of the Brands TFDMemTable.

To show the content from the TFDMemTable on the TDBGrid it uses the DataSource1 TDataSource. The DataSet property of the DataSource1 specifies Brands and the TDBGrid has DataSource1 as the DataSource property.

MemTab2

It shows on the TDBGrid the result of the Models TFDMemTable.

To show the content from the TFDMemTable on the TDBGrid it uses the DataSource2 TDataSource. The DataSet property of the DataSource2 specifies Models and the TDBGrid has DataSource2 as the DataSource property.

Query

It shows on the TDBGrid the result on the FDQuery1 TFDQuery: Select * from Brands B left join Models M on B.Code = M.Brand

To show the content from the TFDQuery on the TDBGrid it uses the DataSource3 TDataSource. The DataSet property of the DataSource3 specifies FDQuery1 and the TDBGrid has DataSource3 as the DataSource property.

Uses

See Also

Samples

Personal tools
Assistance