SQLphone tutorial topics

previous topic | tutorial menu | next topic


2.5   How to iterate multiple database records

This tutorial shows how to fetch many records from a database, by forming a flowchart loop around a SQL Box.

This is an advanced tutorial, it does not contain step-by-step instructions on how to build a flowchart. Instead, it describes a sample flowchart which loops though records fetched by a database query. You should be familiar with SQLphone flowcharting techniques, before examining this flowchart.

1.  Sample Flowchart
Click here to download the sample flowchart for this topic. To install the sample, create a directory C:\Phone, unzip the sample files into this directory, and follow the instructions in the unzipped ReadMe file. The flowchart does this:

2.  How the loop works
The key to the loop, is the use of the CurrentID memory. When the flowchart starts, this memory always has value 0.

The SQL-Box executes the following Select statement:

  select ID as ?CurrentID, Color + '.wav' as ?ColorWav
  from Color
  where Type = $Type
  and ID > $CurrentID
  order by ID

This will fetch the next (single) record which has an ID (primary key) larger than the CurrentID memory value. Now comes the important bit: the ID fetched for this record is stored in the CurrentID memory, overwriting its old value. The next time this SQL-Box is run, it will fetch the next record in the ID sequence, etc.


previous topic | tutorial menu | next topic