FireDAC.TFDLocalSQL InMemDB Sample
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.
You can find the In-memory DB sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
- Object Pascal\DataBase\FireDAC\Samples\Comp Layer\TFDLocalSQL\InMemDB.
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
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.
How to Use the Sample
- Navigate to the location given above and open:
- Delphi: InMemDB.dproj
- Press F9 or choose Run > Run.
- Move to the different tabs and navigate through the records with the TDBNavigators.
The sample is divided on tabs. The TFDMemTables are defined and filled with data by code.
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.
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.
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.