Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWDBSelector


RWDBSelector RWDBSelectorBase

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/db/select.h>

RWDBSelector select = myDbase.selector();

Description

RWDBSelector is an encapsulation of an SQL SELECT statement. Its methods provide an application with explicit control over the SELECT statement's select list, as well as its FROM, WHERE, ORDER BY, and GROUP BY clauses. The set operators +, *, and - (union, intersection, and difference) may be applied to RWDBSelectors in order to achieve the semantics of the SQL UNION, INTERSECTION, and DIFFERENCE operations. See the entry for RWDBCompoundSelector. An RWDBSelector may be used to instantiate an RWDBExpr, so subqueries are also supported. See the entry for RWDBExpr.

The insertion operator << is used to add items to an RWDBSelector select list; the where() method is used to specify a WHERE clause. The items which are inserted into an RWDBSelector are RWDBExprs, which may be any combination of constants, column references, predefined functions, or RWDBSelectors combined by arithmetic or functional operators. The WHERE clause is encapsulated by an RWDBCriterion, which is some number of RWDBExprs combined with logical operators.

The result of an SQL SELECT statement is an SQL table expression. DBTools.h++ represents this concept as a ResultTable. Hence, the following are equivalent:

RWDBSelector also derives from RWDBSelectorBase so that RWDBSelector and RWDBCompoundSelector may be handled in a uniform manner.

RWDBSelector is designed around the Interface/Implementation paradigm. An RWDBSelector instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation. An RWDBSelector implementation is a base class from which a family of database-specific selector implementations is derived.

Most RWDBSelector methods return a reference to self. This allows calls to be stacked, as in:

Example 1

Assuming that dBase is a valid RWDBDatabase, we can encapsulate the SQL statement:

as follows:

Notice that it is not necessary to specify the FROM clause. DBTools.h++ deduces what tables to select from the column references in the select list; it generates a member of the FROM clause for each unique table reference. You can override this behavior by using the from() member function.

Assuming that the name and city columns mentioned above are strings, we would read the results of our query like this:

Example 2

To introduce multiple instances of a table into an encapsulated SELECT statement, declare additional RWDBTable instances. The fragment:

SELECT a.name, b.type from myTable a, myTable b

can be captured as in the following example:

Note that the instantiations of aTable and bTable do not require database access, so this technique does not incur excessive overhead.

Example 3

This example introduces the binding of application variables within a WHERE clause of a SELECT statement. This allows an application to repeatedly execute the RWDBSelector without clearing and constructing the WHERE clause each time. The following example uses an AutoParts table in the database, with text column name and integer column id:

Public Constructors

RWDBSelector();
RWDBSelector(const RWDBSelector& select);

Public Member Operators

RWDBSelector& 
operator=(const RWDBSelector& select);
RWDBSelector&
operator<<(RWDBValueManip& manip);
RWDBSelector& 
operator<<(const RWDBExpr& expr);
RWDBSelector& 
operator<<(const RWDBTable& table);
RWDBColumn
operator[](const RWCString& name) const;
RWDBColumn
operator[](size_t position) const;

Public Member Functions

virtual RWCString
asString() const;
RWDBBulkReader
bulkReader(const RWDBConnection& conn);
RWDBStatus
clear();
RWDBColumn
column(const RWCString& name) const;
RWDBColumn
column(const RWCString& name,
             RWCString::caseCompare casecompare);
RWDBColumn
column(size_t index) const;
RWDBCursor
cursor(RWDBCursor::CursorType type = RWDBCursor::Sequential,
       RWDBCursor::CursorAccess access = RWDBCursor::Read) 
       const; 
RWDBCursor
cursor(const RWDBConnection& connection, 
       RWDBCursor::CursorType type = RWDBCursor::Sequential,
       RWDBCursor::CursorAccess access = RWDBCursor::Read) 
       const; 
RWDBCursor
cursor(const RWDBSchema& updateCols, 
       RWDBCursor::CursorType type = RWDBCursor::Sequential,
       RWDBCursor::CursorAccess access = RWDBCursor::Read) 
       const; 
RWDBCursor
cursor(const RWDBSchema& updateCols, 
       const RWDBConnection& connection,
       RWDBCursor::CursorType type = RWDBCursor::Sequential,
       RWDBCursor::CursorAccess access = RWDBCursor::Read) 
       const;
RWDBDatabase
database();
RWDBCompoundSelector&
difference(const RWDBSelectorBase& selector) const;
RWDBSelector&
distinct(RWBoolean Distinct = TRUE);
RWDBResult
execute();
RWDBResult
execute(const RWDBConnection& connection);
virtual RWBoolean 
fetchSchema();
virtual RWBoolean
fetchSchema(const RWDBConnection& connection);
RWDBSelector&
from(const RWDBJoinExpr& jexpr);
RWDBSelector&
from(const RWCString& tableName);
RWDBSelector&
from(const RWDBTable& table);
RWDBSelector&
fromClear();
RWDBSelector&
groupBy(const RWDBColumn& column);
RWDBSelector&
groupBy(int columnNumber);
RWDBSelector&
groupByClear();
RWDBSelector&
having(const RWDBCriterion& criterion);
RWDBCompoundSelector&
intersection(const RWDBSelectorBase& selector) const;
RWDBSelector&
into(const RWCString& tableName);
RWBoolean
isValid();
RWDBSelector&
on(const RWDBColumn& column);
RWDBSelector&
on(const RWDBCriterion& criterion);
RWDBSelector&
orderBy(const RWDBColumn& column);
RWDBSelector&
orderBy(int columnNumber);
RWDBSelector&
orderByClear();
RWDBSelector&
orderByDescending(const RWDBColumn& column);
RWDBSelector&
orderByDescending(int columnNumber);
RWDBReader
reader(size_t cache=0) const;

NOTE:When cache is 0, an acceptable default is selected by your access library. Please check your access library documentation for limitations on the cache size.
RWDBReader
reader(const RWDBConnection& connection,
       size_t cache=0) const;

NOTE:When cache is 0, an acceptable default is selected by your access library. Please check your access library documentation for limitations on the cache size.
RWDBSchema
schema() const;
RWDBSelector&
select(const RWDBExpr& expr);
RWDBSelector&
select(const RWDBTable& table);
RWDBSelector&
selectClear();
RWDBStatus
status();
RWDBCompoundSelector&
union_ (const RWDBSelectorBase& selector) const;
RWDBCompoundSelector&
unionAll(const RWDBSelectorBase& selector) const;
RWDBCriterion
where() const;
RWDBSelector&
where(const RWDBCriterion& criterion);

Related Global Operators

RWDBCompoundSelector
operator+(const RWDBSelectorBase& left,
          const RWDBSelectorBase& right);
RWDBCompoundSelector
operator-(const RWDBSelectorBase& left,
          const RWDBSelectorBase& right);
RWDBCompoundSelector
operator*(const RWDBSelectorBase& left,
          const RWDBSelectorBase& right);


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.