General:. Record Sets in
Glee are like tables of structures in other languages. A record
set is composed of two objects: (1) a sequence of records(which are sequences
of fields) and (2) field list (naming fields within records). It can be viewed
as a table with named columns. There are facilities for creating the record
set; defining its fields; populating its records; adding, deleting, and
renaming fields; replacing and deleting records; and retrieving by field, by
record, or by combination of both. Glee record sets do not impose
a discipline. They merely provide a mechanism for naming and thereby referring
to elements of a record sequence. For example, you can put string data where
numerics belong and the record set does not debate. Glee will,
however, assure that there is a correspondence between the field names and the
fields in all the records. On entry, it scans all data for conformance and
rejects all or accepts all. Use of Record Sets can make programs more readable.
Create Record Set
(#RS): The niladic operator "#RS" creates a
record set with no fields and no records. You can assign this to a variable
which can then be the target for populating the record set. This record set
contains no fields and no records. It is simply an object with and empty field
list object and record sequence containing no elements.
Add fields to new record
set: You can add fields at any time. Glee checks to be sure
the field your adding is not already part of the record set object. If it is, a
diagnostic is given. If not, the field is appended to the field list for the
record set. If the record set contains records, new items are appended to each
record. These items are a null objects.
Add Records: Data records
are added to record sets by assigning to an empty record set index. This is the
same method we used for adding fields. When you append new records to the
record set using null indexing (i.e. []) the field order of the record
set is assumed. This can be obtained using the .fields property for
the record set (e.g. rs.fields).
Rearranging and deleting
fields in a record set: Record set fields are maintained in the order in
which they are supplied. New fields are appended to the field list. If you want
to change this order or remove fields, you do so by field indexing into the
record set. This creats a new record set in the new order. You can then replace
the existing record set with it. Record sets are just collections of pointers.
However, when you rearrange fields, you are rearranging the elements of the
record sequences as well. If the record set is very large, this is probably not
a good idea. Records sets should probably not be allowed to grow to great size.
They are intended for managing small tables of data.
Create with field list: It
is common to create the record set with its initial complement of fields rather
than to add fields later.
Get Fields: When you get
information from a record set you are given a completely new record set.
Typically you'll only be interested in the records part (presumably you already
know everything about the fields part). See the next example for how to get
just the records part.
The .recs and
.fields properties: Typically when working with the data in the
record set, you only want the "sequence of records" part. The
".recs" property returns this. If you want the field list
part, the ".fields" returns that. These are not references.
You can't change data in this result and expect it to change in the original
record set.
Addressing: Addressing in
record sets can be by record(s); by field(s); or by a combination as shown
here. When using the combination specify the field(s) together (in the order
you want) t the record number(s) (in the order you want). It doesn't matter
which order you use.