Structured Retrieval
The Structured Retrieval component retrieves data from the specified database resource, according to the user-supplied selection criteria, and makes the data available to the Procedure.
The Structured Retrieval component encapsulates the SQL query into a graphical shell that hides the intricacies of SQL programming from the end user; in its simplest form it takes the names of the database resource (table or view) and fields (table/view columns) to be retrieved, optionally adds selection criteria to narrow down the search, and executes the query.
When you introduce the Retrieval component into the Workspace from the Palette, it will be a simple object with two fields: the first field will accept the name of the target database table by selecting or drag-dropping it into the component; the second field (in the Get Field section) will receive the field name to be retrieved from the stated database table.
When the instructions associated with the Retrieval component are executed, it searches the target database table for matching records, according to the selection criteria and loads all found data for the specified fields into internal memory. These accumulated records are then loaded into the procedure variables (of Database field kind) incrementally, one record at a time in a looping sequence, controlled by the flowchart.
To utilize a Retrieval component, follow these steps:
Row processing
- Multiple rows
requires use of Next row? Conditional component (drag from Inspector);
- returns all rows of data as defined by the Retrieval component and based upon the Search criteria view;
- stores them in memory as a stack of data in the specified Sort order, if any; and
- steps through this stack of data, one at a time, from the top down.
- Single row
does not make use of the Next row? Conditional component. Attempts to return a single row of data based upon the Retrieval component and Inspector specifications. To test for success of retrieval, you can connect a Condition object and ask: X==EMPTY (where X is one of the fields being called for and EMPTY is a Constant in the Local Resources area of the Palette)- Distinct only
- returns all rows of data as defined by the Retrieval component and based upon the Search criteria view (but does not include any duplicate data as based upon the fields being retrieved). For the Single row retrieval with the aggregate functions (see below), modifies the function argument by adding "distinct" keyword to it, as in COUNT(distinct Amount).
- stores them in memory as a stack of data in the specified Sort order, if any; and
- steps through this stack of data, one at a time, from the top down.
- The Row Processing view also displays the:
Stop & Show
(a Retrieval feature available for use with Multiple Rows)returns all rows of data as defined by the Retrieval component, requested by the Multiple Rows, and based upon the Search criteria view;
stores them in memory as a stack of data in the specified Sort order, if any;
displays the stack of data in a window
lets the user select one or more displayed rows by clicking on them (to select multiple rows, hold Ctrl key down), effectively manually reducing the size of the stack. Selection of multiple rows is only possible if "Select many" radio button is checked:
steps through this reduced stack of data, one at a time, from the top down.
- Data retrieval loop
which consist of the Next row? Conditional draggable component and an example as to its usage. The use of the Data retrieval loop is mandatory when the Row processing option is not a Single row. To use this component: drag it into the procedure workspace and connect the Retrieval component to it. Connect the YES outlet to the chain of components that process the returned rows - then connect the tail end of the chain back to the Retrieval component. The NO outlet is connected to the component or chain of components that should be executed when no more rows are retrieved.
- Aggregate Functions
when retrieving data as a Single row, the Data retrieval loop area is replaced with a scrollable selection view. This view, with its separator cell Drag fields above this line, lists all fields included in the Retrieval component, which lend themselves to aggregate calculations (numeric and date fields). If one or more displayed fields are to be subjected to an aggregate calculation, drag those field names above the header text. Each field name row will be equipped with a pop-up list containing four aggregate options. These options are: SUM (total), MAX (maximum), MIN (minimum), AVG (average) and COUNT. Make the appropriate selection.
Search
The Search view of the Inspector acts as an additional filter, if desirable, for the Retrieval component (in the Workspace) which specifies the target database table and its specific field(s) for retrieval.
The Search view consists of a single scrollable view which shows all available fields, both user-defined and system fields, for the database table specified in the Retrieval component. To include a field in the Search, select the desired field and drag the field tile above the text header Drag fields above this line. Once dragging is complete, the field tile will display its four component parts:
- Field name;
- pop-up list of available Comparison Operators;
- run-time button;
- comparison value field.
See a more detailed explanation of some of the parts of the Inspector's Search view (as well as Sort and Expert)
Sort
Drag the desired field(s) above Drag fields above this line and set each line to ascending (arrow button up) or descending (arrow button down) order for simple or hierarchical sorts.
Expert
The Expert view displays the WHERE clause of the SQL SELECT statement generated by the graphical settings established by the Search and/or the Sort. The scrollable view is editable and the WHERE clause can be:
- modified, if generated; or,
- set up from scratch, effectively by-passing the graphical Search Criteria and/or the Sort Order views.
In addition, the Lock table feature can be invoked
You are now done with the Retrieval component. When executed, it searches the target database table for matching records, according to the selection criteria and loads all found data for the specified fields into internal memory. These accumulated records are then loaded into the procedure variables (of Database field kind) incrementally, one record at a time in a looping sequence, controlled by the flowchart.