
Introduction
Queries/Cursors
A soup cursor is an object that iterates over entries in a soup. Cursors can:
- Retrieve the current entry
- Move forwards and backwards
- Do searches
You create a cursor by making a query. A query can specify an index, which controls the order in which the cursor iterates over entries. Within a query, you can also restrict by particular conditions, by specific text, or by index values that match a particular key. Using restricted queries, here are some examples of the way you can iterate a cursor:
- To entries that contain the word "Julie" in some slot
- Through the entries based on the value in an indexed slot
- Entries that have an even number of slots
- Entries whose
name
slot starts with 'K'
When you make a query, the system does not go out and create a list of entries which satisfy the query. Among other reasons, there might not be enough memory to do so. Instead, the conditions in the query are evaluated each time you make a call to the cursor. All a cursor knows about is its soup, the entry it is currently on, and the conditions of the query.
One of the neatest things about cursors is their dynamic nature. For instance, if you've created a cursor that iterates over names beginning with 'K' and insert a card, the cursor will now also include those names on the card beginning with a 'K'. This means the next item the cursor iterates to may change, as shown in FIGURE 9.8.

FIGURE 9.8 : A dynamic cursor iterating over entries whose name begins with 'K'.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996