Re-introduction to FireDAC data access (5)
Embarcadero Team Japan - 07/Jul/2020
Embarcadero Team Japan - 07/Jul/2020
[SHOWTOGROUPS=4,20,22]
Utilization of in-memory dataset
In this blog, we will explain the basic usage of FireDAC for those who have used Delphi / C++Builder to some extent.
The fifth theme
An in-memory dataset is a database-independent dataset that is expanded in memory. The FireDAC dataset was introduced in Part 3 . Datasets such as TFDQuery and TFDTable were supposed to handle the data associated with the database information connected by TFDConnection, but in-memory datasets are held in memory without depending on the database.
In-memory datasets can be used to efficiently implement cached data retention and temporary data retention that does not require persistence. This is one of the powerful features of FireDAC.
In this article, I will explain the outline of in-memory datasets and the points to be noted when migrating a project that uses TClientDataSet with an older version of Delphi / C++Builder.
In-memory dataset overview
The in-memory data set is a data set that is expanded on the memory of the client PC and is provided as a component called "TFDMemTable" in FireDAC, and has the following features.
Retain the data in the memory
data of TFDMemTable is capable of high-speed data operation because it can all handle on the memory. However, since all the data is retained in memory, it will be lost when closed, unlike a normal data set. In addition, TFDMemTable has an import/export function for XML/BIN/JSON format files, and data can be stored and read in these formats.
Database-independent
datasets such as TFDQuery and TFDTable always required a database connection, but TFDMemTable does not require a database connection. It can be treated as a local dataset that is database independent.
Similar functionality to TClientDataSet
Delphi/C++Builder provided an in-memory dataset named "TClientDataSet" from a very old version. TFDMemTable has similar functionality to this TClientDataSet, so it can be used in a similar way.
The advantage of using TFDMemTable is that it behaves like a local DB.
Depending on your business, you may not be able to interrupt the operation of inputting/outputting data to/from the system even if you cannot connect to the network. In such a case, it is necessary to prepare a mechanism that allows the operation to continue in some way.
For example, if you get the necessary data from a remote data center with a network connection, you can temporarily store it in a local dataset (TFDMemTable) for caching purposes. Even if the network connection is lost, if you have a mechanism that synchronizes with the data on the server later, you will be able to carry out the work without stopping the operation.
Since FireDAC also supports data access to local DB such as SQLite and IBLite, there is an option to cache to local DB instead of local dataset.
While not suitable for systems that require real-time data synchronization, leveraging local datasets can reduce network traffic by avoiding unnecessary remote DB access. In addition, since the data is manipulated on the memory of the client, it has the advantage of improving the responsiveness of processing.
Precautions when using TClientDataSet in an older version project
Next, let's explain the points to be noted when migrating an existing project that uses TClientDataSet in an older version of Delphi/C++Builder.
For example, when replacing a DB component such as BDE or dbExpress with FireDAC, it has been reported that the behavior may be different from the conventional behavior in the case of continuing to use the combination of FireDAC data set and TClientDataSet-TDataSetProvider.
When migrating to FireDAC, you should use the alternative, TFDMemTable, built on the same new architecture, rather than the old architecture, TClientDataSet and TDataSetProvider.
Below are some guidelines for replacing FireDAC components.
FireDAC doesn't require
TClientDataSet and TDataSetProvider DB components like dbGO and dbExpress only support unidirectional datasets, so I had to use TCientDataSet and TDataSetProvider together to display the data in a grid control like TDBGrid. .. FireDAC datasets are not needed as they can be displayed in TDBGrid without using TClientDataSet and TDataSetProvider. This is also the case when using BDE.
Use of
TFDMemTable As TFDMemTable has the similar function to TClientDataSet as described above, it can be used like TClientDataSet. If you want to use it for local data set, please replace it with TFDMemTable.
[/SHOWTOGROUPS]
Utilization of in-memory dataset
In this blog, we will explain the basic usage of FireDAC for those who have used Delphi / C++Builder to some extent.
The fifth theme
- In-memory dataset overview
- Precautions when using TClientDataSet in an older version project
- Application creation exercise for migrating TClientDataSet data to TFDMemTable
An in-memory dataset is a database-independent dataset that is expanded in memory. The FireDAC dataset was introduced in Part 3 . Datasets such as TFDQuery and TFDTable were supposed to handle the data associated with the database information connected by TFDConnection, but in-memory datasets are held in memory without depending on the database.
In-memory datasets can be used to efficiently implement cached data retention and temporary data retention that does not require persistence. This is one of the powerful features of FireDAC.
In this article, I will explain the outline of in-memory datasets and the points to be noted when migrating a project that uses TClientDataSet with an older version of Delphi / C++Builder.
In-memory dataset overview
The in-memory data set is a data set that is expanded on the memory of the client PC and is provided as a component called "TFDMemTable" in FireDAC, and has the following features.
Retain the data in the memory
data of TFDMemTable is capable of high-speed data operation because it can all handle on the memory. However, since all the data is retained in memory, it will be lost when closed, unlike a normal data set. In addition, TFDMemTable has an import/export function for XML/BIN/JSON format files, and data can be stored and read in these formats.
Database-independent
datasets such as TFDQuery and TFDTable always required a database connection, but TFDMemTable does not require a database connection. It can be treated as a local dataset that is database independent.
Similar functionality to TClientDataSet
Delphi/C++Builder provided an in-memory dataset named "TClientDataSet" from a very old version. TFDMemTable has similar functionality to this TClientDataSet, so it can be used in a similar way.
The advantage of using TFDMemTable is that it behaves like a local DB.
Depending on your business, you may not be able to interrupt the operation of inputting/outputting data to/from the system even if you cannot connect to the network. In such a case, it is necessary to prepare a mechanism that allows the operation to continue in some way.
For example, if you get the necessary data from a remote data center with a network connection, you can temporarily store it in a local dataset (TFDMemTable) for caching purposes. Even if the network connection is lost, if you have a mechanism that synchronizes with the data on the server later, you will be able to carry out the work without stopping the operation.
Since FireDAC also supports data access to local DB such as SQLite and IBLite, there is an option to cache to local DB instead of local dataset.
While not suitable for systems that require real-time data synchronization, leveraging local datasets can reduce network traffic by avoiding unnecessary remote DB access. In addition, since the data is manipulated on the memory of the client, it has the advantage of improving the responsiveness of processing.
Precautions when using TClientDataSet in an older version project
Next, let's explain the points to be noted when migrating an existing project that uses TClientDataSet in an older version of Delphi/C++Builder.
For example, when replacing a DB component such as BDE or dbExpress with FireDAC, it has been reported that the behavior may be different from the conventional behavior in the case of continuing to use the combination of FireDAC data set and TClientDataSet-TDataSetProvider.
When migrating to FireDAC, you should use the alternative, TFDMemTable, built on the same new architecture, rather than the old architecture, TClientDataSet and TDataSetProvider.
Below are some guidelines for replacing FireDAC components.
FireDAC doesn't require
TClientDataSet and TDataSetProvider DB components like dbGO and dbExpress only support unidirectional datasets, so I had to use TCientDataSet and TDataSetProvider together to display the data in a grid control like TDBGrid. .. FireDAC datasets are not needed as they can be displayed in TDBGrid without using TClientDataSet and TDataSetProvider. This is also the case when using BDE.
Use of
TFDMemTable As TFDMemTable has the similar function to TClientDataSet as described above, it can be used like TClientDataSet. If you want to use it for local data set, please replace it with TFDMemTable.
[/SHOWTOGROUPS]