Data Types | |
enum AsStringControlFlag |
#include <rw/db/expr.h>
RWDBExpr represents expressions used in constructing SQL statements. It allows the SQL to be constructed using C++ syntax. Because there are several types of expressions, this class is simply an interface to a family of implementations that can represent numeric and string constants, columns from tables, or other expressions. By its nature, an RWDBExpr can actually represent a complete complex expression in the form of a parse tree.
Because instances of this class are typically created anonymously, there are constructors taking the various operands used in expressions. These include the C++ primitive types, as well as the structured types used by DBTools.h++, such as RWCString and RWDBColumn.
RWDBExpr is designed around the Interface/Implementation paradigm. An RWDBExpr instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation.
In this example, an RWDBExpr is created anonymously to be used as part of an SQL SELECT statement. The intent is to create a selector that adds the value of the program variable x to each value selected.
int x = somevalue; RWDBTable myTable = myDbase.table("myTable"); RWDBSelector select = myDbase.selector(); select << myTable["integerColumn"] + x;
RWDBAssignment is a special kind of expression used to encapsulate the SQL phrase:
SET column = expression.
RWDBAssignment instances are produced by the method RWDBColumn::assign() .
RWDBBoundExpr is used to bind application variables to an SQL statement.
RWDBCollectableExpr derives from RWDBExpr and RWCollectable.
RWDBPhraseBook is used to store database-specific SQL syntax.
RWDBCriterion is a special kind of expression used to encapsulate an SQL WHERE clause. It is formed from RWDBExprs connected with logical operators.
RWDBExprFormDefinition provides an extensible mechanism that allows application programmers to define their own functional SQL notation.
RWDBJoinExpr is used to construct ANSI SQL join syntax.
enum AsStringControlFlag { normal, suppressTagsOnColumns, noPlaceHolder }
RWDBExpr();
The default constructor builds an empty RWDBExpr, that is, one whose asString(const RWDBPhraseBook& phraseBook) method returns an SQL NULL keyword, as specified in phraseBook. Since an empty expression cannot hold a value, RWDBExpr() cannot be used as NULL value.
RWDBExpr(const RWDBExpr& expr);
Copy constructor. Self shares an implementation with expr.
RWDBExpr(char value); RWDBExpr(unsigned char value); RWDBExpr(short value); RWDBExpr(unsigned short value); RWDBExpr(int value); RWDBExpr(unsigned int value); RWDBExpr(long int value); RWDBExpr(unsigned long int value); RWDBExpr(float value); RWDBExpr(double value); RWDBExpr(const char* value); RWDBExpr(const RWDBMBString& value); RWDBExpr(const RWWString& value); RWDBExpr(const wchar_t* value);
Creates an RWDBExpr from the given value.
RWDBExpr(const RWDBValue& value, RWBoolean usePhraseBook = TRUE);
Creates an RWDBExpr from an RWDBValue. When the asString function is applied to this RWDBExpr, it passes the phraseBook on to the RWDBValue for interpretation. Passing FALSE for the usePhraseBook parameter suppresses this behavior. The effect of suppressing the use of the phraseBook is to prevent strings from being quoted and RWDBDateTimes from using the database's designated format.
RWDBExpr(const RWDBColumn& column);
Creates an RWDBExpr from the column reference.
RWDBExpr(const RWCString& value); RWDBExpr(const RWDecimalPortable& value); RWDBExpr(const RWDBDateTime& value); RWDBExpr(const RWDBDuration& value); RWDBExpr(const RWDate& value); RWDBExpr(const RWTime& value); RWDBExpr(const RWDBBlob& value);
Creates an RWDBExpr from value.
RWDBExpr(const RWDBSelectorBase& subQuery);
Creates an RWDBExpr from an RWDBSelector. This constructor supports the SQL subquery construct.
RWDBExpr(RWDBValueManip manip);
Creates an RWDBExpr according to the semantics of manip. In particular, an expression representing a literal NULL may be constructed from rwdbNull.
RWDBExpr(const RWCollection& collection);
Creates an RWDBExpr that represents a delimited list of the items in collection. collection must be a collection of RWDBCollectableExprs. collection must remain in scope for the entire period that the RWDBExpr can be referenced, since the expression is not expanded into a string until the expr.asString() method is called, which can happen long after you assign the collectable to the expression.
RWDBExpr(const RWDBExpr& left, RWDBPhraseBook::RWDBPhraseKey op, const RWDBExpr& right);
Creates an RWDBExpr that represents a dyadic expression; that is, an expression of the form: lhs operator rhs.
RWDBExpr& operator=(const RWDBExpr& expr);
Assignment operator. Self shares an implementation with expr.
RWCString asString (const RWDBPhraseBook& phraseBook, AsStringControlFlag control = normal)const;
Returns an RWCString representing self as a string based on the format found in phraseBook. Normally, references to columns in self are represented in the string with table tags attached. Setting the value of control with RWDBExpr::suppressTagsOnColumns prevents the tags from being included in the string.
RWDBCriterion between(const RWDBExpr& expression1, const RWDBExpr& expression2) const;
Returns an RWDBCriterion that represents an encapsulation of the SQL clause:
expression BETWEEN expression1 AND expression2
where expression refers to self. RWDBCriterion encapsulates SQL WHERE clauses.
RWDBPhraseBook::RWDBPhraseKey getOperator() const;
Returns an enum representing the operator associated with this expression. Returns RWDBPhraseBook::operatorNoOp if there is no operator.
RWDBCriterion in(const RWDBExpr& expression) const;
Returns an RWDBCriterion that represents an encapsulation of the SQL phrase:
expression IN expression
where expression refers to self. An RWDBCriterion is an encapsulation of an SQL WHERE clause. For example, to produce the SQL clause:
(col1 + `bye') in (`hello', `good-bye')
we could write:
RWDBExpr anExpression(col1 + "bye"); anExpression.in(RWDBExpr("('hello', 'good-bye')", FALSE));
Note: the parameter FALSE in the constructor for the RWDBExpr above is required in order to suppress quotation marks in the resultant SQL string.
RWDBCriterion isNull()const;
Returns an RWDBCriterion that represents an encapsulation of the SQL clause:
expression IS NULL
where expression refers to self. An RWDBCriterion is an encapsulation of an SQL WHERE clause.
RWBoolean isValid() const;
Returns TRUE if self is not an empty (null) expression.
RWDBCriterion leftOuterJoin(const RWDBExpr& expression) const;
Returns an RWDBCriterion that represents an encapsulation of the LEFT OUTER JOIN SQL phrase. An RWDBCriterion is an encapsulation of an SQL WHERE clause.
RWDBCriterion like(const RWDBExpr& expression) const;
Returns an RWDBCriterion that represents an encapsulation of the SQL clause:
expression LIKE expression
where expression refers to self. For example, to produce the SQL clause:
col1 LIKE `%object%'
we would write:
table["col1"].like("%object%");
RWDBCriterion matchUnique(const RWDBExpr& expression) const;
Returns an RWDBCriterion that represents an encapsulation of the SQL clause:
MATCH UNIQUE expression
where expression refers to self.
RWDBCriterion rightOuterJoin(const RWDBExpr& expression) const;
Returns an RWDBCriterion that represents an encapsulation of the RIGHT OUTER JOIN SQL phrase. An RWDBCriterion is an encapsulation of an SQL WHERE clause.
Arithmetic operators may be applied to RWDBExpr instances to build complex RWDBExprs. Logical operators may be applied to produce an RWDBCriterion.
RWDBExpr operator+(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBExpr representing a dyadic expression between two subexpressions with + (plus) as the operator.
RWDBExpr operator+(const RWDBExpr&);
Returns an RWDBExpr representing a monadic expression with + (plus) as the operator.
RWDBExpr operator-(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBExpr representing a dyadic expression between two subexpressions with - (minus) as the operator.
RWDBExpr operator-(const RWDBExpr&);
Returns an RWDBExpr representing a monadic expression with the operator as - (minus).
RWDBExpr operator*(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBExpr representing a dyadic expression between two subexpressions with * (multiply) as the operator.
RWDBExpr operator/(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBExpr representing a dyadic expression between two sub-expressions with / (divide) as the operator.
RWDBExpr operator%(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBExpr representing a dyadic expression between two subexpressions with the % (modulo) operator.
RWDBCriterion operator&&(const RWDBCriterion&, const RWDBCriterion&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with && (and) as the operator, if both operands are initialized. If only one operand is initialized, returns an RWDBCriterion representing a monadic expression.
RWDBCriterion operator||(const RWDBCriterion&, const RWDBCriterion&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with || (or) as the operator, if both operands are initialized. If only one operand is initialized, returns an RWDBCriterion representing a monadic expression.
RWDBCriterion operator!(const RWDBCriterion&);
Returns an RWDBCriterion representing a monadic expression with the operator ! (not).
RWDBCriterion operator==(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with the == (equality) operator.
RWDBCriterion operator!=(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with the != (inequality) operator.
RWDBCriterion operator>(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with the > (greater than) operator.
RWDBCriterion operator<(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with the < (less than) operator.
RWDBCriterion operator>=(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with the >= (greater than or equal to) operator.
RWDBCriterion operator<=(const RWDBExpr&, const RWDBExpr&);
Returns an RWDBCriterion representing a dyadic expression between two subexpressions with the <= (less than or equal to) operator.
These functions may be applied to RWDBExpr instances to build RWDBExprs representing SQL functions.The SQL syntax for these functions typically varies among the various vendors' implementations. DBTools.h++ hides the variations by providing the database-specific syntax at runtime.
DBTools.h++ also provides an extensible mechanism for applications to define their own functional notation. See RWDBExprFormDefinition for details.
RWDBExpr rwdbAvg(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
AVERAGE(expr)
RWDBExpr rwdbCast(const RWDBExpr& expr, const RWDBValue& type);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
CAST(expr, type)
For example, to produce the SQL phrase:
CAST(Col1 + 7, STRING)
we would write:
RWDBExpr anExpression = rwdbCast(col1 + 7, "STRING");
RWDBExpr rwdbCast(const RWDBExpr& expr, const RWDBValue& typeName, const RWDBExpr& formatString);
Returns an RWDBExpr representing the database specific equivalent of the SQL function:
CAST(expr, typeName, formatString)
For example, to produce the SQL phrase:
CAST(dateCol,STRING, `MM-DD-YY')
we would write:
RWDBExpr anExpression = rwdbCast(dateCol,"STRING", "'MM-DD-YY'");
RWDBExpr rwdbCast(const RWDBExpr& expr, const RWDBValue& typeName, const RWDBExpr& formatString, const RWDBExpr& secondaryFormat);
Returns an RWDBExpr representing the database specific equivalent of the SQL function:
CAST(expr, typeName, formatString, secondaryFormat)
For example, to produce the SQL phrase:
CAST(dateCol, STRING, `MM-DD-YY',
French_France.WE8ISO88591')
where the last argument is a database-specific directive to use French style formatting, write:
RWDBExpr anExpression = rwdbCast(dateCol,"STRING","'MM-DD-YY'", "'French_France.WE8ISO88591'");
RWDBExpr rwdbCharLength (const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
CHARACTER_LENGTH(expr)
RWDBExpr rwdbCount(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
COUNT(expr)
RWDBExpr rwdbCount();
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
COUNT(*)
RWDBExpr rwdbCountDistinct (const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
COUNT DISTINCT (expr)
RWDBExpr rwdbCurrentUser ();
Returns an RWDBExpr representing the database-specific function that returns the name of the current user.
RWDBCriterion rwdbExists(const RWDBSelectorBase& select);
Returns an RWDBCriterion representing the database-specific equivalent of the SQL expression EXISTS(<select-statement>). In this expression, <select-statement> is the SQL select statement encapsulated by select.
RWDBExpr rwdbLower(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
TOLOWER(expr)
RWDBExpr rwdbMax(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
MAX(expr)
RWDBExpr rwdbMin(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
MIN(expr)
RWDBExpr rwdbName(const RWCString& name, const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL phrase name = expr. For example, to encapsulate the SQL statement:
SELECT employeeName = name from employees
write:
mySelector << rwdbName("employeeName", employees["name"]);
RWDBExpr rwdbPosition(const RWDBExpr& expr1,const RWDBExpr& expr2);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
POSITION(expr1, expr2)
The goal is to produce an SQL statement that gives the index of the string expr1 in expr2.
RWDBExpr rwdbSessionUser();
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
SESSION_USER()
The details of the SESSION_USER() function are vendor-specific.
RWDBExpr rwdbSubString(const RWDBExpr& expr1, const RWDBExpr& expr2);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
SUBSTRING(expr1, expr2)
The goal is to produce an SQL statement that gives the substring of expr1 starting at the index given by expr2.
RWDBExpr rwdbSubString(const RWDBExpr& expr1, const RWDBExpr& expr2, const RWDBExpr& expr3);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
SUBSTRING(expr1, expr2, expr3)
The goal is to produce an SQL statement that gives the substring of expr1 starting at the index given by expr2, with length given by expr3.
RWDBExpr rwdbSum(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
SUM(expr)
RWDBExpr rwdbSystemDateTime();
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
SYSTEM_DATETIME()
RWDBExpr rwdbSystemUser();
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
SYSTEM_USER()
RWDBExpr rwdbTrimLeading(const RWDBExpr& expr1, const RWDBExpr& expr2);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
TRIM_LEADING(expr1, expr2)
where expr1 represents the character to trim and expr2 represents the string expression to be trimmed.
RWDBExpr rwdbTrimTrailing(const RWDBExpr& expr1, const RWDBExpr& expr2);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
TRIM_TRAILING(exp1, expr2)
where expr1 represents the character to trim and expr2 represents the string expression to be trimmed.
RWDBExpr rwdbTrimBoth(const RWDBExpr& expr1, const RWDBExpr& expr2);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
TRIM_BOTH(expr1, expr2)
where expr1 represents the character to trim and expr2 represents the string expression to be trimmed.
RWDBExpr rwdbUpper(const RWDBExpr& expr);
Returns an RWDBExpr representing the database-specific equivalent of the SQL function:
UPPER(expr)
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.