Show: Delphi C++
Display Preferences

FireDAC.Comp.DataSet.TFDDataSet.Execute

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Execute(ATimes: Integer = 0; AOffset: Integer = 0); virtual;

C++

virtual void __fastcall Execute(int ATimes = 0x0, int AOffset = 0x0);

Properties

Type Visibility Source Unit Parent
procedure
function
public
FireDAC.Comp.DataSet.pas
FireDAC.Comp.DataSet.hpp
FireDAC.Comp.DataSet TFDDataSet

Description

Executes an SQL command.

Call Execute to execute a SQL statement currently assigned to descendant class properties:

Use Execute to execute queries that do not return a cursor to data (such as INSERT, UPDATE, DELETE, CREATE TABLE, CALL, BEGIN .. END, etc). For SELECT statements and other returning cursors, call Open instead of Execute

Execute prepares the SQL statement for execution, if it has not already been prepared. To speed the performance, an application should ordinarily call the Prepare method before calling Execute for the first time. 

Use ResourceOptions.CmdExecMode to control the asynchronous execution mode. Also, use ResourceOptions.CmdExecTimeout to set the maximum command execution time. After that time, the command execution is canceled and an exception is raised. 

To cancel the command execution, use AbortJob

Before the command execution, the BeforeExecute event is fired. If the server returns a command execution error, then FireDAC raises an exception. It can be analyzed in the OnError event. After the command execution is finished, any output parameters are put into the Params property and the AfterExecute event is fired. 

If ATimes is equal to zero or one, the command is executing in standard mode, otherwise in is executing in Array DML mode. By default, ATimes and AOffset are equal to 0. ATimes specifies the size of the parameter array. AOffset specifies at which row index in the parameters array, the Array DML command execution should start. ATimes must be less or equal to Params.ArraySize, otherwise an exception is raised. 

After the command execution, the application can check the RowsAffected property value to see how many database records were affected by the last command execution.

Example

var
  i: Integer;
....
FDQuery1.SQL.Text := 'insert into mytab values (:p1, :p2)';
FDQuery1.Params.ArraySize := 10;
for i := 0 to FDQuery1.Params.ArraySize - 1 do begin
  FDQuery1.Params[0].AsIntegers[i] := i;
  FDQuery1.Params[1].AsStrings[i] := 'qwe';
end;
FDQuery1.Execute(FDQuery1.Params.ArraySize, 0);

See Also

Samples

Personal tools
RAD Studio 10.2 Tokyo
In Other Languages
Previous Versions
Assistance