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 quantity of pasted/deleted/updated records. On working with procedure/function the method returns -1, the results of procedure/function working will be available in collection of parameter values that must be created on opening repository object.

Example

Executing the example requires that the repository contains a procedure with the P_CALC identifier. The procedure's structure has to input parameters with the pMin, pMax identifiers and one output parameters 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;
    
//Run procedure
    SQLInst.Execute;
    
//Display value of output parameter
    Debug.WriteLine(PValues.FindById("pResult").Value);
End Sub UserProc;

Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    MDesc: IMetabaseObjectDescriptor;
    PValues: IMetabaseObjectParamValues;
    SQLInst: ISQLCommandInstance;
Begin
    MB := Params.Metabase;
    
//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;
    
//Run procedure
    SQLInst.Execute();
    
//Display value of output parameter
    System.Diagnostics.Debug.WriteLine(PValues.FindById("pResult").Value);
End Sub;

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