Expressions, Criteria, and Assignments
One of the great advantages of a client/server environment is the ability of the client to defer computation to the server. When a complicated query is requested, the client does not have to execute the query itself; the server does the work. This is illustrated by SQL statements like this:
SELECT *
FROM SomeTable
WHERE COl1 = 17 AND COL2 < COL3 - LENGTH( RTRIM (COL4) )
The
WHERE clause, which is specified by the client but executed by the server, contains a type of expression that is encapsulated in the DB Interface Module by some of the expression classes
RWDBExpr,
RWDBCriterion, and
RWDBAssignment. These classes, and others, can be used to represent the following types of expressions:
RWDBExpr is the base class for simple or complex expressions. These classes derive from it:
RWDBCriterion is used in the context of a boolean expression, as in the
WHERE clause above and in the check condition of an
RWDBCheckConstraint.
RWDBSimpleCaseExpr and
RWDBSearchedCaseExpr are used to create SQL
CASE expressions, either simple
CASE expressions or searched
CASE expressions.
RWDBAssignment is used to assign new values to columns, as in the
SET clause for updating rows.
The various databases have minor differences in their expression syntax. For example, the Sybase database has a modulus operator, while the Oracle database uses a function call instead. The DB Interface Module reconciles these differences by using standard C++ expression syntax involving columns, literals, and function invocations to encapsulate expressions. The Access module then translates expressions into forms appropriate for the database in use. These translations are described in the guides for the Access Modules.
Instances of the
RWDBExpr,
RWDBCriterion, and
RWDBAssignment classes are usually created anonymously, while
RWDBSimpleCaseExpr and
RWDBSearchedCaseExpr are explicitly created.
The following sections discuss these classes in more detail.