Detailed description of sample scripts
- Last UpdatedJul 22, 2024
- 2 minute read
This section is a detailed step-by-step description of what is happening in the sample scripts that follow. For more information about using application objects, see the AVEVA Application Server User Guide.
-
Create a connection object and supply the connection string. The connection string in this example is a literal string, but you can use a connection string supplied by another ArchestrA object through a UDA.
-
If you are using transactions, create a transaction object on the connection object that you created.
-
Create a command object. This example supplies a literal string for the SQL statement, but it could be supplied by another ArchestrA object through a UDA. Note that the SQL statement is a query with a parameter, which allows the requesting object to specify the column to read:
-
If you are not using transactions, create the command object on the connection object.
-
If you are using transactions, create the command object on the transaction object.
-
-
Because the SQL statement of the command object contains a parameter, you must initialize that parameter object (or the transaction that contains it).
-
Run the transaction or command using either the ExecuteAsync() or ExecuteSync() methods.
-
If the command or transaction is processed synchronously, the SQLData Script Library does not return from the ExecuteSync() method until the command is complete. Because processing can take an extended period of time, you should use an asynchronous script (that is, a script that is not synchronized with the scan of the ArchestrA AppEngine).
If the command or transaction is executed asynchronously, poll for completion as follows:
-
If your script runs synchronously with the scan of the ArchestrA AppEngine, you must signal polling to occur by a script once per scan cycle of the engine. This example script starts a second polling script, but you can write a single script with a state variable that starts processing in one state and polls in the other state.
-
If your script runs asynchronously with the ArchestrA AppEngine, you can poll in the following lines of the same script that starts processing using a while loop, which can take an extended period of time to finish.
-
-
When the command or transaction completes without an error, the result can be read from the command object using the parameter that was initialized before the command object was run.
-
Check for errors at each of the major script processing steps.