SELECT, SELECTN, SELECTV |
![]() ![]() ![]() |
The SELECT statement creates a select list containing all record keys from a file.
Format
SELECT var {TO list.no} {ON ERROR statement(s)} SELECTN var {TO list.no} {ON ERROR statement(s)} SELECTV var TO list.var {ON ERROR statement(s)}
where
The SELECT and SELECTN statements construct a list of record keys in the file open as var and store this as an active select list list.no replacing any previously active list. If there are no records in the file, an empty list is created.
|The SELECTV statement constructs the list in the same way but stores it in a select list variable which can be processed by a subsequent use of READNEXT.
For compatibility with other database products, the action of the SELECT statement can be changed to produce a select list variable in the same was as SELECTV. This is achieved by setting the SELECTV option of the $MODE compiler directive.
The QMBasic SELECT statement uses an optimised method for processing hashed files such that each group is examined only when the record keys are extracted from the select list. This reduces disk transfers and gives better application performance than constructing the entire list in one operation. This benefit does not apply to SELECTV. This overlapping of processing with record selection means that, if the application writes new records while the select list is being processed, these new records may be seen later in the operation.
It is important that a program that does not completely process a select list should use CLEARSELECT to clear the remainder of the list. While the list is active, split and merge operations are suspended on the data file. Thus, leaving a list active may cause the file performance to degrade if updates are made. Note that the file will automatically reconfigure for optimum performance once the select operation has terminated.
The @SELECTED variable is set to the number of records selected for a directory file or the number of records in the first non-empty group for a dynamic file.
The optional ON ERROR clause is executed in the event of a fatal error. This covers such situations as disk hardware errors and faults in the internal structure of the file. The STATUS() function will return a value relating to the cause of the error. If no ON ERROR clause is present, a fatal error will result in an abort.
Except where the ON ERROR clause is taken, the STATUS() function will return zero.
Use of a Dynamic Array instead of a File Variable
For compatibility with Pick style environments, QM also supports a variation on these statements where the var is a dynamic array in which each field becomes an entry in the target select list.
Example
SELECT STAFF TO 7
This statement creates a list of the records on the file with file variable STAFF and saves it as active select list 7. |