Execute: Integer;
The Execute method executes the command on the database server and returns the number of processed records.
The method runs the SQL query specified in the IDalCommand.SQL property. If the command is used to extract data, it is recommended to use the CreateCursor method instead of the Execute method.
If the SQL query changes data (adds or deletes records, or updates the existing records), the method returns the number of processed records. When the parameters are used in the query, their actual values are substituted from the IDalCommand.Params collection. If the command is used for the batch insert of multiple sets of parameter values, all the sets in the range from zero to CurrentParamsRow are processed on executing the method. After executing the Execute method, the CurrentParamsRow property is set to zero.
If an error occurs on executing the SQL query, an exception is thrown.
Executing the example requires a database with the DB identifier and a table with the MyTable identifier in the repository.
Sub UserProc;
Var
Mb : IMetabase;
DB_ORCL8 : IDatabaseInstance;
Command : IDalCommand;
Params : IDalCommandParams;
sql : String;
paramArraySize, i, j : Integer;
Begin
MB := MetabaseClass.Active;
DB_ORCL8 := MB.ItemById("DB").Open(Null) As IDatabaseInstance;
sql := "insert into MyTable (field,field1) values(:1,:2)";
Command := DB_ORCL8.Connection.CreateCommand(sql);
Command.Type := DalCommandType.Text;
Command.Parse;
Command.Prepare;
Params := Command.Params;
Params.Item(0).DataType := DbDataType.String;
Params.Item(1).DataType := DbDataType.Float;
paramArraySize := 3;
Command.MaxParamsRows := paramArraySize;
j := 1;
For i := 1 To 10 Do
Params.Item(0).Value := "№ "+i.ToString;
Params.Item(1).Value := i + 0.1;
If (j < paramArraySize) Then
Command.NextParamsRow;
j := j+1;
Else
Command.Execute;
j:= 1;
End If;
End For;
If j > 1 Then
Command.ExecuteWithoutLast;
End If;
End Sub UserProc;
10 records are inserted into the table after executing this example.
See also: