Summary
Class RWDBSelector is used to specify data to be read from a database. It encapsulates all aspects of the SELECT statement used in SQL, including the relational concepts of projection, restriction, and join. Since selecting data returns a single table of results, it is convenient to view a selector as a short cut to a result table. Consequently, RWDBSelector can be provided wherever RWDBTable representing a result table is used.
RWDBSelector supports a lot of functionality, so it has many member functions and operators. A complete listing of these is in the SourcePro API Reference Guide. Selecting Data covered these important concepts:
*The insertion operator << is used to specify items to be selected, that is, a SELECT list. Use it multiple times to specify more than one item to select.
*In general, selectors can deduce the tables from which to select by examining the column references in the selected items and the WHERE criterion. For complex queries, manipulation of the FROM clause may be needed, and is provided by methods from(), fromClear(), fromGeneration(), fromExtern(), and fromExternClear().
*The where() method is used to specify a selection criterion, that is, the WHERE clause. A selector can have only a single selection criterion, but the criterion may be complex.
*RWDBSelector has an execute() method that returns an RWDBResult, which is expected to contain one table. It is usually more convenient to read the selected data by obtaining an RWDBReader directly from the selector.
*Outer joins can be specified either through the FROM method or the WHERE method of RWDBSelector, based on the capabilities of the database.
*Methods such as orderBy() and groupBy() apply SQL semantics to selectors, such as ORDER BY and GROUP BY clauses.
*To express self-joins, declare multiple instances of the same table. This is not expensive.
*A selector may be converted into an expression in order to express subquery semantics. When using subqueries, it may be necessary to use the fromExtern() method to declare tables as externally defined, as for correlated subqueries.