AVEVA Query Reference Manual
AVEVA Query Reference Manual
AVEVA Query Reference Manual
Reference Manual
AVEVA Solutions Limited
Disclaimer
1.1 AVEVA does not warrant that the use of the AVEVA software will be uninterrupted, error-free or free from
viruses.
1.2 AVEVA shall not be liable for: loss of profits; loss of business; depletion of goodwill and/or similar losses; loss of
anticipated savings; loss of goods; loss of contract; loss of use; loss or corruption of data or information; any
special, indirect, consequential or pure economic loss, costs, damages, charges or expenses which may be
suffered by the user, including any loss suffered by the user resulting from the inaccuracy or invalidity of any data
created by the AVEVA software, irrespective of whether such losses are suffered directly or indirectly, or arise in
contract, tort (including negligence) or otherwise.
1.3 AVEVA's total liability in contract, tort (including negligence), or otherwise, arising in connection with the
performance of the AVEVA software shall be limited to 100% of the licence fees paid in the year in which the user's
claim is brought.
1.4 Clauses 1.1 to 1.3 shall apply to the fullest extent permissible at law.
1.5 In the event of any conflict between the above clauses and the analogous clauses in the software licence under
which the AVEVA software was purchased, the clauses in the software licence shall take precedence.
Copyright
Copyright and all other intellectual property rights in this manual and the associated software, and every part of it
(including source code, object code, any data contained in it, the manual and any other documentation supplied
with it) belongs to, or is validly licensed by, AVEVA Solutions Limited or its subsidiaries.
All rights are reserved to AVEVA Solutions Limited and its subsidiaries. The information contained in this document
is commercially sensitive, and shall not be copied, reproduced, stored in a retrieval system, or transmitted without
the prior written permission of AVEVA Solutions Limited. Where such permission is granted, it expressly requires
that this copyright notice, and the above disclaimer, is prominently displayed at the beginning of every copy that is
made.
The manual and associated documentation may not be adapted, reproduced, or copied, in any material or
electronic form, without the prior written permission of AVEVA Solutions Limited. The user may not reverse
engineer, decompile, copy, or adapt the software. Neither the whole, nor part of the software described in this
publication may be incorporated into any third-party software, product, machine, or system without the prior written
permission of AVEVA Solutions Limited, save as permitted by law. Any such unauthorised action is strictly
prohibited, and may give rise to civil liabilities and criminal prosecution.
The AVEVA software described in this guide is to be installed and operated strictly in accordance with the terms
and conditions of the respective software licences, and in accordance with the relevant User Documentation.
Unauthorised or unlicensed use of the software is strictly prohibited.
© Copyright 1974 to current year. AVEVA Solutions Limited and its subsidiaries. All rights reserved. AVEVA shall
not be liable for any breach or infringement of a third party's intellectual property rights where such breach results
from a user's modification of the AVEVA software or associated documentation.
AVEVA Solutions Limited, High Cross, Madingley Road, Cambridge, CB3 0HB, United Kingdom
Trademark
AVEVA and Tribon are registered trademarks of AVEVA Solutions Limited or its subsidiaries. Unauthorised use of
the AVEVA or Tribon trademarks is strictly forbidden.
AVEVA product/software names are trademarks or registered trademarks of AVEVA Solutions Limited or its
subsidiaries, registered in the UK, Europe and other countries (worldwide).
The copyright, trademark rights, or other intellectual property rights in any other product or software, its name or
logo belongs to its respective owner.
Query Reference Manual
Revision Sheet
Contents Page
Reference Manual
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:1
Who this Manual is Meant For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:1
Guide Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:2
Conventions used in the Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:2
END . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:4
EXTERNAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:4
GET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:5
OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:6
SEND
START . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:6
TOGGLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:7
1 Introduction
Query is a flexible way to access and manipulate the contents of outside databases from
within its products. It provides for a two-way flow of data between application programs and
local or remote databases using Structured Query Language (SQL) as its database access
language. SQL became an ANSI standard in 1986 and an ISO standard in 1987; it is used
today in a great many database application programs management systems.
Query is essentially a programming toolkit which allows the user to create their own macros
to carry out functions such as:
• Reading additional attribute data from local or remote databases
• Adding object and attribute data to external databases
• Adding functionality to existing user interfaces
The addition of Query to an application program forms a powerful programmable
engineering database system.
Query supports Open Database Connectivity (ODBC), an interface standard for database
access. All components necessary to provide the ODBC interface, such as
communications, are internal to ODBC.
A user of Query commands is presented with the same interface and need not be aware of
the different ways in which the functionality is provided, except of course when Query or the
database is configured.
Query and ODBC describes the ODBC architecture used by Query with
its setup requirements and special features.
The Communicating Using Query section explains the commands available within Query for
accessing an external database, such as a remote source on a data sever. Data settings
can be read from, or written to the data server. It also explains how the user can store and
manipulate the results of querying such data within Query.
where synonym is a text string which identifies the server daemon through which
communication is to be channelled (and which therefore identifies the data server required);
token_var is the name of a PML variable into which a token for the connection is to be
written; and (if your data server requires login data) connect_string is a text string which
confirms the users access rights (such as their username and password).
Example:
To connect Query to a data server which is installed on a different machine, use the
extended form of the command
where synonym, token_var and connect_string are as above and host is a text string which
identifies the node on the network on which the server daemon. For example, to connect to
a data server on a machine called pc35, enter
EXTERNAL OPEN ’MAINTENANCE’ !!MAINT ON ’pc35’ AS ’bull/
robert’
or, alternatively, a generalised version such as
EXTERNAL OPEN ’MAINTENANCE’ !!MAINT ON ’sqlnet’ AS ’bull/
robert’
where the alias ‘sqlnet’ has been defined so as to point to the current host for, say, an SQL
database server.
To disconnect Query from a data server to which it is currently connected, use the command
where token is the token for the communication channel which was supplied by a successful
EXTERNAL OPEN command (and stored in the token_var variable).
Example:
Note: The $ prefix used to expand the variable !!MAINT to give the token value.
Note: The ODBC Data Source Administrator also provides control over this logging.
The user can send commands to the data server in one of two ways:
• As individual command lines, each of which is sent as soon as the newline character is
entered to terminate the command line.
• In continuous mode, such that a sequence of command lines is concatenated and sent
as a single command string. The maximum length for an individual command line is
120 characters; continuous mode allows the user to send longer command sequences.
To send an individual command line to the data server, simply prefix the command text thus:
where token is the token for the communication channel which was supplied by a successful
EXTERNAL OPEN command (and stored in the token_var variable) and command_text is
the command string to be sent to the data server.
Example:
To send a continuous command sequence to the data server, use the syntax
where token is the token for the communication channel which was supplied by a successful
EXTERNAL OPEN command (and stored in the token_var variable) and command_text_1
etc. are the command strings to be sent to the data server.
Example:
When the END command is reached, all text lines entered since START are concatenated,
with a space separator between each, and sent to the data server as a single command.
where token is the token for the communication channel which was supplied by a successful
EXTERNAL OPEN command (and stored in the token_var variable). The variable varname
will be interpreted automatically as an array variable and each data item will be stored in a
separate element of the array. (The PML SPLIT command is not required here; splitting is
carried out automatically.)
Note: No data field should be longer than 120 characters, since this is the maximum
permitted length that can be stored in a variable. If a data field exceeds 120
characters, nothing will be returned by the query.
and so on for subsequent data records. If the newly read record has less completed fields
than the preceding record, some elements of the array variable will remain with their
previous settings unchanged.
The user can control the writing of data to an array variable explicitly by using the variable-
setting syntax. For example, to read in a record such that its first field is stored in element 10
of the array variable, rather than starting from element 1 by default, the user could use the
syntax
VAR !datarow[10] EXTERNAL GET $!!MAINT NEXT
To read a record and append the resulting data to the array variable, rather than overwriting
the current settings of the array elements, the user could use the syntax
VAR !datarow APPEND EXTERNAL GET $!!MAINT NEXT
and so on.
The most convenient way to retrieve multiple data records is usually to incorporate the
NEXT command into a PML ‘infinite’ DO loop construct, reading one data record during
each cycle of the loop. When the last record has been read in, the next cycle of the loop will
generate the message
(79, 10) No more data
which can be dealt with by using the PML HANDLE facility. For example:
To set the column headings returned by a data server query in an array variable, use either
version of the following syntax:
These commands always return the first row of the result of the last request sent to the data
server identified by token (typically, but not necessarily, header information resulting from an
SQL database SELECT command).
For example, the querying command
EXTERNAL SEND $!!MAINT ’select * from maintdata’
VAR !header EXTERNAL GET $!!MAINT RESULT
$!header[1] refno
$!header[2] servint
$!header[3] lastserv
Note: As with the data fields, no heading should be longer than 120 characters. If a
heading exceeds 120 characters, nothing will be returned by the query.
would be received by Query, using the default ~ delimiter, as the data block
Catalytic Cracker~Reflux~Heater~DES21142
and would be split, incorrectly, into the fields
To prevent this effect, you can redefine the delimiter character to be any single character
which is not used within any database field. To do so, use the command
where token is the token for the communication channel which was supplied by a successful
EXTERNAL OPEN command (and stored in the token_var variable) and text_char is the
required data field delimiter character.
For example, the specification
EXTERNAL DELIMIT $!!MAINT ’&’
would cause the data block from the preceding example to be received as
Catalytic Cracker&Reflux~Heater&DES21142
which would be correctly split at the points identified by the & characters.
The text of a data server error message is usually explicit, since it is generated from the
database, and so its meaning, and the method of resolving it, should be clear. For example,
if the user is communicating with an ORACLE database, the command
EXTERNAL SEND $!!MAINT ’select * from emp’
could result in the error
(79, 7) Request failed: ORA-00942: table or view does not
exist
Similarly, the command
EXTERNAL SEND $!!MAINT ’select * from emp’
could result in the error
(79, 7) Request failed: ORA-00904: invalid SQL statement
Note: These are most likely to be caused by general network problems rather than by
Query itself.
(79, 63) Server daemon has shut down because a FATAL error
was detected
3 Command Syntax
The Command Syntax section gives detailed information on how to use the relevant
commands for using Query to communicate with other data servers.
The commands described in the main part of this section have their legal command and
interrogation options presented in the form of syntax diagrams. These diagrams formalise
the precise command sequences which may be used and supplement the explanations
given in the appropriate sections of this manual.
The following conventions apply to the syntax diagrams in this section:
• Names written in lowercase letters enclosed in angled brackets (e.g. <direction>)
represent subsidiary syntax diagrams. Such names are used for cross-reference
purposes within other syntax diagrams.
• Commands to be input from the terminal are shown in a combination of uppercase and
lowercase letters. In general, these commands can be abbreviated; the capital letters
indicate the minimum permissible abbreviation.
Note: Using this convention does not mean that the second part of the command must be
typed in lowercase letters; commands may be entered in any combination of
uppercase and lowercase letters.
means the user can type in ABC or PQR or any command allowed by the syntax given
in subsidiary syntax diagram <dia> or just press RETURN to get the default option.
• points marked with an asterisk (*) are loop back junctions. Command options
following these may be repeated as required. Thus
.-----<-------.
/ |
>---*--- option1 ---|
| |
|--- option2 ---|
| |
‘--- option3 ---+--->
permits any combination of option1 and/or option2 and/or option3 to be used (where
the options may define commands, other syntax diagrams, or command arguments).
Using this may form an exception to the rule of reading from top left to bottom right.
The simplified format
.----<-----.
/ |
>---*--- name ---+--->
means that you may type in a list of names, separated from each other by at least one
space.
Note: The need to press the Return (or Enter or ) key to complete each command line
is implicit in all syntax diagrams and is not usually shown. Only in cases where the
need to press Return/Enter/ has some particular significance is this indicated
specifically by the abbreviation nl.
3.2 Commands
The information is given under the following headings:
Description:
A brief explanation of what the command enables the user to do and when the user might
use it.
Example:
Examples of the permitted command variations. (Examples are omitted in trivial cases.)
Syntax:
The full command syntax, given in diagrammatic form.
3.2.1 CLOSE
Description:
Disconnects Query from a specified data server (to which it is currently connected as a
result of an OPEN command).
Example:
EXTERNAL CLOSE $!!MAINT
Syntax:
>-- EXTERnal -- CLOse -- token -->
where:
token is the token for the communication channel which was supplied by a successful
OPEN command and which is stored in a variable.
3.2.2 DELIMIT
Description:
Allows the user to specify the delimiting character which separates the individual data fields
when querying a specified data server. The default delimiter is the ~ (tilde) character.
Example:
EXTERNAL DELIMIT $!!TOK_VAR ’&’
Syntax:
>-- EXTERnal DELImit server_token text_char -->
where:
server_token is an integer identifying the required data server channel and text is a
single character only.
Note: The user must choose a delimiting character which does not occur within any data,
otherwise Query will split the incoming data string in the wrong place.
3.2.3 END
Description:
Terminates the sending of a long command string to a data server.
All command lines following a START entry will be concatenated to form a composite
command of any required length until terminated by a corresponding END entry.
The maximum length for a single query line is 120 characters.
The maximum total length for the overall query string (i.e. all lines between the START and
END commands) is 4095 characters.
Example:
EXTERNAL SEND $!!MAINT START
’select refno, servint, lastserv from maintdata’
’where elementtype = ’’EQUIPMENT’’’
END
Note: The use of multiple delimiting ’’ characters for nesting text within text in this example.
You could, alternatively, write the example using ‘vertical bar’ text delimiters, thus:
Syntax:
.-----<-----.
/ |
>-- EXTERnal SENd server_token START --*-- text nl --+-- END -->
where:
server_token is an integer identifying the required data server channel.
3.2.4 EXTERNAL
Description:
Allows the user to send to a specified data server any valid text string which represents a
command to read from, or write to, a database.
For details of subsidiary commands relevant to EXTERNAL mode, see under the following
headings:
CLOSE
DELIMIT
END
GET
OPEN
SEND
START
TOGGLE
Example:
EXTERNAL SEND $!!MAINT ’select * from maintdata’
This sends the specified text string to the data server whose channel token is stored in
the variable !!MAINT.
Syntax:
>-- EXTERnal ... -->
3.2.5 GET
Description:
Allows the user to set to data values returned from a data server (using NEXT). Note that all
of the standard syntax for setting is available for use within Query.
Also allows the user to store the column headings returned by a data server query in an
array variable (using RESULT or HEADER).
Example:
VAR !datarow EXTERNAL GET $!!MAINT NEXT
VAR !header EXTERNAL GET $!!MAINT RESULT
Syntax:
>- VAR varname EXTERnal GET token -+- NEXT -------.
| |
|- RESult -----|
| |
‘- HEADer -----+--->
where:
token is the token for the communication channel which was supplied by a successful
EXTERNAL OPEN command (and stored in the token_var variable).
varname will be interpreted automatically as an array variable and each data item will
be stored in a separate element of the array. (The PML SPLIT command is not
required here; splitting is carried out automatically.)
Note: RESULT and HEADER commands always return the first row of the result of the last
request sent to the data server identified by token (typically, but not necessarily,
header information resulting from an SQL database SELECT command).
As with the data fields, no heading should be longer than 120 characters. If a
heading exceeds 120 characters, nothing will be returned by the query.
3.2.6 OPEN
Description:
Connects Query to a specified data server (via a server daemon).
Many communication channels may be open concurrently, each being identified by a token
(an integer) which is returned by the server and stored in a named variable for subsequent
reference.
Example:
EXTERNAL OPEN ’MAINTENANCE’ !!MAINT AS ’bull/robert’
EXTERNAL OPEN ’MAINTENANCE’ !!MAINT ON ’pc35’ AS ’bull/
robert’
Syntax:
>- EXTERnal OPEn synonym token_var -+- ON hostid-.
| |
‘------------+- AS connect_string -.
| |
‘---------------------+->
where:
synonym is a text string which identifies the server daemon through which
communication is to be channelled. The synonyms must be defined in the
daemon_file - refer to Appendix A.
token_var identifies a variable to be used to store the integer token returned by the
server when the communication channel is successfully opened. The user uses the
setting of this variable for all subsequent references to that server daemon.
hostid is a text string which identifies the node on which the server daemon resides
(not required for ODBC or if the daemon is running on the same node as Query).
connect_string is any text string needed to allow you to connect/login to the data
server (typically contents and database name, username and password).
3.2.7 SEND
Description:
Allows the user to send a command string to a specified data server.
The user can send short command strings (up to 120 characters) within the SEND
command line, or the user can concatenate multiple command strings by using the START
and END commands (q.v.).
Example:
EXTERNAL SEND $!!MAINT ’commit’
Syntax:
>-- EXTERnal SENd server_token text -->
3.2.8 START
Description:
Allows the user to send a long command string to a specified data server (by extending the
SEND command).
All command lines following a START entry will be concatenated to form a composite
command of any required length until terminated by a corresponding END entry.
The maximum length for a single query line is 120 characters.
The maximum total length for the overall query string (i.e. all lines between the START and
END commands) is 4095 characters.
Example:
EXTERNAL SEND $!!MAINT START
’select refno, servint, lastserv from maintdata’
’where elementtype = ’’EQUIPMENT’’’
END
Note: The use of multiple delimiting ’’ characters for nesting text within text in this example.
The user could, alternatively, write the example using ‘vertical bar’ text delimiters,
thus:
Syntax:
.-------------.
/ |
>-- EXTERnal SENd server_token START --*-- text - nl --+-- END -->
where:
server_token is an integer identifying the required data server channel.
3.2.9 TOGGLE
Description:
Allows the user to toggle on or off any tracing facilities built into a server daemon.
Example:
EXTERNAL TOGGLE $!!MAINT TRACE
Syntax:
>-- EXTERnal TOGgle server_token TRAce -->
Note: For all ODBC connections that the ON hostid clause of the EXTERNAL OPEN
command is not used. All the information it needs is supplied by the DSN any other
parts of the connection string.
In the following sections there are some general details of ODBC, its components and
facilities. For more information, refer to the appropriate ODBC document or help file.
Example:
do
var !INFO delete
var !INFO external get $!TOK NEXT
handle ( 79, 10 )
break $* end of data
endhandle
var list _TABLE1 add (trim(vtext(!INFO[1])))
exit
enddo
$* close the connection
external close $!TOK
handle any
error |$!!ERROR.TEXT|
endhandle
return
Important: It is important to remember that these facilities are not based on the system
ODBC libraries and that the commands that are shown are the only ones that
are supported.
Index
C Errors
Handling Returned . . . . . . . . . . . . . . 2:7
Commands
Abbreviations . . . . . . . . . . . . . . . . . . 3:1
AS . . . . . . . . . . . . . . . . . . . . 2:1, 2:2, 3:5
O
CLOSE . . . . . . . . . . . . . . . . . . . 2:2, 3:3 ODBC
DELIMIT . . . . . . . . . . . . . . . . . . 2:6, 3:3 Architecture . . . . . . . . . . . . . . . . . . . A:1
END . . . . . . . . . . . . . . . . . . . . . 2:3, 3:4 SQL Escape Sequences . . . . . . . . . A:5
EXTERNAL . . . . . . . . . . . . . . . 2:1, 3:4
GET . . . . . . . . . . . . . . . . . . 2:4, 2:5, 3:5
S
HEADER . . . . . . . . . . . . . . . . . 2:5, 3:5
NEXT . . . . . . . . . . . . . . . . . . . . 2:4, 3:5 Synonym (data server) . . . . . . . . . . . 2:1, 3:5
ON . . . . . . . . . . . . . . . . . . . . . . 2:2, 3:5
OPEN . . . . . . . . . . . . . . . . . 2:1, 2:2, 3:5 T
RESULT . . . . . . . . . . . . . . . . . . 2:5, 3:5
SEND . . . . . . . . . . . . . . . . . 2:3, 3:4, 3:6 Token . . . . . . . . . . . . . . . . . . . . . . . . . . . 3:5
START . . . . . . . . . . . . . . . . . . . 2:3, 3:6 (data server) . . . . . . . . . . . . . . . 2:1, 3:5
TOGGLE . . . . . . . . . . . . . . . . . . . . . 3:7
TRACE . . . . . . . . . . . . . . . . . . . . . . . 2:2
D
Data Field Delimiter
Specifying . . . . . . . . . . . . . . . . . . . . . 2:6
Data Server
Connecting Query . . . . . . . . . . . . . . 2:1
Directing Commands . . . . . . . . . . . . 2:1
Sending Commands . . . . . . . . . . . . . 2:3
Setting Variables from Responses . . 2:4
E
Environmental Setup Requirements . . . . 2:2
Error messages
Server daemon . . . . . . . . . . . . . . . . . 2:7