ExecuteDataReturn

This method executes a query to a NoSQL database that was previously set using the I_NoSQLQueryBuilder function block. The transferred instance of type FB_NoSQLResultEvt is filled with return values.

Syntax

METHOD ExecuteDataReturn : BOOL
VAR_INPUT
    hDBID : UDINT;
    iNoSSQLQueryBuilder: I_NoSQLQueryBuilder;
    pNoSQLResult: POINTER TO FB_NoSQLResultEvt;
END_VAR

ExecuteDataReturn 1: Inputs

Name

Type

Description

hDBID

UDINT

ID of the set database configuration

iNoSQLQueryBuilder

I_NoSQLQueryBuilder

Preconfigured QueryBuilder function block that defines the query to be sent.

pNoSQLResult

POINTER TO FB_NoSSQLResultEvt

Specifies the address for the FB_NoSQLResultEvt function block, which can be used to read the results.

ExecuteDataReturn 2: Return value

Name

Type

Description

ExecuteDataReturn

BOOL

Displays the status of the method. Returns TRUE as soon as the method execution is finished, even in the event of an error.

nDataCount

UDINT

[optional] Number of records returned

Uses the QueryBuilder to execute the corresponding query.

VAR
    fbNoSqlQuery : FB_NoSQLQueryEvt(sNetID := '', tTimeout := T#5S);
    fbNoSQLQueryBuilder_DocumentDB: FB_NoSQLQueryBuilder_DocumentDB
    FindQueryOptions : T_QueryOptionDocumentDB_Find;
    fbNoSqlResult : FB_NoSQLResultEvt(sNetID := '', tTimeout := T#5S);
    myDBID : UDINT := 1;
    sFilter : STRING(255);
    sSort: STRING(255);
    sProjection: STRING(255);
    TcMessage : I_TcMessage;
END_VAR
// set QueryInputs:
fbNoSQLQueryBuilder_DocumentDB.eQueryType := E_DocumentDbQueryType.Find;
fbNoSQLQueryBuilder_DocumentDB.pQueryOptions := ADR(FindQueryOptions);
fbNoSQLQueryBuilder_DocumentDB.cbQueryOptions := SIZEOF(FindQueryOptions);

//set Find Parameter ([optional] sort, projection):
sFilter := '{}'; // read all data from database
FindQueryOptions.pFilter:= ADR(sFilter);
FindQueryOptions.cbFilter:= SIZEOF(sFilter);

// call nosql query:
IF fbNoSqlQuery.ExecuteDataReturn(myDBID, fbNoSqlQuery, ADR(fbNoSqlResult)) THEN
    IF fbNoSqlQuery.bError THEN
        TcMessage := fbNoSqlQuery.ipTcResult;
        nState := 255; 
    ELSE
        nState := nState+1; 
    END_IF
END_IF

First, the FB_NoSQLQueryEvt function block is parameterized via the FB_NoSQLQueryBuilder_DocumentDB function block. Depending on the query type there are various options, such as T_QueryOptionDocumentDB_Find, for defining the filter, sorting or projection.