SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWDBExprFormDefinition Class Reference

Base class for a family of classes that defines functional notation for RWDBExpr. More...

#include <rw/db/func.h>

Inheritance diagram for RWDBExprFormDefinition:
RWDBExprFuncDef0 RWDBExprFuncDef1 RWDBExprFuncDef2 RWDBExprFuncDef3 RWDBExprFuncDef4

Public Member Functions

 RWDBExprFormDefinition ()
 
 RWDBExprFormDefinition (const RWCString &formatString)
 
virtual RWDBExpr operator() ()
 
virtual RWDBExpr operator() (const RWDBExpr &expr0)
 
virtual RWDBExpr operator() (const RWDBExpr &expr0, const RWDBExpr &expr1)
 
virtual RWDBExpr operator() (const RWDBExpr &expr0, const RWDBExpr &expr1, const RWDBExpr &expr2)
 
virtual RWDBExpr operator() (const RWDBExpr &expr0, const RWDBExpr &expr1, const RWDBExpr &expr2, const RWDBExpr &expr3)
 

Detailed Description

RWDBExprFormDefinition is a base class for a family of classes that provide an extensible mechanism for an application to define functional notation for RWDBExpr. RWDBExprFormDefinition allows the creation an object that translates into an RWDBExpr and can eventually be expanded into an SQL string. The object will allow up to four expressions to be embedded into the resultant string.

An RWDBExprFormDefinition object is instantiated with a format string. The format string may contain placeholders for up to four positional parameters, which are labeled %0 through %3. An object defined this way may subsequently be referenced like predefined functions, such as rwdbMax and rwdbAvg.

When an RWDBExprFormDefinition object is expanded by the asString() method of RWDBExpr, each instance of %0 is replaced with the first actual parameter, each instance of %1 is replaced with the second actual parameter, and so on. There can be multiple instances of a placeholder in the format string, and the placeholders may occur in any order. This allows great flexibility in defining functions, at the cost of losing compile-time checking on the number of parameters actually passed. To enable compile-time checking on the number of actual parameters, at the cost of some flexibility, use the RWDBExprFuncDef0, RWDBExprFuncDef1, RWDBExprFuncDef2, RWDBExprFuncDef3 and RWDBExprFuncDef4 classes.

Synopsis
#include <rw/db/func.h>
RWDBExprFormDefinition myFunc("myFormat");
See also

RWDBCritFormDefinition provides a parallel mechanism for defining an RWDBCriterion, rather than using RWDBExpr.

RWDBExprFuncDef0, RWDBExprFuncDef1, RWDBExprFuncDef2, RWDBExprFuncDef3, and RWDBExprFuncDef4 are derived from RWDBExprFormDefinition. They provide a simplified interface for functions requiring 0 - 4 parameters, respectively, and do not require positional placeholders.

See RWDBExpr for details on SQL expressions in the DB Interface Module, as well as for a complete listing of predefined SQL functions.

Example

Imagine that a database vendor's SQL variant provides the function DECRYPT(string, length, key). The DB Interface Module has no direct support for this function, yet we would like to use it without losing the benefits of its high-level constructs for data manipulation. To do so, we can use a function which we define ourselves:

RWDBExprFormDefinition decrypt("DECRYPT(%0, %1, %2)");
RWCString key = getMyKey();
RWDBTable users = myDbase.table("users");
RWDBColumn passWord = users["passWord"];
RWDBSelector select = users.selector();
select << decrypt(passWord, rwdbCharLength(passWord), key);

Note that the number of parameters actually passed to decrypt is not checked. Compare this example with the RWDBExprFuncDef3 example to see how such checking can be enabled.

Constructor & Destructor Documentation

RWDBExprFormDefinition::RWDBExprFormDefinition ( )

Creates an empty RWDBExprFormDefinition. Provided for convenience only.

RWDBExprFormDefinition::RWDBExprFormDefinition ( const RWCString formatString)

Creates an RWDBExprFormDefinition with the given formatString. Objects instantiated this way may subsequently be referenced as though they were predefined SQL functions.

Member Function Documentation

virtual RWDBExpr RWDBExprFormDefinition::operator() ( )
virtual

Returns an RWDBExpr that encapsulates the formatString associated with RWDBExprFormDefinition.

Reimplemented in RWDBExprFuncDef4, RWDBExprFuncDef3, RWDBExprFuncDef2, RWDBExprFuncDef1, and RWDBExprFuncDef0.

virtual RWDBExpr RWDBExprFormDefinition::operator() ( const RWDBExpr expr0)
virtual

Returns an RWDBExpr that can replace any instance of %0 in self's function definition with expr0.

Reimplemented in RWDBExprFuncDef4, RWDBExprFuncDef3, RWDBExprFuncDef2, RWDBExprFuncDef1, and RWDBExprFuncDef0.

virtual RWDBExpr RWDBExprFormDefinition::operator() ( const RWDBExpr expr0,
const RWDBExpr expr1 
)
virtual

Returns an RWDBExpr that can replace any instance of %0 in self's function definition with expr0 and %1 with expr1.

Reimplemented in RWDBExprFuncDef4, RWDBExprFuncDef3, RWDBExprFuncDef2, RWDBExprFuncDef1, and RWDBExprFuncDef0.

virtual RWDBExpr RWDBExprFormDefinition::operator() ( const RWDBExpr expr0,
const RWDBExpr expr1,
const RWDBExpr expr2 
)
virtual

Returns an RWDBExpr that can replace any instance of %0 in self's function definition with expr0, %1 with expr1, and so on.

Reimplemented in RWDBExprFuncDef4, RWDBExprFuncDef3, RWDBExprFuncDef2, RWDBExprFuncDef1, and RWDBExprFuncDef0.

virtual RWDBExpr RWDBExprFormDefinition::operator() ( const RWDBExpr expr0,
const RWDBExpr expr1,
const RWDBExpr expr2,
const RWDBExpr expr3 
)
virtual

Returns an RWDBExpr that can replace any instance of %0 in self's function definition with expr0, %1 with expr1, and so on.

Reimplemented in RWDBExprFuncDef4, RWDBExprFuncDef3, RWDBExprFuncDef2, RWDBExprFuncDef1, and RWDBExprFuncDef0.

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