Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
DB Interface Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

RWDBSelector

Module:  DB Interface Module   Group:  Data Manipulation Classes


RWDBSelector RWDBSelectorBase

Local Index

Members

Non-Members

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. The DB Interface Module 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:

select.where(...).orderBy(...).groupBy(...), etc.

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. The DB Interface Module 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(), fromGeneration(), and fromExtern() member functions

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 Enum

enum FromGeneration { ExplicitOrImplicit, ExplicitAndImplicit };

Public Member Functions

RWCString
asString() const;

NOTE -- When the RWDBDatabase::verboseAsString() option is set to true, the SQL returned by this method may not be a valid SQL statement. However, this method's return value is not necessarily the same SQL that is sent to the database for execution. For example, if an RWDBBlob object is bound, calling asString() with RWDBDatabase::verboseAsString() set to true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.

RWCString asString(bool verbose) const;

NOTE -- The SQL returned by this method when verbose is true may not be a valid SQL statement. However, this is not necessarily the same SQL sent to the database for execution. For example, if an RWDBBlob object is bound, calling asString(true) will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
RWCString
asString(const RWDBConnection& conn) const;

NOTE -- When the RWDBDatabase::verboseAsString() option is set to true, the SQL returned by this method may not be a valid SQL statement. However, this method's return value is not necessarily the same SQL that is sent to the database for execution. For example, if an RWDBBlob object is bound, calling asString() with RWDBDatabase::verboseAsString() set to true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.

RWCString asString(const RWDBConnection& conn, bool verbose) const;

NOTE -- The SQL returned by this method when verbose is true may not be a valid SQL statement. However, this is not necessarily the same SQL sent to the database for execution. For example, if an RWDBBlob object is bound, calling asString(true) will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
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(bool Distinct = true);
RWDBResult
execute();
RWDBResult
execute(const RWDBConnection& connection);
virtual bool 
fetchSchema();
virtual bool
fetchSchema(const RWDBConnection& connection);
RWDBSelector&
from(const RWDBJoinExpr& jexpr);
RWDBSelector&
from(const RWCString& tableName);
RWDBSelector&
from(const RWDBTable& table);
RWDBSelector&
fromClear();
RWDBSelector&
fromExtern(const RWDBTable& table);
RWDBSelector&
fromExternClear();
RWDBSelector&
fromGeneration(FromGeneration flag);
FromGeneration
fromGeneration() const;
RWDBSelector&
groupBy(const RWDBColumn& column);
RWDBSelector&
groupBy(const RWDBExpr& expr);
RWDBSelector&
groupBy(int columnNumber);
RWDBSelector&
groupByClear();
RWDBSelector&
having(const RWDBCriterion& criterion);
RWDBCompoundSelector&
intersection(const RWDBSelectorBase& selector) const;
RWDBSelector&
into(const RWCString& tableName);
bool
isValid();
RWDBSelector&
on(const RWDBColumn& column);

NOTE -- This method is deprecated and will be eliminated in a later release. Instead, use the similar on()method in RWDBJoinExpr to attach a join condition to a specific join.
RWDBSelector&
on(const RWDBCriterion& criterion);

NOTE -- This method is deprecated and will be eliminated in a later release. Instead, use the similar on()method in RWDBJoinExpr to attach a join condition to a specific join.
RWDBSelector&
orderBy(const RWDBColumn& column);
RWDBSelector&
orderBy(const RWDBExpr& expr);
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 Module. Please check your Access Module 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 Module. Please check your Access Module documentation for limitations on the cache size.
RWDBSchema
schema() const;
RWDBSelector&
select(const RWDBExpr& expr);
RWDBSelector&
select(const RWDBTable& table);
RWDBSelector&
selectClear();
void
setErrorHandler(RWDBStatus::ErrorHandler handler);
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 DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.