CreateSP
This method is used to initialize an instance of the function block FB_SQLStoredProcedureEvt with the already open database connection of the function block FB_SQLDatabaseEvt. The function block FB_SQLStoredProcedureEvt only uses the database connection it was assigned via the CreateCmd method. Several instances of the function block FB_SQLStoredProcedureEvt can be initialized with the same database connection.
The initialization of the function block FB_SQLStoredProcedureEvt may take several cycles. The Busy flag of the function block or the method return value of the CreateCmd method have to be checked before the function block can be used.
Syntax
METHOD CreateSP : BOOL
VAR_INPUT
sProcedureName: T_MaxString;
pParameterInfo: POINTER TO ARRAY [0..MAX_SPPARAMETER] OF ST_SQLSPParameter;
cbParameterInfo: UDINT;
pSQLProcedure: POINTER TO FB_SQLStoredProcedureEvt;
END_VAR
Inputs
Name | Type | Description |
---|---|---|
sProcedureName | T_MaxString | Indicates the name of the procedure to be executed. |
pParameterInfo | POINTER TO ARRAY [0..MAX_SPPARAMETER] OF ST_SQLSPParameter | Pointer address for the parameter info list. |
cbParameterInfo | UDINT | Indicates the length of the parameter info list. |
pSQLProcedure | POINTER TO FB_SQLStoredProcedureEvt | Returns a new instance of the function block FB_SQLStoredProcedureEvt. |
Return value
Name | Type | Description |
---|---|---|
CreateSP | BOOL | Displays the status of the method. Returns TRUE as soon as the method execution is finished, even in the event of an error. |
Sample
VAR
fbSqlDatabase : FB_SQLDatabaseEvt(sNetID := '', tTimeout := T#5S);
ParaInfo : ST_SQLSPParameter;
END_VAR
ParaInfo.sParameterName := '@Customer_ID';
ParaInfo.eParameterType := E_SPParameterType.Input;
ParaInfo.eParameterDataType := E_ColumnType.BigInt;
ParaInfo.nParameterSize := 8;
IF fbSQLDatabase.CreateSP('dbo.SP_GetCustomerPositions', ADR(ParaInfo), SIZEOF(ParaInfo), ADR(fbSQLStoredProcedure)) THEN
IF fbSQLDatabase.bError THEN
nState:=255;
ELSE
nState:= nState+1;
END_IF
END_IF
Subsequently, the FB_SQLStoredProcedureEvt can be used to execute the stored procedure.