Migrating from DBGo (ADO) to FireDAC


In my last blog I explained how to migrate from DBExpress to FireDAC. Here I will show you how to migrate a client-server application using ADO data access components, such as TADOConnection, TADOQueryTADOTable, to the FireDAC. It shows the basic principles of replacing the common components, properties and code, preserving the developers working time and avoiding the common migration pitfalls.

So lets start in steps.

1. Units Changed
We need to replace used ADO units to FireDAC units.
Find 
ADODB
Replace
          FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Phys, FireDAC.Stan.Pool,
FireDAC.Stan.Async, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, FireDAC.Comp.Client, FireDAC.Comp.DataSet

2. ADO components classes compatible with FireDAC
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
TADOConnection
TFDConnection
TADOTable
TFDTable
TADOQuery
TFDQuery
TADOStoredProc
TFDStoredproc
TADOCommand
TFDCommand

3. Other Types classes changed
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
TParams
TFDParams
TBlobStream
TFDBlobStream
TBDEDataSet
TFDRDBMSDataSet

4. TADOConnection -> TFDConnection Properties
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
ConnectionTimeout
Not Supported.
ConnectOptions
Not Supported.
CursorLocation
Not Supported.
DefaultDatabase
Not Supported.
IsolationLevel
Not Supported.
KeepConnection
ResourceOptions.KeepConnection
Provider
DriverName

Note* - OnLogin Event
TFDConnection.OnLogin event is different than TFDConnection.OnLogin. So we should remove Tdatabase event and re-write TFDConnection Event.

5. TADOTable -> TFDTable Properties
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
CommandTimeOut
Not Supported
ConnectionString
Not supported
CursorLoacation
Not supported
CursorType
FetchOptions.CursorKind
ExecuteOptions
Not Supported
EnableBCD
Not supported
LockType
UpdateOptions.LockMode
MarshallOptions
Not supported
MaxRecords
FetchOptions.RecsMax
Readonly
UpdateOptions.Readonly

6. TADOQuery -> TFDQuery Properties
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
CommandTimeOut
Not Supported
ConnectionString
Not supported
CursorLoacation
Not supported
CursorType
FetchOptions.CursorKind
Datasource
MasterSource

Note. Please check MasterFields
ExecuteOptions
Not Supported
EnableBCD
Not supported
LockType
UpdateOptions.LockMode
MarshallOptions
Not supported
MaxRecords
FetchOptions.RecsMax
ParamCheck
ResourceOptions.Paramcreate
Parameters
Params

7. TADOStoredProc -> TFDStoredProc     Properties
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
CommandTimeOut
Not Supported
ConnectionString
Not supported
CursorLoacation
Not supported
CursorType
FetchOptions.CursorKind
Datasource
MasterSource

Note. Please check MasterFields
ExecuteOptions
Not Supported
EnableBCD
Not supported
LockType
UpdateOptions.LockMode
MarshallOptions
Not supported
MaxRecords
FetchOptions.RecsMax
ParamCheck
ResourceOptions.Paramcreate
Parameters
Params
ProcedureName
StoredProcName

8. TADOCommand -> TFDCommand        Properties
Search ADO classes and replace with FireDAC classes

 ADO
 FireDAC
CommandTimeOut
Not Supported
CommandType
CommandKind
ConnectionString
Not supported
ExecuteOptions
Not Supported
ParamCheck
ResourceOptions.Paramcreate
Parameters
Params


9. Sorting
FireDAC components like TFDQuery, TFDTable does not have Sort property. So we have to use IndexFieldNames property for sorting. So where ever we have used Sort for sorting in our project we need to replace with IndexFieldNames like follow.

ADQuery1.IndexFieldNames := 'ORDERID';
or
ADQuery1.IndexFieldNames := 'OrderDate:D;Price'; //D for descending//

10. TBookMark Changes for Dataset components
When we save a bookmark for future use we must use pointer for

var
BookMark : Pointer;
CDS : TClientDataset
……
// Required so your assignment doesn't attempt to free a non-existent bookmark //
 Bookmark := nil;
 TBookmark(Bookmark) := CDS.GetBookmark;

11. Data Property
If we use TFDQuery and ClientDataset together then Data property is mostly used to assign saved data to any other dataset component directly instead of using any loop. Here TFDQuery have also Data property but type is different. Earlier in TADOQuery or other Query component, Data property was OleVariant type which was same type like ClientDataset but now it is IFDDataSetReference. So we cannot just assign directly like.

Clientdataset1.Data := FDQuery.Data; //will result an error //

Above code will compile successfully but will result “Invalid data packet” error at runtime. In this scenario we have to use TDatasetProvider as mediator to transfer data from once dataset to another. We can use DatasetProvider.Data property like follow.

DataSetProvider1.Dataset := FDQuery1;
FdQuery1.Open;
Clientdataset1.data := DatasetProvider1.data;

12. Extra points to check
a. Need to change some numeric fields to TBCDFields when it will show error and set Size=2 when in Database field type is like number(15,2)

b. Check SQL statement for “. If it is like “DBA.Segments” which is wrong then it should be “DBA”.”Segment” or DBA.Segments

Comments

  1. Hola, Mi nombre es Luis, quiere decir que puedo copiar un conjunto de datos a otro sin tener que hacer registro por registro?.

    ReplyDelete

Post a Comment

Popular posts from this blog

ShellExecute in Delphi

How to send Email in Delphi?

Drawing Shapes in Delphi