SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWDBCritFormDefinition Class Reference

Base class for a family of classes used to define functional notation for RWDBCriterion. More...

#include <rw/db/func.h>

Inheritance diagram for RWDBCritFormDefinition:
RWDBCritFuncDef0 RWDBCritFuncDef1 RWDBCritFuncDef2 RWDBCritFuncDef3 RWDBCritFuncDef4

Public Member Functions

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

Detailed Description

RWDBCritFormDefinition is a base class for a family of classes that provides an extensible mechanism an application can use to define functional notation for RWDBCriterion. RWDBCritFormDefinition creates an object that can translate into an RWDBCriterion and eventually be expanded into an SQL string. The object allows up to four expressions to be embedded into the resultant string.

An RWDBCritFormDefinition 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 in this way may subsequently be referenced in the same way that predefined functions like rwdbMax and rwdbAvg are referenced.

When an RWDBCritFormDefinition object is expanded by the asString() method of an RWDBCriterion, 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. Multiple instances of a placeholder can exist 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 RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3 and RWDBCritFuncDef4 classes.

Synopsis
#include <rw/db/func.h>
RWDBCritFormDefinition myFunc("myFormat");
Base class for a family of classes used to define functional notation for RWDBCriterion.
Definition func.h:710
See also

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

RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3, and RWDBCritFuncDef4 are derived from RWDBCritFormDefinition. They provide a simplified interface for functions requiring 0 - 4 parameters, respectively, and do not require positional placeholders.

See RWDBCriterion for details on SQL WHERE clauses in the DB Interface Module.

Example

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

RWDBCritFormDefinition validName("VALID_NAME(%0)");
RWDBTable potentialNames = myDbase.table("potentialNames");
RWDBColumn name = potentialNames["name"];
RWDBSelector usableNames = myDbase.selector();
usableNames << name;
usableNames.where(validName(name));
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
RWDBCriterion where() const
Base class for a family of classes that represent the abstract notion of a database table in a number...
Definition table.h:89

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

Constructor & Destructor Documentation

◆ RWDBCritFormDefinition() [1/2]

RWDBCritFormDefinition::RWDBCritFormDefinition ( )

The default constructor creates an empty RWDBCritFormDefinition.

◆ RWDBCritFormDefinition() [2/2]

RWDBCritFormDefinition::RWDBCritFormDefinition ( const RWCString & formatString)

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

Member Function Documentation

◆ operator()() [1/5]

virtual RWDBCriterion RWDBCritFormDefinition::operator() ( )
virtual

Returns an RWDBCriterion that encapsulates the formatString associated with RWDBCritFormDefinition.

Reimplemented in RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3, and RWDBCritFuncDef4.

◆ operator()() [2/5]

virtual RWDBCriterion RWDBCritFormDefinition::operator() ( const RWDBExpr & expr0)
virtual

Returns an RWDBCriterion with the ability to replace any instance of %0 in self's function definition with expr0.

Reimplemented in RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3, and RWDBCritFuncDef4.

◆ operator()() [3/5]

virtual RWDBCriterion RWDBCritFormDefinition::operator() ( const RWDBExpr & expr0,
const RWDBExpr & expr1 )
virtual

Returns an RWDBCriterion with the ability to replace any instance of %0 in self's function definition with expr0 and %1 with expr1.

Reimplemented in RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3, and RWDBCritFuncDef4.

◆ operator()() [4/5]

virtual RWDBCriterion RWDBCritFormDefinition::operator() ( const RWDBExpr & expr0,
const RWDBExpr & expr1,
const RWDBExpr & expr2 )
virtual

Returns an RWDBCriterion with the ability to replace any instance of %0 in self's function definition with expr0, %1 with expr1, and so on.

Reimplemented in RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3, and RWDBCritFuncDef4.

◆ operator()() [5/5]

virtual RWDBCriterion RWDBCritFormDefinition::operator() ( const RWDBExpr & expr0,
const RWDBExpr & expr1,
const RWDBExpr & expr2,
const RWDBExpr & expr3 )
virtual

Returns an RWDBCriterion with the ability to replace any instance of %0 in self's function definition with expr0, %1 with expr1, and so on.

Reimplemented in RWDBCritFuncDef0, RWDBCritFuncDef1, RWDBCritFuncDef2, RWDBCritFuncDef3, and RWDBCritFuncDef4.

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