The contents of fields from a database file are retrieved in the same way as
from within a text body using the %
operator which must be immediately
followed by the name of the field (always in upper case). A field reference is
by default made to the current database and current record of that database.
All the various modes of the %
operator are described below. Note that
there is no way to change the contents of a field, database files cannot be
altered with the grg
program.
The %
operator gets the contents of the field from the current record
of the current database.
The %%
operator gets the name of the field. This is similar to but
not identical to just quoting the field name.
The %#
operator gets the length of the field. This is the defined
maximum length in characters.
The %$
operator gets the type of the field This is a one character
string which will be C
(character/string), N
(numeric), D
(date), L
(logical), or M
(memo) although this last type is not
supported as a data type.
The given field name can be more complex than a simple name to support
referencing more that one database file and direct record indexing within that
database file. The syntax of this is given below using the get field operator
%
as an example although any of the field operators above accept the
same syntax variants.
The %field
syntax just gets the value of the field
from the
current record and is the default syntax given above.
The %field[index]
syntax gets the value of the field
from
the record with the given index
(record indecies go from one to the number of
records in the database).
The %database->field
syntax gets the value of the field
from the
current record of the given database
(name should match that given when the
database file was declared using the DATABASE predefined macro
without the pathname or extension).
The %database->field[index]
syntax gets the value of the
field
from the record with the given index
of the given
database
.
The index
can be a simple numeric literal or any normal expression that
returns a numeric value (which must be greater than or equal to 1
and
less than or equal to the total number of records in the database
). There should be no whitespace in the above syntax forms
except where the index
is a more complex expression which can include
whitespace if neccessary.
The above syntax forms all bypass any active filters. The current record forms when referring to a database other than the master database will always refer to the first record of that database.
Here are some examples of field referencing from an equate.
%NAME >> s1 %CATS->NAME + %CATS->TYPE >> s2 1 >> a %DOGS->NAME[2+a] >> s3
The first example gets the contents of the NAME
field from the current
record of the current database (the current database is always the master
database unless operating under a roll ... through
loop through another database). The
second example gets the contents of the NAME
and TYPE
fields of the
current record in the cats
database, adds them together and assigns the
result to the s2
variable (the two fields must have the same data type).
The last example gets the contents of the NAME
field of the 3rd record in
the dogs
database and assigns the value to the s3
variable.
Go to the first, previous, next, last section, table of contents.