SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWDBSimpleCaseExpr Class Reference

Used to build simple CASE expressions. More...

#include <rw/db/expr.h>

Inheritance diagram for RWDBSimpleCaseExpr:
RWDBExpr

Public Member Functions

 RWDBSimpleCaseExpr (const RWDBExpr &input)
 
 RWDBSimpleCaseExpr (const RWDBSimpleCaseExpr &simpleCaseExpr)
 
void else_ (const RWDBExpr &elseExpr)
 
RWDBSimpleCaseExproperator= (const RWDBSimpleCaseExpr &simpleCaseExpr)
 
void when (const RWDBExpr &whenExpr, const RWDBExpr &thenExpr)
 
- Public Member Functions inherited from RWDBExpr
 RWDBExpr ()
 
 RWDBExpr (char value)
 
 RWDBExpr (const char *value)
 
 RWDBExpr (const RWBasicUString &value)
 
 RWDBExpr (const RWCollection &collection)
 
 RWDBExpr (const RWCString &value)
 
 RWDBExpr (const RWDate &value)
 
 RWDBExpr (const RWDateTime &value)
 
 RWDBExpr (const RWDBBlob &value)
 
 RWDBExpr (const RWDBColumn &column)
 
 RWDBExpr (const RWDBColumn &left, const RWDBExpr &right)
 
 RWDBExpr (const RWDBColumn &left, const RWDBValue &right)
 
 RWDBExpr (const RWDBDateTime &value)
 
 RWDBExpr (const RWDBDuration &value)
 
 RWDBExpr (const RWDBExpr &expr)
 
 RWDBExpr (const RWDBMBString &value)
 
 RWDBExpr (const RWDBSelectorBase &subSelect)
 
 RWDBExpr (const RWDBTable &)
 
 RWDBExpr (const RWDBValue &value, bool usePhraseBook=true)
 
 RWDBExpr (const RWDecimalPortable &value)
 
 RWDBExpr (const RWTime &value)
 
 RWDBExpr (const RWWString &value)
 
 RWDBExpr (const wchar_t *value)
 
 RWDBExpr (double value)
 
 RWDBExpr (float value)
 
 RWDBExpr (int value)
 
 RWDBExpr (long double value)
 
 RWDBExpr (long int value)
 
 RWDBExpr (long long value)
 
 RWDBExpr (RWDBValueManip manip)
 
 RWDBExpr (short value)
 
 RWDBExpr (unsigned char value)
 
 RWDBExpr (unsigned int value)
 
 RWDBExpr (unsigned long int value)
 
 RWDBExpr (unsigned long long value)
 
 RWDBExpr (unsigned short value)
 
RWCString asString (const RWDBPhraseBook &phraseBook, AsStringControlFlag control=normal) const
 
RWDBCriterion between (const RWDBExpr &expression1, const RWDBExpr &expression2) const
 
RWDBCriterion in (const RWDBExpr &expression1) const
 
RWDBCriterion isNull (void) const
 
bool isValid (void) const
 
RWDBCriterion leftOuterJoin (const RWDBExpr &expression) const
 
RWDBCriterion like (const RWDBExpr &expression1) const
 
RWDBCriterion matchUnique (const RWDBExpr &expression1) const
 
RWDBExproperator= (const RWDBExpr &expr)
 
RWDBCriterion rightOuterJoin (const RWDBExpr &expression) const
 

Additional Inherited Members

- Public Types inherited from RWDBExpr
enum  AsStringControlFlag { normal , suppressTagsOnColumns , noPlaceHolder , placeHolderNotRecommended }
 

Detailed Description

RWDBSimpleCaseExpr represents a specialized type of RWDBExpr used to specify a simple SQL CASE expression.

Synopsis
#include <rw/db/expr.h>
RWDBSimpleCaseExpr caseExpr(aDatabase.table("table1").column("column1"));
Used to build simple CASE expressions.
Definition expr.h:1267
See also
RWDBSimpleCaseExpr is a special case of RWDBExpr. See RWDBExpr for more details.
Example
In this example, an RWDBSimpleCaseExpr is constructed with an input expression. The instance adds several WHEN expressions and an ELSE expression, then is finally inserted into the SELECT list.
// SELECT c1,
// (CASE c2
// WHEN 'NameA' THEN c1 * 2
// WHEN 'NameB' THEN c1 * 5
// ELSE c1 * 10
// END)
// FROM table1
// ORDER BY c2
// Instantiate a table object to represent the table.
RWDBTable t1 = aDatabase.table("table1");
// Instantiate a column object to represent the first column.
RWDBColumn c1 = t1["c1"];
// Instantiate a column object to represent the second column.
RWDBColumn c2 = t1["c2"];
// Instantiate simple CASE expression specifying column 2 as the input
// expression to be evaluated.
RWDBSimpleCaseExpr caseExpr(c2);
// Add WHEN clauses that are evaluated if column2 is equal to the
// specified WHEN expression argument.
caseExpr.when("NameA", RWDBExpr(c1) * 2);
caseExpr.when("NameB", RWDBExpr(c1) * 5);
// Add an ELSE expression that is evaluated if all WHEN clauses
// do not match.
caseExpr.elseExpr(c1 * 10);
// Instantiate a selector to represent a CASE query.
RWDBSelector aSel = db.selector();
// Add column 1 and the CASE expression to the SELECT list.
aSel << c1 << caseExpr;
// Specify an ORDER BY clause to order on column 2.
aSel.orderBy(c2);
Represents a column within a table or schema, or a particular parameter of a stored procedure.
Definition column.h:147
Encapsulates the SQL SELECT statement.
Definition select.h:369
RWDBSelector & orderBy(const RWDBColumn &column)
Base class for a family of classes that represent the abstract notion of a database table in a number...
Definition table.h:89

Constructor & Destructor Documentation

◆ RWDBSimpleCaseExpr() [1/2]

RWDBSimpleCaseExpr::RWDBSimpleCaseExpr ( const RWDBExpr & input)

Constructs an RWDBSimpleCaseExpr from input expression.

◆ RWDBSimpleCaseExpr() [2/2]

RWDBSimpleCaseExpr::RWDBSimpleCaseExpr ( const RWDBSimpleCaseExpr & simpleCaseExpr)

Copy constructor. The created RWDBSimpleCaseExpr shares an implementation with simpleCaseExpr.

Member Function Documentation

◆ else_()

void RWDBSimpleCaseExpr::else_ ( const RWDBExpr & elseExpr)

Specifies the ELSE expression for self as elseExpr. If self already has an ELSE clause, this method replaces it.

◆ operator=()

RWDBSimpleCaseExpr & RWDBSimpleCaseExpr::operator= ( const RWDBSimpleCaseExpr & simpleCaseExpr)

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

◆ when()

void RWDBSimpleCaseExpr::when ( const RWDBExpr & whenExpr,
const RWDBExpr & thenExpr )

Appends a WHEN/THEN clause to self where the argument whenExpr encapsulates the WHEN comparison expression, and the argument thenExpr encapsulates the THEN return expression.

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