SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions | Related Functions
RWDBSelector Class Reference

Encapsulates the SQL SELECT statement. More...

#include <rw/db/select.h>

Inheritance diagram for RWDBSelector:
RWDBSelectorBase

Public Types

enum  FromGeneration { ExplicitOrImplicit, ExplicitAndImplicit }
 

Public Member Functions

 RWDBSelector ()
 
 RWDBSelector (const RWDBSelector &select)
 
RWCString asString () const
 
RWCString asString (const RWDBConnection &conn) const
 
RWCString asString (bool verbose) const
 
RWCString asString (const RWDBConnection &conn, bool verbose) const
 
RWDBBulkReader bulkReader (const RWDBConnection &conn) const
 
RWDBStatus clear ()
 
RWDBColumn column (size_t index) const
 
RWDBColumn column (const RWCString &name) const
 
RWDBColumn column (const RWCString &name, RWCString::caseCompare caseCompare) 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 () const
 
virtual RWDBCompoundSelector difference (const RWDBSelectorBase &selector) const
 
RWDBSelectordistinct (bool logic=true)
 
RWDBResult execute ()
 
RWDBResult execute (const RWDBConnection &connection)
 
bool fetchSchema ()
 
bool fetchSchema (const RWDBConnection &connection)
 
RWDBSelectorfrom (const RWCString &tableName)
 
RWDBSelectorfrom (const RWDBTable &table)
 
RWDBSelectorfrom (const RWDBJoinExpr &jExpr)
 
RWDBSelectorfromClear ()
 
RWDBSelectorfromExtern (const RWDBTable &table)
 
RWDBSelectorfromExternClear ()
 
RWDBSelectorfromGeneration (FromGeneration flag)
 
FromGeneration fromGeneration () const
 
RWDBSelectorgroupBy (const RWDBColumn &column)
 
RWDBSelectorgroupBy (const RWDBExpr &expr)
 
RWDBSelectorgroupBy (int columnNumber)
 
RWDBSelectorgroupByClear ()
 
RWDBSelectorhaving (const RWDBCriterion &criterion)
 
virtual RWDBCompoundSelector intersection (const RWDBSelectorBase &selector) const
 
RWDBSelectorinto (const RWCString &tableName)
 
bool isValid () const
 
RWDBSelectoron (const RWDBCriterion &criterion)
 
RWDBSelectoron (const RWDBColumn &column)
 
RWDBSelectoroperator<< (RWDBValueManip manip)
 
RWDBSelectoroperator<< (const RWDBExpr &expr)
 
RWDBSelectoroperator<< (const RWDBTable &table)
 
RWDBSelectoroperator= (const RWDBSelector &select)
 
RWDBColumn operator[] (const RWCString &name) const
 
RWDBColumn operator[] (size_t position) const
 
RWDBSelectororderBy (const RWDBColumn &column)
 
RWDBSelectororderBy (const RWDBExpr &expr)
 
RWDBSelectororderBy (int columnNumber)
 
RWDBSelectororderByClear ()
 
RWDBSelectororderByDescending (const RWDBColumn &column)
 
RWDBSelectororderByDescending (int columnNumber)
 
RWDBReader reader (size_t cacheSize=0) const
 
RWDBReader reader (const RWDBConnection &connection, size_t cacheSize=0) const
 
RWDBSchema schema () const
 
RWDBSelectorselect (const RWDBExpr &expr)
 
RWDBSelectorselect (const RWDBTable &table)
 
RWDBSelectorselectClear ()
 
void setErrorHandler (RWDBStatus::ErrorHandler handler)
 
RWDBStatus status () const
 
virtual RWDBCompoundSelector union_ (const RWDBSelectorBase &selector) const
 
virtual RWDBCompoundSelector unionAll (const RWDBSelectorBase &selector) const
 
RWDBCriterion where () const
 
RWDBSelectorwhere (const RWDBCriterion &criterion)
 

Related Functions

(Note that these are not member functions.)

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

Detailed 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 RWDBSelector objects 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 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 RWDBExpr objects, which may be any combination of constants, column references, predefined functions, or RWDBSelector objects combined by arithmetic or functional operators. The WHERE clause is encapsulated by an RWDBCriterion, which is some number of RWDBExpr objects combined with logical operators.

The result of an SQL SELECT statement execution is an SQL table expression. The DB Interface Module represents this concept as a ResultTable. Hence, the following are equivalent:

(1) RWDBReader rdr = selector.execute().table().reader();
(2) RWDBReader rdr = selector.reader();

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.
Synopsis
#include <rw/db/select.h>
RWDBSelector select = myDbase.selector();
Example

Example1

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

SELECT myTable.name, yourTable.city FROM myTable,
yourTable WHERE myTable.key = yourTable.key

as follows:

RWDBTable myTable = dBase.table("myTable");
RWDBTable yourTable = dBase.table("yourTable");
RWDBSelector select = dBase.selector();
select << myTable["name"] << yourTable["city"];
select.where(myTable["key"] == yourTable["key"]);

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:

RWDBReader rdr = select.reader();
RWCString name;
RWCString city;
while(rdr()) {
rdr >> name >> city;
// process the name and city
}

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:

RWDBTable aTable = myDbase.table("myTable");
RWDBTable bTable = myDbase.table("myTable");
RWDBSelector select = myDbase.selector();
select << aTable["name"] << bTable["type"];

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:

RWDBTable partsTable = myDbase.table("AllParts");
RWDBConnection connection = myDbase.connection();
RWDBSelector select = myDbase.selector();
int id = 1001;
select << partsTable["name"];
select.where( partsTable["id"] == RWDBBoundExpr(&id) );
RWDBReader reader = select.reader(connection);
// process reader...
id = 2001;
reader = select.reader(connection);
// process reader...

Member Enumeration Documentation

A class-scoped enum presents different behaviors that can be used to compose the FROM clause. It is used in the fromGeneration() methods. Please refer to the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide, for detailed information.

Enumerator
ExplicitOrImplicit 

If there are any explicit from() entries, uses only those to generate the FROM clause, otherwise uses only implicit entries.

ExplicitAndImplicit 

Combines the implicit and explicit entries to generate the FROM clause, removing duplicate entries.

Constructor & Destructor Documentation

RWDBSelector::RWDBSelector ( )

The default constructor creates an RWDBSelector whose status is RWDBStatus::notInitialized. This constructor is provided as a convenience, for example, for declaring an array of RWDBSelector objects. Usable RWDBSelector instances are obtained from RWDBDatabase.

RWDBSelector::RWDBSelector ( const RWDBSelector select)

Copy constructor. The created object shares an implementation with select.

Member Function Documentation

RWCString RWDBSelector::asString ( ) const
inline

Returns the SQL equivalent of:

SELECT <column-list> FROM <from-list>
WHERE <where-clause> GROUP BY <groupby-list>
HAVING <having-clause> ORDER BY <orderby-list>

This method returns an SQL statement that would be produced by executing self with an implicit RWDBConnection object. An implicit RWDBConnection object inherits the time zone setting from the producer RWDBDatabase instance. Hence, the time zone setting of the producer RWDBDatabase object will be used for creating the string representations of any RWDateTime instances in self.

The behavior of this method depends upon the RWDBDatabase::verboseAsString() setting in the producer RWDBDatabase instance.

  • If verboseAsString() is false, the SQL returned is the same as that passed to the database for execution. This is the default.
  • If verboseAsString() is true, any placeholders in the returned SQL are replaced with their bound values.
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 this method with RWDBDatabase::verboseAsString() set to true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBDatabase::timeZone(const RWZone*) for time zone setting on RWDBDatabase.
RWCString RWDBSelector::asString ( const RWDBConnection conn) const
inline

Returns the SQL equivalent of:

SELECT <column-list> FROM <from-list>
WHERE <where-clause> GROUP BY <groupby-list>
HAVING <having-clause> ORDER BY <orderby-list>

This method returns an SQL statement that would be produced by executing self with conn. The time zone setting of conn will be used for creating string representations of any RWDateTime instances in self.

The behavior of this method depends upon the RWDBDatabase::verboseAsString() setting in the producer RWDBDatabase instance.

  • If verboseAsString() is false, the SQL returned is the same as that passed to the database for execution. This is the default.
  • If verboseAsString() is true, any placeholders in the returned SQL are replaced with their bound values.
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 this method with RWDBDatabase::verboseAsString() set to true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBConnection::timeZone(const RWZone*) for time zone setting on RWDBConnection.
RWCString RWDBSelector::asString ( bool  verbose) const
inline

Returns the SQL equivalent of:

SELECT <column-list> FROM <from-list>
WHERE <where-clause> GROUP BY <groupby-list>
HAVING <having-clause> ORDER BY <orderby-list>

This method returns an SQL statement that would be produced by executing self with an implicit RWDBConnection object. An implicit RWDBConnection object inherits the time zone setting from the producer RWDBDatabase instance. Hence, the time zone setting of the producer RWDBDatabase object will be used for creating the string representations of any RWDateTime instances in self.

The behavior of this method depends on the value of verbose, and is independent of the RWDBDatabase::verboseAsString() setting.

  • If verbose is false, the SQL returned is the same as that passed to the database for execution.
  • If verbose is true, any placeholders in the returned SQL are replaced with their bound values although the SQL passed to the database for execution will not be affected.
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 this method with verbose as true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBDatabase::timeZone(const RWZone*) for time zone setting on RWDBDatabase.
RWCString RWDBSelector::asString ( const RWDBConnection conn,
bool  verbose 
) const
inline

Returns the SQL equivalent of:

SELECT <column-list> FROM <from-list>
WHERE <where-clause> GROUP BY <groupby-list>
HAVING <having-clause> ORDER BY <orderby-list>

This method returns an SQL statement that would be produced by executing self with conn. The time zone setting of conn will be used for creating string representations of any RWDateTime instances in self.

The behavior of this method depends on the value of verbose, and is independent of the RWDBDatabase::verboseAsString() setting.

  • If verbose is false, the SQL returned is the same as that passed to the database for execution.
  • If verbose is true, any placeholders in the returned SQL are replaced with their bound values although the SQL passed to the database for execution will not be affected.
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 this method with verbose as true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBConnection::timeZone(const RWZone*) for time zone setting on RWDBConnection.
RWDBBulkReader RWDBSelector::bulkReader ( const RWDBConnection conn) const
inline

Returns an RWDBBulkReader able to read the result set associated with the rows of self. The RWDBBulkReader executes using the supplied connection.

RWDBStatus RWDBSelector::clear ( )
inline

Clears self's clauses, selection lists, and internal controls.

RWDBColumn RWDBSelector::column ( size_t  index) const
inline

Returns a deep copy of the RWDBColumn in self's schema at the given index. If index is out of range, returns an RWDBColumn with status RWDBStatus::invalidPosition. A deep copy is made so that applications can modify the returned RWDBColumn without modifying self's schema.

RWDBColumn RWDBSelector::column ( const RWCString name) const
inline

Returns a deep copy of the first RWDBColumn in self's schema whose name matches the given name. If no matching column is found, returns an RWDBColumn whose status is RWDBStatus::columnNotFound. A deep copy is made so that applications can modify the returned RWDBColumn without modifying self's schema.

RWDBColumn RWDBSelector::column ( const RWCString name,
RWCString::caseCompare  caseCompare 
) const
inline

Returns a deep copy of the first RWDBColumn in self's schema whose name matches the given name. If no matching column is found, returns an RWDBColumn whose status is RWDBStatus::columnNotFound. A deep copy is made so that applications can modify the returned RWDBColumn without modifying self's schema. The caseCompare argument toggles case sensitivity when comparing column names. Valid arguments are RWCString::exact and RWCString::ignoreCase.

RWDBCursor RWDBSelector::cursor ( RWDBCursor::CursorType  type = RWDBCursor::Sequential,
RWDBCursor::CursorAccess  access = RWDBCursor::Read 
) const
inline

Produces an RWDBCursor for execution of the SQL select statement encapsulated by self. The cursor is created on a default database connection, using the type and access specifications provided. The connection is held by the RWDBCursor until the RWDBCursor is destroyed.

RWDBCursor RWDBSelector::cursor ( const RWDBConnection connection,
RWDBCursor::CursorType  type = RWDBCursor::Sequential,
RWDBCursor::CursorAccess  access = RWDBCursor::Read 
) const
inline

Produces an RWDBCursor for execution of the SQL statement encapsulated by self. The cursor is created on the supplied database connection, using the type and access specifications provided. The connection is held by the RWDBCursor until the RWDBCursor is destroyed. This function can behave asynchronously if executed using an asynchronous connection.

RWDBCursor RWDBSelector::cursor ( const RWDBSchema updateCols,
RWDBCursor::CursorType  type = RWDBCursor::Sequential,
RWDBCursor::CursorAccess  access = RWDBCursor::Read 
) const
inline

Produces an RWDBCursor for execution of the SQL select statement encapsulated by self. The argument updateCols is used in building a clause:

FOR UPDATE OF column-name, column-name, ...

Some SQL dialects require this form. The cursor is created on a default database connection, using the type and access specifications provided. The connection is held by the RWDBCursor until the RWDBCursor is destroyed.

RWDBCursor RWDBSelector::cursor ( const RWDBSchema updateCols,
const RWDBConnection connection,
RWDBCursor::CursorType  type = RWDBCursor::Sequential,
RWDBCursor::CursorAccess  access = RWDBCursor::Read 
) const
inline

Produces an RWDBCursor for execution of the SQL statement encapsulated by self. The cursor is created on the supplied database connection, using the type and access specifications provided. The connection is held by the RWDBCursor until the RWDBCursor is destroyed. The argument updateCols is used in building a clause:

FOR UPDATE OF column-name, column-name, ...

Some SQL dialects require this form. This function can behave asynchronously if executed using an asynchronous connection.

RWDBDatabase RWDBSelector::database ( ) const
inline

Returns the RWDBDatabase that produced this selector. If there is no such object, for example, if this selector was created using the default constructor, returns an RWDBDatabase with a status of RWDBStatus::notInitialized.

virtual RWDBCompoundSelector RWDBSelector::difference ( const RWDBSelectorBase selector) const
virtual

Returns an RWDBCompoundSelector that represents the SQL selector:

select-stmt DIFFERENCE selector

where select-stmt is the SELECT statement represented by self.

Reimplemented from RWDBSelectorBase.

RWDBSelector& RWDBSelector::distinct ( bool  logic = true)

By default, adds the DISTINCT SQL keyword to the select statement encapsulated by self. If logic is specified as false, removes the DISTINCT keyword if it is present. Returns a reference to self.

RWDBResult RWDBSelector::execute ( )
inline

Uses a default database connection to submit the SQL SELECT statement encapsulated by self for execution. There will always be one or more RWDBTable objects in the returned RWDBResult.

RWDBResult RWDBSelector::execute ( const RWDBConnection connection)
inline

Uses the supplied connection to submit the SQL SELECT statement encapsulated by self for execution. There will always be one or more RWDBTable objects in the returned RWDBResult. This function can behave asynchronously if executed using an asynchronous connection.

bool RWDBSelector::fetchSchema ( )
inline

Executes the SQL statement associated with self, then populates self's internal schema with the result set, that is, the columns in the table that resulted from the execution of the SQL statement. This function returns true if successful.

To obtain schema information, the DB Interface Module uses a default database connection to query the database. If no schema can be obtained, this function returns false.

bool RWDBSelector::fetchSchema ( const RWDBConnection connection)
inline

Executes the SQL statement associated with self, then populates self's internal schema with the result set, that is, the columns in the table that resulted from the execution of the SQL statement. This function returns true if successful.

To obtain schema information, the DB Interface Module uses the supplied connection to query the database. If no schema can be obtained, this function returns false.

RWDBSelector& RWDBSelector::from ( const RWCString tableName)

Adds tableName to self's explicit FROM list. Normally, RWDBSelector has no explicit FROM clause. It can deduce which tables to query from the column references in its select list. By using the from() method, you can manipulate default FROM clause generation and cause an explicit FROM list to be maintained. Each call to from() adds an entry to the explicit FROM list. The explicit FROM list can be used by itself or combined with the default implicit list, depending on the fromGeneration() setting. This is explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

RWDBSelector& RWDBSelector::from ( const RWDBTable table)

Adds name of table to self's explicit FROM list. Normally, RWDBSelector has no explicit FROM clause. It can deduce which tables to query from the column references in its select list. By using the from() method, you can manipulate default FROM clause generation and cause an explicit FROM list to be maintained. Each call to from() adds an entry to the explicit FROM list. The explicit FROM list can be used by itself or combined with the default implicit list, depending on the fromGeneration() setting. This is explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

RWDBSelector& RWDBSelector::from ( const RWDBJoinExpr jExpr)

Adds jExpr to self's explicit FROM list. This method is used for adding outer join constructs to the FROM clause. Each call to from() adds an entry to the explicit FROM list. See the Section on "Outer Joins" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide and the RWDBJoinExpr entry in this Reference Guide for information on generating appropriate outer join constructs. The FROM clause generation is explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

RWDBSelector& RWDBSelector::fromClear ( )

Clears self's explicit FROM list. See from() for an explanation of implicit and explicit FROM clauses. This is also explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

RWDBSelector& RWDBSelector::fromExtern ( const RWDBTable table)

Declares table as an externally defined table and hence to not be included in the self's FROM clause. Each call to fromExtern() adds an entry to self's extern table list. This method is especially useful in forming correlated SQLs in which the correlated subquery references a table defined in the outer SQL. The FROM clause generation and correlated subqueries are explained in detail in the Section "Composing FROM clause" and the Section "Subqueries" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

RWDBSelector& RWDBSelector::fromExternClear ( )

Clears self's extern table list. See fromExtern() for an explanation of the extern table list. The FROM clause generation is explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

RWDBSelector& RWDBSelector::fromGeneration ( FromGeneration  flag)

Sets self's FROM clause generation behavior. Class-scoped enum FromGeneration defines the behavior in generating self's FROM clause from the implicit and explicit FROM entries. The default behavior is ExplicitOrImplicit. The FROM clause generation is explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide. Returns a reference to self.

FromGeneration RWDBSelector::fromGeneration ( ) const

Returns self's FROM clause generation behavior. Class-scoped enum FromGeneration defines the behaviors in which to generate self's FROM clause from the implicit and explicit FROM entries. The default behavior is ExplicitOrImplicit. The FROM clause generation is explained in detail in the Section "Composing FROM clause" in the Chapter "The Data Manipulation Classes" in the DB Interface Module User's Guide.

RWDBSelector& RWDBSelector::groupBy ( const RWDBColumn column)

Specifies column as a GROUP BY column for self. A select statement may have multiple GROUP BY columns; successive calls to groupBy() add GROUP BY columns to self. The order of groupBy() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::groupBy ( const RWDBExpr expr)

Specifies expr as a GROUP BY <expression> for self. A select statement may have multiple GROUP BY expressions; successive calls to groupBy() add GROUP BY expressions to self. The order of groupBy() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::groupBy ( int  columnNumber)

Specifies columnNumber as a GROUP BY column for self. A select statement may have multiple GROUP BY columns; successive calls to groupBy() add GROUP BY columns to self. The order of groupBy() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::groupByClear ( )

Clears self's GROUP BY clause. Returns a reference to self.

RWDBSelector& RWDBSelector::having ( const RWDBCriterion criterion)

Specifies criterion as self's HAVING clause. If self already has a HAVING clause, this method replaces it. This method is most often used in conjunction with groupBy(). Returns a reference to self.

virtual RWDBCompoundSelector RWDBSelector::intersection ( const RWDBSelectorBase selector) const
virtual

Returns an RWDBCompoundSelector that represents the SQL selector:

select-stmt INTERSECTION selector

where select-stmt is the SELECT statement represented by self.

Reimplemented from RWDBSelectorBase.

RWDBSelector& RWDBSelector::into ( const RWCString tableName)

Specifies the INTO clause of a select statement. If self already has an INTO clause, this method replaces it. A blank tableName removes the clause from self. If self's database does not support SELECT INTO, the DB Interface Module does not attempt to emulate this functionality. In such cases this method sets self's status to RWDBStatus::notSupported. Returns a reference to self.

bool RWDBSelector::isValid ( void  ) const
inline

Returns true if self's status is RWDBStatus::ok, otherwise returns false. Does not return false if the previous executed statement failed. You must check the status of the RWDBResult returned from execute() instead of the status of the RWDBSelector object.

RWDBSelector& RWDBSelector::on ( const RWDBCriterion criterion)
Deprecated:
As of SourcePro 1, use RWDBJoinExpr::on(const RWDBCriterion&) to attach a join condition to a specific RWDBJoinExpr.

Attaches the criterion as an SQL ON clause to the first RWDBJoinExpr attached to self using the from() method. If the first RWDBJoinExpr already has an ON clause, this method replaces it. Returns a reference to self.

RWDBSelector& RWDBSelector::on ( const RWDBColumn column)
Deprecated:
As of SourcePro 1, use RWDBJoinExpr::on(const RWDBColumn&) to add a column to the SQL USING clause of a specific RWDBJoinExpr.

Adds the column to the SQL USING clause of the first RWDBJoinExpr attached to self using the from() method. Returns a reference to self.

RWDBSelector& RWDBSelector::operator<< ( RWDBValueManip  manip)

The insertion operator adds manip to self's select list. Returns a reference to self.

RWDBSelector& RWDBSelector::operator<< ( const RWDBExpr expr)

The insertion operator adds an item to self's select list. The supplied expr may be made up of constants, column references, predefined functions, or RWDBSelector instances, combined with arithmetic or functional operators. See RWDBExpr. Returns a reference to self.

RWDBSelector& RWDBSelector::operator<< ( const RWDBTable table)

Use this method to specify SELECT * FROM table. Returns a reference to self.

RWDBSelector& RWDBSelector::operator= ( const RWDBSelector select)

Assignment operator. Self shares an implementation with select. Returns a reference to self.

RWDBColumn RWDBSelector::operator[] ( const RWCString name) const
inline

Returns a deep copy of the first RWDBColumn in self's schema whose name matches the given name. If no matching column is found, returns an RWDBColumn whose status is RWDBStatus::columnNotFound. A deep copy is made so that applications can modify the returned RWDBColumn without modifying self's schema.

RWDBColumn RWDBSelector::operator[] ( size_t  position) const
inline

Returns a deep copy of the RWDBColumn in self's schema whose position matches the given position. If no matching column is found, returns an RWDBColumn whose status is RWDBStatus::columnNotFound. A deep copy is made so that the application can modify the returned RWDBColumn without modifying self's schema.

RWDBSelector& RWDBSelector::orderBy ( const RWDBColumn column)

Specifies column as an ORDER BY column for self. A select statement may have multiple ORDER BY columns; successive calls to orderBy() and orderByDescending() add ORDER BY columns to self. The order of orderBy() and orderByDescending() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::orderBy ( const RWDBExpr expr)

Specifies expr as an ORDER BY <expression> for self. A select statement may have multiple ORDER BY expressions; successive calls to orderBy() and orderByDescending() add ORDER BY expressions to self. The order of orderBy() and orderByDescending() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::orderBy ( int  columnNumber)

Specifies columnNumber as an ORDER BY column for self. A select statement may have multiple ORDER BY columns; successive calls to orderBy() and orderByDescending() add ORDER BY columns to self. The order of orderBy() and orderByDescending() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::orderByClear ( )

Clears self's ORDER BY clause. Returns a reference to self.

RWDBSelector& RWDBSelector::orderByDescending ( const RWDBColumn column)

Specifies column as an ORDER BY DESCENDING column for self. A select statement may have multiple ORDER BY columns; successive calls to orderBy() and orderByDescending() add ORDER BY columns to self. The order of orderBy() and orderByDescending() calls is retained. Returns a reference to self.

RWDBSelector& RWDBSelector::orderByDescending ( int  columnNumber)

Specifies columnNumber as an ORDER BY DESCENDING column for self. A select statement may have multiple ORDER BY columns; successive calls to orderBy() and orderByDescending() add ORDER BY columns to self. The order of orderBy() and orderByDescending() calls is retained. Returns a reference to self.

RWDBReader RWDBSelector::reader ( size_t  cacheSize = 0) const
inline

Produces an RWDBReader that can be used to read data from self one row at a time. Uses a default database connection which is held by the RWDBReader until the RWDBReader is destroyed.

Note
When cacheSize is 0, an acceptable default is selected by your Access Module. Please check your Access Module documentation for limitations on the cache size.
RWDBReader RWDBSelector::reader ( const RWDBConnection connection,
size_t  cacheSize = 0 
) const
inline

Produces an RWDBReader that can be used to read data from self one row at a time. Uses the supplied connection, which is held by the RWDBReader until the RWDBReader is destroyed. This function can behave asynchronously if executed using an asynchronous connection.

Note
When cacheSize is 0, an acceptable default is selected by your Access Module. Please check your Access Module documentation for limitations on the cache size.
RWDBSchema RWDBSelector::schema ( ) const
inline

Returns a deep copy of self's RWDBSchema. The copy is made so that an application can modify the returned RWDBSchema without modifying self's schema. The schema is empty until self's fetchSchema() method is called.

RWDBSelector& RWDBSelector::select ( const RWDBExpr expr)

This is a synonym for *this << expr. Returns a reference to self.

RWDBSelector& RWDBSelector::select ( const RWDBTable table)

This is a synonym for *this << table. Returns a reference to self.

RWDBSelector& RWDBSelector::selectClear ( )

Clears self's select list. Returns a reference to self.

void RWDBSelector::setErrorHandler ( RWDBStatus::ErrorHandler  handler)
inline

Installs handler as self's error handler. The supplied handler is inherited by all objects produced by self. By default, an RWDBStatus::ErrorHandler is inherited from the object that produced self; this method overrides the default.

RWDBStatus RWDBSelector::status ( ) const
inline

Returns the status of self.

virtual RWDBCompoundSelector RWDBSelector::union_ ( const RWDBSelectorBase selector) const
virtual

Returns an RWDBCompoundSelector that represents the SQL selector:

select-stmt UNION selector

where select-stmt is the SELECT statement represented by self. The trailing underscore is to avoid conflict with the C++ union keyword.

Reimplemented from RWDBSelectorBase.

virtual RWDBCompoundSelector RWDBSelector::unionAll ( const RWDBSelectorBase selector) const
virtual

Returns an RWDBCompoundSelector which represents the SQL selector:

select-stmt UNION ALL selector

where select-stmt is the SELECT statement represented by self.

Reimplemented from RWDBSelectorBase.

RWDBCriterion RWDBSelector::where ( ) const

Returns a copy of self's RWDBCriterion, an encapsulated SQL WHERE clause. Returns an empty RWDBCriterion if self has no WHERE clause.

RWDBSelector& RWDBSelector::where ( const RWDBCriterion criterion)

Specifies criterion as self's SQL WHERE clause. If self already has a WHERE clause, this method replaces it. Returns a reference to self.

Friends And Related Function Documentation

RWDBCompoundSelector operator* ( const RWDBSelectorBase left,
const RWDBSelectorBase right 
)
related

Intersection. Equivalent to

left.intersection(right);
RWDBCompoundSelector operator+ ( const RWDBSelectorBase left,
const RWDBSelectorBase right 
)
related

Union. Equivalent to

left.union_(right);
RWDBCompoundSelector operator- ( const RWDBSelectorBase left,
const RWDBSelectorBase right 
)
related

Difference. Equivalent to

left.difference(right);

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.