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 | Appmethod 1.16 | Samples and then navigate to:
- Object Pascal\DataBase\FireDAC\Samples\Comp Layer\TFDLocalSQL\InMemDB.
- Subversion Repository for Object Pascal: http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE8//Object%20Pascal/Database/FireDAC/Samples/Comp%20Layer/TFDLocalSQL/InMemDB.
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:
- Object Pascal: 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.