RetrieVe and SQL both use a command called SELECT
. They are not related. UniVerse can tell whether you are executing a RetrieVe or a SQL SELECT
by analysing the syntax of the overall command: they are formed quite differently, and do different things, All the examples below are RetrieVe SELECT
commands.
The SELECT
command creates a list of keys 'in memory' which is then used by the next command you execute. Much of its syntax is the same as that for the LIST
command (see Listing Records). It supports the same WITH
, BY
and SAMPLE
keyswords. For instance:
>SELECT COPY.OF.VOC SAMPLE 3
3 record(s) selected to SELECT list #0.
>>
So what has happened here? Well, three keys from the COPY.OF.VOC
file are now stored in a select list. Note the prompt is now >>
instead of the usual >
: this is a reminder that the command you are about to type in will be using a select list.
To see what effect this has, try the following command:
>>LIST COPY.OF.VOC
LIST COPY.OF.VOC 14:00:33 08-19-99 PAGE 1 VOC......... F9 PRINT.ADMIN TEST.PARAGRA PH 3 records listed. >
This LIST
command would normally have displayed all the records in the file: but because there was (in UniVerse jargon) an 'active select list' of three keys, it displayed only those three records.
So what is the point of this? You could have achieved the same thing more easily by typing LIST COPY.OF.VOC SAMPLE 3
.
Firstly, LIST
is not the only command which responds to select lists. For instance, if you wished to edit a number of records, you could first create a select list containing their keys, and then use ED
like this:
>SELECT COPY.OF.VOC SAMPLE 3
3 record(s) selected to SELECT list #0.
>>ED COPY.OF.VOC
SELECTed record name = "F9".
6 lines long.
----:
What has happened here? Well, ED
has spotted the select list, and so has begun by using the first key from that list to open a record. As soon as you abandon or file the current record, the editor will open the next record in the select list, and so on until it runs out of keys and prompts you to enter the next. Try it:
----: Q
SELECTed record name = "PRINT.ADMIN".
2 lines long.
----:
Two new commands become available within ED
when you are using it with a select list in this way. The first, N
, simply moves to the next record in the list without saving the current one (much as Q
does, so I'm not entirely sure of the point to this command), while X
leaves the editor altogether, regardless of the number of keys left in the select list. Use this to exit this example.
Most commands which operate on individual records will respond to select lists. The compiler BASIC
will compile all the records (programs) in a select list, DELETE
will delete them all, COPY
will copy them all, and so on. You'll learn about these commands during our discussion of the TCL command language later.
Also, the UniVerse Basic programming language contains statements to read the keys from select lists, and so it is possible to write programs which are designed to be run once a select list is in memory, and thus can be applied to any group of records the user requires.
One of the commands which will automatically work from an active select list is the SELECT
command itself. This effectively means that by issuing a series of SELECT
commands, the various lists produced can be intersected. For instance, to create a select list of three sampled M
type COPY.OF.VOC
records, try:
>SELECT COPY.OF.VOC WITH TYPE = 'M'
9 record(s) selected to SELECT list #0.
>>SELECT COPY.OF.VOC SAMPLE 3
3 record(s) selected to SELECT list #0.
>>LIST COPY.OF.VOC TYPE
LIST COPY.OF.VOC TYPE 14:52:46 08-19-99 PAGE 1
VOC......... TYPE
CONV.ACCT.ME M
NU
PRINT.ADMIN. M
MENU
BASIC.CONT M
3 records listed.
>
Of course, the same select list could have been built in one step by using the clause WITH TYPE = 'M' SAMPLE 3, but such simplification is not always easy, or even possible. Where it isn't, this intersecting behaviour is useful.
The examples above showed the use of the 'default' select list. In fact, UniVerse allows each user to store up to ten select lists, numbered 0 to 9. The default is number 0, and if the select command is specified without a select list number, the results are loaded into 0. To load a different numbered select list, use the TO
keyword, as here:
>SELECT COPY.OF.VOC SAMPLE 3 TO 1
3 record(s) selected to SELECT list #1.
>>
Note that this time, the command prompt has not become >>
as it did before. This is because only the default select list, list 0, will automatically be picked up by the following commands. The numbered select lists can be accessed by UniVerse Basic statements, and a few other commands which take select list number parameters, and are therefore used less often.
If you wish to, you can save your select list for use in the future. One advantage of this is that you can then use it more than once without the overhead of reselecting the records which make it up. To save a select list, use the command SAVE.LIST
:
>SELECT COPY.OF.VOC SAMPLE 3
3 record(s) selected to SELECT list #0.
>>SAVE.LIST MYLIST
3 record(s) SAVEd to SELECT list "MYLIST".
>
The keys are actually written to a record called MYLIST
in the file &SAVEDLISTS&
: you may remember that this was one of the three UniVerse files created automatically when you first created your UniVerse account, along with VOC
and VOCLIB
. You can even look at the record with the editor:
ED &SAVEDLISTS& MYLIST
3 lines long.
----: P
0001: F9
0002: PRINT.ADMIN
0003: TEST.PARAGRAPH
Bottom at line 3.
----: Q
>
As you can see, it is a simple list, with each field bearing a key. In fact, you can create your own 'saved lists' using ED
without ever issuing a SELECT
command just by creating a record in &SAVEDLISTS&
.
To activate your saved list, use the command GET.LIST
:
>GET.LIST MYLIST
3 record(s) selected to SELECT list #0.
>>
Finally, you can clear a list you don't plan to use with the CLEARSELECT
command:
>CLEARSELECT
SELECT list number 0 cleared.
Any of these commands can be used with numbered select lists too, by using the forms:
SAVE.LIST listname FROM listnumber
GET.LIST listname TO listnumber
CLEARSELECT listnumber