Summer 1998   

MV Basics

The Access Query Language, Part 1

The MV Basics series is an occasional series of articles of a generally technical theme, designed for those of you who are new to the MultiValue way of life. It will also be of interest to the old hands who may have forgotten one or two tricks of the trade! This guide to Access has been compiled by Simon Patterson of Beauchamp Computer Services Ltd.

 

Introduction

ACCESS is PICK’s query language. It allows users to query and display the data within the database in as much or as little detail as required. The data can be sorted, selected, and generally manipulated in many ways to generate the desired output. Thus ACCESS provides for a range of uses from the simplest queries to the most complex reports. Combined with other TCL commands, it also provides the System Administrator with very powerful tools for managing the database. Finally, ACCESS provides programmers with a quick method of producing reports whatever else their program is doing!

MultiValue systems, i.e. those using the Pick data model, use a 4-level file hierarchy as the structure supporting the relational database. We will be looking in detail at the relationship between a dictionary file and its data files(s).

The data file holds information in the form of items. The dictionary file holds specific information about its data file(s) in two types of items. The first type of item, a file definition item (D-pointer), defines which data files exist for that dictionary. The second type of item, an attribute definition item (known as an A-pointer or word), describes each attribute of the item(s) in the data file i.e. how each item is made up, line by line.

To summarize: data files contain items of the same format such that, for example, the name is always stored in attribute one, the address in attribute two, the telephone number in attribute three etc. The dictionary file (of such a data file) can then contain A-pointer items (or words) defining each of these attributes of the data file. These A-pointers are then used in ACCESS queries to reference those data.

1. ATTRIBUTE DEFINITION ITEM (A-pointer)

All attribute definition items conform to the following layout:

Attribute Description
0
1
2
3
4
5
6
7
8
9
10
Item-id
Definition Code
Attribute Number
Column Header
Controlling/Dependent
Not used
Not used

Conversion
Correlative
Type
Width

 

Attribute 0 (Item-id)
Usually an abbreviated description of the contents of the attribute since it is used in the ACCESS statement. If the item-id is numeric then the attribute definition will be used in listings if no other output criteria are specified.
Attribute 1: Definition Code
A Primary attribute definition.
S
 
Synonym attribute definition, that is an alternative definition of an attribute even though multiple A-pointers to any given attribute are also allowed.
X
 
A protected attribute definition which does not appear as output and usually only in selection criteria.

Attribute 2: Attribute Number
The number of the attribute.

0
 
is used to reference the item-id or if the output is computed and is not stored on the item.
9998 outputs the number of items listed so far.
9999 outputs the size of the current item in bytes.

Attribute 3: Column Header
The text printed at the top of the column of output. If blank then the item-id of the A-pointer is used. Multi-line headers are possible by separating each line of the header with a value mark.
Attribute 4: Controlling/Dependent
Defines the relationship between attributes within items.
Attribute 5
Not used.
Attribute 6
Not used.
Attribute 7: Conversion
Any ACCESS conversion code used to format the contents of the attribute prior to output. Separate multiple conversion codes with value marks.
Attribute 8: Correlative
Any ACCESS correlative code used to format the contents of the attribute, or generate other output, prior to sorting. Separate multiple correlatives with value marks.
Attribute 9: Type
L
 
Output is displayed/sorted with left justification. Only use for attributes containing purely alphabetic data.
R Right justification display/sort. Use for all attributes other than pure alphabetics.
T
 
As “L” but if the output from the attribute is longer than the width (see below) then output is wrapped at the last space character.
U
 
As “L” but the output from the attribute is allowed to exceed the width specified below.
Attribute 10: Width
The maximum width to be used for output. If this is less than the length of the column header then the column header’s length is used. If this width is zero AND the column header only contains “” then no output is displayed when used in conjunction with ACCESS’ break-on modifier.


2. SYNTAX OF ACCESS STATEMENTS

ACCESS statements are of the following format. Mandatory parameters are in bold, optional parameters are in italics:

>VERB filename itemlist criteria modifiers outputlist (options)

Thus a statement can be as simple as:

>LIST MD

or as complex as:

>SORT SWANSEA-TIDES WITH DATE GE “31/12/93” AND WITH DATE LE “31/12/99” BY DATE BREAK-ON DATE TIME HEIGHT WATER ID-SUPP HEADING “Page ‘P5’ SWANSEA TIDES (KING’S DOCK, OUTER SILL) 1994 ‘TL’”

Note how literal strings within the statement must be enclosed in double quotes. Backslashes can also be used. If single quotes are used then ACCESS assumes the quantity enclosed thereby refers to an item-id.

The various components of the ACCESS statement are as follows:

VERB - The TCL command which informs ACCESS as to the type of processing required.

filename - The name of the file to process. Only one data file can be processed directly in an ACCESS statement although a different dictionary file can be used (i.e. not the data file’s dictionary file) by employing the “USING” modifier.

Itemlist - A specified list of item-ids surrounded by double/single quotes or backslashes.

Criteria - Criteria made up of tests (A-pointers, connectives etc) to selectively process a limited set of data. For example, the date range specified in the second statement above.

Modifiers - Special ACCESS commands to format the report to produce, for example subtotalling.

Outputlist - A list of A-pointers (words) whose data is to appear in the report. Note that if the sum of the widths of the A-pointers to be printed exceeds the width defined for the output device (screen or printer - see TERM command) then the report will not appear in columnar format but will use one line per A-pointer.

(Options) - The following options apply to most ACCESS verbs. They must be enclosed in parentheses. They also have wordier alternatives which are not enclosed in parentheses.

B Suppress the linefeed after the compile phase.
C Suppress column and default page header (see COL-HDR-SUPP).
D Suppress detail lines (see DET-SUPP).
F
 
Formfeed before every new item. Only applicable to LIST-ITEM, SORT-ITEM verbs.
H Suppresses default page header (see HDR-SUPP).
I Suppresses default item-ids (see ID-SUPP).
N Suppresses paging to terminal (see NOPAGE).
P Directs output to printer (see LPTR).
n
 
 
Limits the number of items processed by the command (i.e. LIST, SORT, SELECT etc) to the quantity n for Icon PICK etc. ADDS users should use the syntax L,n (see also the SAMPLING modifier section).

 

3. Wildcard Characters

To perform wildcard searches in ACCESS the following characters are used:

^ Any single character.
[Text ending with text.
Text] beginning with text.
[Text] containing text.

4. RETRIEVAL OF A-POINTERS

ACCESS performs two passes when looking for the A-pointers specified in the outputlist. The first pass looks in the current dictionary file. The second pass looks in the current MD. Thus A-pointers and any other ACCESS operators (such as throwaway connectives) applicable to all files within an account are stored in the MD. When an account is created the A-pointers *A0 to *A10 are created in its MD allowing access to the id and first 10 attributes of any item in any file in that account.

5. ACCESS COMMANDS

N.B.

1. The use of the terms “conversion” and “correlative” in this section is not arbitrary. Conversions work best in attribute 7, and correlatives best in attribute 8 of A-pointers. Thus T-correlatives are so called because they should be put in attribute 8. D-conversions should be put in attribute 7 etc.

2. ACCESS only performs integer mathematics - it ignores figures after the decimal point. Thus, data stored with the decimal point must be converted to integer format before being used in calculations (see F-correlative example 1). Also, data must not be converted back to decimal format until all calculations have been performed via integer format.

A (throwaway connective)
The word “A” can be used anywhere in an ACCESS statement to increase its readability. Such words are actually ignored by ACCESS itself.
A-conversion (arithmetic function)
A-conversions take exactly the same format as A-correlatives (see below) except that they are only applied in break (subtotal) lines and not in detail-lines. Similarly A-correlatives are only applied in detail-lines and not in break-lines. Whilst this distinction usually holds it does depend on what precisely your A-code is doing and how you are using it as to whether it should be a correlative or a conversion. Needless to say this can be very frustrating since only trial and error will produce the desired result.

For example when calculating averages, to print the average on the break-line, it is necessary to use an A-conversion and to total the quantity being averaged:

SALES ISALES AVERAGE.SALE
001
002
003
004
005
006
007
008
009
010
A
31
Sales
 
 
 
MR2
 
R
12
001
002
003
004
005
006
007
008
009
010
A
31
Integer]Sales
 
 
 
 
 
R
12
001
002
003
004
005
006
007
008
009
010
A
0
Average Sales
 
 
 
AN(ISALES)/ND]MR2
 
R
12

>SORT CUSTOMERS BY REGION BREAK-ON REGION TOTAL SALES AVERAGE.SALE (DI

(To print the average sales figure overall on the grand-total line then use TOTAL AVERAGE.SALE in the statement above.)

A-correlative (arithmetic function)
The A correlative is used to perform arithmetic functions and complex string manipulations on the data stored within an attribute. It takes the format of:

An;expression

where the optional parameter n supposedly specifies the number of decimal digits (0-4) to be retained during calculations (doesn’t work on any known version of PICK). The expression is made up of any of the following functions:

Operators: The following arithmetic operators are supported: +,-,*,/. Relational operators <,>,>=,<=,=,# are available to perform Boolean arithmetic.

Attribute Numbers: The data stored within an attribute is retrieved by specifying the attribute number within the A-correlative. For example, to add the contents of attribute 1 to attribute 2:

A1+2

Special attribute numbers for the current item are:

0 for the item-id
9998 for the number of the current item in the listing
9999 for the size in bytes.

 

Attribute Names: Any attribute name (the item-id of any word (A-pointer) in the current dictionary) can be used in an A-correlative. For example, to compute the invoice amount from the goods and VAT amounts:

AN(GOODS)+N(VAT)

Thus one A-correlative can call another word which itself can be an A-correlative (or any other type of word). The number of calls by words of other words cannot be more than 7 levels deep or an error message such as “RTN STACK FULL” will be given.

Literal Numbers/Strings: Literal number and strings are specified in either double or single quotation marks. For example, to multiply the contents of attribute three by ten:

A3*“10”

To build up the address as a comma delimited string:

AN(ADDR1);", ":N(ADDR2):", ":N(ADDR3):", ":N(ADDR4):", ":N(PC)

Special Operands: The following special operands can be used within A-correlatives exactly like any attribute number, attribute name or literal.

NI the item counter
NV the value counter
NS the subvalue counter
ND the detail-line counter
NB the break-level counter
LPV load previous value
D Current system date (days from 31.12.1967)
T Current system time (seconds from midnight)

MV Basics guide to the Access Query Language will continue in the Autumn 1998 issue of MultiValue News

MV Basics: The Access Query Language - Part 2


Last Updated: 6 November 1998

Home | | What's New | | News | | Articles | | Workspace | | Pick of the Web | | InfoCentre | | Parting Shots | | About Us | | Subscribe |