You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Much activity that programmers associate with select list processing -- initializing select lists (cursors), fetching record keys, sorting, and selecting (reducing) -- is done not by the filing system, but by special SELECT and READNEXT processors.

These processors, a set of system programs that provide a layer between BASIC+ and the filing system, are the master controllers for select list processing. It is only under the control of these processors that BASIC+ will access the filing system for SELECT and READNEXT processing.

The special SELECT and READNEXT processors automatically take care of the more complex aspects of select list processing such as sorting or reducing. In comparison, the filing system SELECT and READNEXT calls are relatively simple. In most cases, they simply return a group of record keys or records, as directed by the higher-level SELECT and READNEXT processors. Decisions about placing record keys in cursors or sorting blocks of records for extended SELECT logic are made by the special processors.

As a rule, MFS programmers do not need to concern themselves with these esoteric aspects of select list processing. In some cases -- for instance, in SI.MFS -- the MFS deliberately assumes control over specific tasks (in this case, returning sorted key lists). However, an MFS that does not concern the return of a sorted or reduced key list does not need to include logic for these tasks.

Simple (Latent) Select

In BASIC+, a simple SELECT statement  (not an extended SELECT ... BY statement) does not directly produce a list of record keys for processing. Instead, the SELECT statement simply initializes variables in the system, indicating that a select condition is active.

In addition, the SELECT is passed to the filing system so it can perform any filing system-specific activity to initialize a select condition.  A filing system SELECT call returns a select mode with three possible values in the RECORD argument:

Select Mode

Meaning

0

No select list is active (disable the select)

1

Latent file select

2

Latent index select

 

 If a select condition is active, subsequent BASIC+ READNEXT statements will return record keys until the file has been exhausted. If no select list is active, a subsequent BASIC+ READNEXT statement will fall through its ELSE branch.

The select mode value is available to an BASIC+ program in the system variable @LIST.ACTIVE.  If the SELECT call fails for any reason, the RECORD argument is passed back false, indicating to the system that no select list is active.  @LIST.ACTIVE will also be set to false.

This BASIC+ program fragment illustrates the typical flow of a simple SELECT:

 

SELECT FILE ; * establish "latent" select
DONE = 0
LOOP
  READNEXT @ID ELSE DONE = 1
  UNTIL DONE DO
    /* process the row */
REPEAT

ReadNext Processing

Once a select condition is established (select mode is true), the system can use a READNEXT command to return record keys from the select list. In BASIC+, READNEXT is used to return a single key from the select list.  In a filing system, however, a READNEXT call returns an entire block of keys.

When a READNEXT operation is being performed at the BASIC+ level, requests for record keys are processed by the READNEXT processor. The processor maintains a system list variable (cursor) for currently active keys. When a program first executes an BASIC+ READNEXT, this list variable is typically empty.

If the list variable is empty, the READNEXT processor generates a filing system READNEXT operation. The filing system READNEXT returns a block of keys, which the processor stores in the system list variable.

The READNEXT processor satisfies requests for individual record keys from this list variable. When the READNEXT processor reaches the end of the list of keys in the list variable, the READNEXT processor generates another BFS READNEXT call. The filing system READNEXT call returns the next block of keys, which replaces the keys in the system list variable. A BASIC+ READNEXT command may thus execute many times before causing the READNEXT processor to execute a filing system READNEXT operation.

This cycle of filling the list variable, exhausting it, and generating a new filing system READNEXT operation continues until the filing system READNEXT indicates that there are no more blocks of keys in the file. At that point, the filing system READNEXT sets the status argument to false. This causes the BASIC+ READNEXT operation to fall through its ELSE logic.

In order to track its progress through the file, the filing system READNEXT operation maintains a select pointer. This is a type of handle that contains the information that the filing system READNEXT requires in order to fetch the next block of keys properly. A simple select pointer might contain a pointer to the next block or group of keys to be fetched. As each filing system READNEXT operation is called, the select pointer is incremented.

An MFS should not disturb a select pointer for which it is not responsible. Doing so can cause severe errors in the key blocks returned by a filing system READNEXT operation, or can result in logical read errors in the file.

READNEXT Direction

When a filing system READNEXT call is made, the status argument is used to pass to the filing system the direction of the READNEXT operation (ascending or descending). The filing system uses this direction in maintaining the select pointer. If the BASIC+ READNEXT operation designates the select list as descending, the select pointer is decremented with each filing system READNEXT operation, rather than being incremented for an ascending READNEXT.

  • No labels