ExecuteQuery
(ODBC Manager Library)
Description: |
Called to send an SQL SELECT command to the server and get a reply back. This function is used as a general query tool and does not provide for the guaranteed eventual execution that the ExecuteQueryCached() function does. |
Returns: | 0 upon query execution starting. See the following comments. |
Usage: | Script Only. |
Related to: | AddConnection | BuildDelete | BuildInsert | BuildSelect | BuildUpdate | ConvertToDbDate | ConvertToDbTime | ConvertToDbTimeStamp | ConvertToVTSDate | ConvertToVTSTime | ConvertToVTSTimeStamp | CopyRecords | DBDropList | DBGridList | ErrMessage | ExecuteQueryCached | FlushCache | FormatBatchQuery | GetConnList | ResultFormat | StatsWin | TableSynch | Transaction | TransactionCached |
Format: | \ODBCManager\ExecuteQuery(ErrPtr, CmdStr, DSN, UserName, Password, ResultPtr [, AttribPtr, ErrorMsgPtr, SQLStatePtr, ErrorCodePtr, ReFormat, TransObj, FormatBitField, dbType]) |
Parameters: |
ErrPtr | ||||||||||
Required. Pointer to an error. Always valid on completion. Set to 0 if the command succeeds. | ||||||||||
CmdStr | ||||||||||
Required. The SQL command to send to the database | ||||||||||
DSN | ||||||||||
Required. The name of the ODBC database in which to execute the command. | ||||||||||
UserName | ||||||||||
Required. The user name in the database for authentication. A null provided in this field will be passed to the database as a null string. | ||||||||||
Password | ||||||||||
Required. The password in the database for authentication. A null provided in this field will be passed to the database as a null string. | ||||||||||
ResultPtr | ||||||||||
Required. A pointer to the ODBC result data being passed back as the result of the query. | ||||||||||
AttribPtr | ||||||||||
Optional. A pointer to the ODBC attribute array being passed back from the result of the query. no default: | ||||||||||
ErrorMsgPtr | ||||||||||
Optional. A pointer to the ODBC error message being passed back. Will contain invalid if the command succeeds. no default: | ||||||||||
SQLStatePtr | ||||||||||
Optional. A pointer to the ODBC error state being passed back. Will contain invalid if the command succeeds. no default: | ||||||||||
ErrorCodePtr | ||||||||||
Optional. A pointer to ODBC error code being passed back. Will contain invalid if the command succeeds. no default: | ||||||||||
ReFormat | ||||||||||
Optional. A flag which, if set to true, causes the result set from the query to be reformatted from a Result[Column][Row] to Result[Row][Column]. This is potentially useful for reformatting multi-record "Select" queries to match your application requirements. no default: | ||||||||||
TransObj | ||||||||||
Optional. An transaction object (as returned from the "Transaction()" function) to execute this query within. If a transaction is opened on this DSN and this value is not set, then the query will wait until the transaction has completed before being executed. If set, the query will be executed after all other outstanding ExecuteQuery() functions for the transaction on the DSN have executed. no default: | ||||||||||
FormatBitField | ||||||||||
Optional. Bitfield indicating whether values coming back from the query will be converted to their corresponding VTScada data types. Can be set on a type by type basis according to the following flags: (no default)
|
dbTyp | |||||||||||||
Optional numeric value, indicating the type of this DB connection.
|
Comments: | This module is a member of the ODBCManager Library, and must therefore be prefaced by \ODBCManager\, as shown in "Format" above. This module MUST be called as a subroutine in a script. This function acts as a shell to launch a query within the DSN within the ODBCManager library. Upon completion of the execution of the function, the query is still active. Completed execution of the query is indicated by a valid value set in the variable pointed to by parameter "ErrPtr". For this reason the variable referenced by "ErrPtr" MUST be invalidated before calling the function. |
Example
Init [ If 1 Wait Execution; [ ErrPtr = Invalid(); \ODBCManager\ExecuteQuery(&Err, "Select ID, TimeStamp, Data1 From Log_Table Order By TimeStamp", "MAIN LOGGER", User, Pass) ] ] WaitExecution [ If Err DisplayError; If !Err DisplayData; ]