Execute

This method sends a query to the NoSQL database, which was previously set with the I_NoSQLQueryBuilder function block.

Syntax

METHOD Execute : BOOL
VAR_INPUT
    hDBID: UDINT;
    iNoSQLQueryBuilder: I_NoSQLQueryBuilder;
END_VAR

Execute 1: Inputs

Name

Type

Description

hDBID

UDINT

ID of the set database configuration

iNoSSQLQueryBuilder

I_NoSQLQueryBuilder

Pre-parameterized QueryBuilder function block. This varies depending on the database.

Execute 2: Return value

Name

Type

Description

Execute

BOOL

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

Uses the QueryBuilder to execute the corresponding query.

VAR
    fbNoSQLQuery : FB_NoSQLQueryEvt(sNetID := '', tTimeout := T#5S);
    fbNoSQLQueryBuilder_DocumentDB: FB_NoSQLQueryBuilder_DocumentDB;
    InsertQueryOptions: T_QueryOptionDocumentDB_Insert;
    myDBID : UDINT := 1;
    sDocument : STRING(1000);
    TcMessage : I_TcMessage;
END_VAR
// set QueryInputs
fbNoSQLQueryBuilder_DocumentDB.eQueryType := E_DocumentDbQueryType.InsertOne;
fbNoSQLQueryBuilder_DocumentDB.pQueryOptions := ADR(InsertQueryOptions);
fbNoSQLQueryBuilder_DocumentDB.cbQueryOptions := SIZEOF(InsertQueryOptions);

// set insert parameter:
sDocument := '{Name : „MyValue“, Value : 123.456}';
InsertQueryOptions.pDocuments:= ADR(sDocument);
InsertQueryOptions.cbDocuments:= SIZEOF(sDocument);

// call nosql command
IF fbNoSQLQuery.Execute(myDBID, fbNoSQLQueryBuilder_DocumentDB) 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_Insert, for setting the document to be inserted.