|
AnyDAC
|
Executes an SQL command.
|
Parameters |
Description |
|
ATimes: Integer = 0 |
A parameters array size. |
|
AOffset: Integer = 0 |
A offset in parameters array. |
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 others, returning cursors, call Open instead of Execute.
Execute prepares the SQL statement for execution, if it has not already been prepared. To speed performance, an application should ordinarily call Prepare method before calling Execute for the first time.
Use ResourceOptions.CmdExecMode to control asynchronous execution mode. And ResourceOptions.CmdExecTimeout to set maximum command execution time. After that time command execution will be canceled and exception raised.
To cancel command execution use AbortJob.
Before command execution the BeforeExecute event is fired. If server will return command execution error, then AnyDAC raises an exception. It may be analyzed in OnError event. After command execution is finished, any output parameters are put into Params property and AfterExecute event is fired.
If ATimes is equal to zero or one, then command is executing in standard mode, otherwise in Array DML mode. See Array DML article for details. By default ATimes and AOffset are equal to 0. ATimes specifies parameters array size. AOffset specifies from which row index in parameters array Array DML command execution should be started. ATimes must be less or equal to Params.ArraySize, otherwise exeception will be raised.
After command execution application may check RowsAffected property value to see how much database records were affected by last command execution.
procedure Execute(ATimes: Integer = 0; AOffset: Integer = 0); virtual;
var i: Integer; .... ADQuery1.SQL.Text := 'insert into mytab values (:p1, :p2)'; ADQuery1.Params.ArraySize := 10; for i := 0 to ADQuery1.Params.ArraySize - 1 do begin ADQuery1.Params[0].AsIntegers[i] := i; ADQuery1.Params[1].AsStrings[i] := 'qwe'; end; ADQuery1.Execute(ADQuery1.Params.ArraySize, 0);
|
What do you think about this topic? Send feedback!
|