SQLQuery
(VTSSQLInterface library)
Description: | A launched module that executes an SQL query on data in a VTS application. For queries of external databases, refer to the ODBC Manager Service |
Returns: | Nothing (The parameters will be populated with pointers to the returned information) |
Usage: | Script Only. |
Function Groups: | Database and Data Source, ODBC |
Related to: | |
Format: | \VTSSQLInterface.SQLQuery(QueryString, &Results, &FieldNames, &FieldTypes, &ReturnCode, &ErrorMsg[, &ParamInfo, &PageInfo, &PageStatsInfo]) |
Parameters: |
QueryString | ||||||||||||||
Required. Any text expression containing a valid SQL select statement. Not all selection clauses are supported. | ||||||||||||||
Results | ||||||||||||||
Required. A pointer to a variable which will hold the results array. | ||||||||||||||
FieldNames | ||||||||||||||
Required. A pointer to a variable that will hold the field names array. Field names are typically "Value" for most tag values. |
||||||||||||||
FieldTypes | ||||||||||||||
Required. A pointer to a variable that will hold the field types. The types will be returned as SQL data types according to the following table:
|
||||||||||||||
ReturnCode | ||||||||||||||
Required. A pointer to a variable that will hold the return code. The code will be one of the following:
|
||||||||||||||
ErrorMsg | ||||||||||||||
Required. A pointer to a variable that will hold a textual error message. Valid only if ReturnCode is not zero. | ||||||||||||||
ParmInfo | ||||||||||||||
Optional. A pointer to a variable that will hold parameter information. | ||||||||||||||
PageInfo | ||||||||||||||
Optional. A pointer to a variable that will hold a PageInfoStruct structure, used to support pagination. | ||||||||||||||
PageStatsInfo | ||||||||||||||
Optional. A pointer to a variable that will hold a PageStatsInfoStruct structure, used to support pagination. |
Comments: |
Only selection queries are supported. SQL statements for data manipulation will do nothing. If tag filtering or realm-area filter is in effect, this function will retrieve data only from tags the currently logged-on user is permitted to access. When retrieving historical data, SQLQuery is essentially a wrapper for GetTagHistory. It takes an incoming SQL query, and makes one or more calls to GetTagHistory to retrieve the results. SQLQuery may also be used to retrieve current tag values and other custom tables (such as alarm data). Legacy tables made it look like tag values were stored in separate tables and used the time stamp of the current server. These legacy tables still exist but are hidden by default, using the property: SQLQueryHideLegacyTables. Newer code should query all tag values from the table, "History", or from a ":TPP"derivative such as "History:1d". See the links for further information. Supported SQL syntax is as follows: SELECT [DISTINCT | ALL] columnspecifier-1, columnspecifier-2, ... FROM tablename-1, tablename-2, ... [WHERE where-expression] [ORDER BY columnspecifier-1 [ASC | DESC], columnspecifier-2, ...] [LIMIT [offset,] row_count]
Each logged tag corresponds to one table in the VTS database schema. Every logged variable within the tag is one column. In addition, a "TPP specifier" may be appended to a tag name to utilize GetTagHistory's ability to retrieve data over time periods. The TPP specifier is a colon followed by a number and an abbreviation for various time periods. The recognized time period abbreviations are (case-insensitive):
For example, the table 'ai1:2D' can be used to retrieve data from tag ai1 with a TPP of 2 days. A TPP may only be specified for a tag that has at least one numeric logged variable. When a TPP is specified, the available columns are:
... where VarName may be replaced by any numeric logged variable from the tag. The current values of a tag may be retrieved using a table name with the format "TagName_Current". This table will have one row whose columns are Timestamp (the current time) and the current values of each logged value in the tag. Bit-Wise queries can be created, similar to modes 12 and 13 of calls to GetTagHistory(). To specify a bit-wise summary, use either:
For example: Select Timestamp, as1:value:average, as1:value:BitwiseOR from History_1h where Timestamp >= '2017-10-02 00:00' and Timestamp <= '2017-10-02 23:59' |