TSQLDataDriverEh component
TSQLDataDriverEh component
TSQLDataDriverEh
is a universal DataDriver
that can interact with server using SQL
commands.
TSQLDataDriverEh
have five objects of the TSQLCommandEh
type: SelectCommand
, DeleteCommand
, InsertCommand
, UpdateCommand
, GetrecCommand
.
Each object holds SQL
expressions and parameters to execute command to get table data, delete record, insert record, update record and get one record. To execute commands TSQLDataDriverEh
calls global event - DefaultSQLDataDriverResolver.OnExecuteCommand
.
You should write this event to execute SQL expressions on the server and, if need, return DataSet
to read data. When TSQLDataDriverEh
is used as provider of data, it takes records from DataSet created in DefaultSQLDataDriverResolver.OnExecuteCommand
event and writes them in TMemTableEh
. On the measure of the requirement it takes given current record, writes them in TMemTableEh
and goes over to following record.
When TSQLDataDriverEh
is used as handler of changes, it takes a changed record from TMemTableEh
, and call DefaultSQLDataDriverResolver.OnExecuteCommand
event sending DeleteCommand
, InsertCommand
or UpdateCommand
as a parameter.
Using TSQLDataDriverEh
it is possible change a type of the access to data. Suffice it to rewrite global event - DefaultSQLDataDriverResolver.OnExecuteCommand
.
TSQLDataDriverEh
has a SpecParams
property of TStrings
type. You may use it to write the special values, which you can use in the DefaultSQLDataDriverResolver.OnExecuteCommand
event. This event also is used by TServerSpecOperationsEh
object when DefaultSQLDataDriverResolver.ServerSpecOperations
property is assigned. List of special values depends of the type of TServerSpecOperationsEh
object and values is filled similarly of description in the "Characteristic TXXXDataDriverEh.SpecParams" section.
DefaultSQLDataDriverResolver.ServerSpecOperations
property has a TServerSpecOperationsEh
type. This object is intended to process the special operations before or after ExecuteCommand
procedure is performed. TServerSpecOperationsEh
is a base class for classesTOracleSpecOperationsEh
, TMSSQLSpecOperationsEh
, TInterbaseSpecOperationsEh
, TInfromixSpecOperationsEh
, TDB2SpecOperationsEh
, TSybaseSpecOperationsEh
and TMSAccessSpecOperationsEh
.
Each Of these objects can process a SpecParams
property in particular to get values of the autoincrement fields that is generated by the server.
On the name of the class it is possible to define a type of the server, for which class is intended.
For full functioning of TSQLDataDriverEh
it is necessary to write DefaultSQLDataDriverResolver.OnExecuteCommand
event to execute queries on the server and assign DefaultSQLDataDriverResolver.ServerSpecOperations
property by the object that inherited from TServerSpecOperationsEh
class. Assigning a ServerSpecOperations
property makes sense, if you execute operations of the insertion in tables that have autoincrement field (or sequence objects).
The typical code to adjust working of TSQLDataDriverEh
can be look as follows:
// Below code adjusts working of TSQLDataDriverEh components in the whole Application to access
// InderBase server via BDE Engine
uses … DataDriverEh, BDEDataDriverEh;
type
TMainForm = class(TMainForm)
Database1: TDatabase;
SQLDataDriverEh: TSQLDataDriverEh;
…
procedure TMainForm.FormCreate(Sender: TObject);
begin
DefaultSQLDataDriverResolver.OnExecuteCommand := OnExecuteSQLCommand;
DefaultSQLDataDriverResolver.ServerSpecOperations := TInterbaseSpecOperationsEh.Create;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
DefaultSQLDataDriverResolver.ServerSpecOperations.Free;
DefaultSQLDataDriverResolver.ServerSpecOperations := Nil;
end;
function TMainForm.OnExecuteSQLCommand(SQLDataDriver: TCustomSQLDataDriverEh;
Command: TCustomSQLCommandEh; var Cursor: TDataSet; var FreeOnEof,
Processed: Boolean): Integer;
begin
Result := DefaultExecuteBDECommandEh(SQLDataDriver, Command,
Cursor, FreeOnEof, Processed, Database1.DatabaseName);
end;
TSQLDataDriverEh
is a base class for TBDEDataDriverEh
, TIBXDataDriverEh
, TDBXDataDriverEh
and TADODataDriverEh
. These objects overwrite ExecuteCommand
procedure and them can execute SQL
expressions on the server and if need returns DataSet to read data. When SQL
commands is called, it creates DataSet with type of corresponding type of the access to data. For TBDEDataDriverEh it is a TQuery, for TIBXDataDriverEh
it is a TIBXQuery
and so on. Furthermore, TBDEDataDriverEh
, TIBXDataDriverEh
, TDBXDataDriverEh
can define TServerSpecOperationsEh
object automatically. For TADODataDriverEh
it is need to assign DefaultSQLDataDriverResolver
. ServerSpecOperations
because ADO technology does not allow to define a type of the server.
TSQLDataDriverEh have the next events: OnExecuteCommand
write this event to execute SQL expression. You can call TCustomSQLDataDriverEh.DefaultExecuteCommand
method to process this event by default. By default TCustomSQLDataDriverEh.DefaultExecuteCommand
calls DefaultSQLDataDriverResolver.ExecuteCommand
method, which, in turn, call DefaultSQLDataDriverResolver.OnExecuteCommand
event.
OnGetBackUpdatedValues
write this event to return updated values from server. You can call TCustomSQLDataDriverEh.DefaultGetUpdatedServerValues
method to process action by default. TCustomSQLDataDriverEh.DefaultGetUpdatedServerValues
call DefaultSQLDataDriverResolver.GetBackUpdatedValues
. If it was not processed in DefaultSQLDataDriverResolver
then it call InternalGetServerSpecOperations.GetBackUpdatedValues
. InternalGetServerSpecOperations
returns object of TServerSpecOperationsEh
type.
Property TXXXDataDriverEh.SpecParams
Property SpecParams kept a list of parameters and values. TXXXDataDriverEh
use them when performing SQL expressions. Value of each parameter have to be wrote in the separate line in the format PARAMETER_NAME =VALUE
. Depending on the type of the server (InterBase
, Oracle
, MSSQL
, Informix
) SpecParams
can contain the following parameters.
On interaction with InterBase server:
GENERATOR
- defines a name of the InterBase generator. DataDriver uses this parameter to get current value of generator after the insertion of new record.
GENERATOR_FIELD
- defines a name of the field, which will be assigned current value of the generator after the insertion of new record.
AUTO_INCREMENT_FIELD
- defines a name of the field, which DataDriver will set AutoIncremet type. It is used on making a structure of the internal array of record.
On interaction with Oracle server:
SEQUENCE
- will assign a name of the field Oracle sequences. DataDriver uses this parameter for the reception of the current value of the sequence after the insertion of new record.
SEQUENCE_FIELD
- will assign a name of the field, which will be assigned current value of the sequence after the insertion of new record.
AUTO_INCREMENT_FIELD
- defines a name of the field, which DataDriver will set AutoIncremet type. It is used on making a structure of the internal array of record.
On interaction with MSSQL server:
AUTO_INCREMENT_FIELD
- defines a name of the field, which DataDriver will set AutoIncremet type. It is used on making a structure of the internal array of record.
On interaction with Informix server:
AUTO_INCREMENT_FIELD
- defines a name of the field, which DataDriver will set AutoIncremet type. It is used on making a structure of the internal array of record.
Example of the list of parameters for InterBase server:
GENERATOR=EMP_NO_GEN
GENERATOR_FIELD=emp_no
AUTO_INCREMENT_FIELD=emp_no
SQL expression for the insertion of record must contain EMP_NO_GEN generator.
insert into
employee (EMP_NO, FIRST_NAME)
values
(:EMP_NO_GEN, :FIRST_NAME)