ISQLCommandInstance.Execute

Syntax

Execute: Integer;

Description

The Execute method runs object on execution and returns the quantity of processed records.

Comments

If DBMS command is processed, the method returns the number of inserted/deleted/updated records.

When working with procedure/function the method returns -1, the results of procedure/function work will be available in the collection of parameter values that must be created on opening repository object. The instance of the ISQLCommandInstance object can also be cast to the IMetabaseObjectInstance interface that allows for working with object parameters.

Example

Executing the example requires that the repository contains a procedure with the P_CALC identifier. The procedure's structure has two input parameters with the pMin, pMax identifiers and one output parameter with the pResult identifier. Any calculation is executed in procedure.

Add links to the Db and Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    MDesc: IMetabaseObjectDescriptor;
    PValues: IMetabaseObjectParamValues;
    SQLInst: ISQLCommandInstance;
Begin
    MB := MetabaseClass.Active;
    
// Procedure description
    MDesc := MB.ItemById("P_CALC");
    
// Create a set of parameters
    PValues := MDesc.Params.CreateEmptyValues;
    PValues.FindById(
"pMin").Value := 0;
    PValues.FindById(
"pMax").Value := 1000;
    
// Get opened instance
    SQLInst := MDesc.Open(PValues) As ISQLCommandInstance;
    
// Execute procedure
    SQLInst.Execute;
    
// Display output parameter value
    Debug.WriteLine(PValues.FindById("pResult").Value);
End Sub UserProc;

On executing the example the procedure instance intended for its execution will be obtained. On instance opening, input parameters will be set. After running the procedure for execution, the obtained value of output parameter will be displayed to the development environment console.

See also:

ISQLCommandInstance