dtl
Category: functors | Component type: concept |
Local BCAs and Local BPAs allow you to declare BCAs and BPAs "inline" in the constructor for a DBView . There are three parts to defining a local BCA.
1. Define a local variable for the row.
2. List the columns you want to bind. Individual column bindings are added to the list using the && operator.
3. Pass the set of columns to a BCA constructor to create the local BCA for you.
None.
// simple example for Local BCA ... reading doubles from a table
vector<double> ReadDataLocalBCASingleField()
{
// declare our BCA locally
// note how we bind using the COLS class to identify columns
double rowbuf; // row object used by BCA() to guide binding process
DBView<double> view("DB_EXAMPLE",
BCA(rowbuf, COLS["DOUBLE_VALUE"] >> rowbuf)
);
// copy the doubles from the view into the vector and return
vector<double> results;
copy(view.begin(), view.end(), back_inserter(results));
return results;
}
// Example for Local BCA's and BPA's
class Example
{
public: // tablename.columnname:
int exampleInt; // DB_EXAMPLE.INT_VALUE
string exampleStr; // DB_EXAMPLE.STRING_VALUE
double exampleDouble; // DB_EXAMPLE.DOUBLE_VALUE
long exampleLong; // DB_EXAMPLE.EXAMPLE_LONG
TIMESTAMP_STRUCT exampleDate; // DB_EXAMPLE.EXAMPLE_DATE
};
vector<Example> ReadDataLocalBCA()
{
// declare our BCA locally
// note how we bind using the quasi-BoundIOs named COLS
// and each binding is separated by operator&&() rather than semicolons
Example rowbuf; // object used by BCA() to guide binding process
DBView<Example> view("DB_EXAMPLE",
BCA(rowbuf,
COLS["INT_VALUE"] >> rowbuf.exampleInt &&
COLS["STRING_VALUE"] >> rowbuf.exampleStr &&
COLS["DOUBLE_VALUE"] >> rowbuf.exampleDouble &&
COLS["EXAMPLE_LONG"] >> rowbuf.exampleLong &&
COLS["EXAMPLE_DATE"] >> rowbuf.exampleDate
)
);
// copy DB_EXAMPLE records that matched the query into the vector and return
vector<Example> results;
copy(view.begin(), view.end(), back_inserter(results));
return results;
}
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Create local BCA with multiple fields |
template<class DataObj> LocalBCA<DataObj> BCA(DataObj &rowbuf, const BoundIOs &boundIOs); |
BoundIOs constructed using COLS syntax (see description) | Defines a Local BCA with multiple fields. The rowbuf passed in guides the actual binding process. | The returned LocalBCA object is a valid BCA. |
Creates local BCA with single field. |
template<class DataObj> LocalBCA<DataObj> BCA(DataObj &rowbuf, const BoundIO &boundIO); |
BoundIO constructed using COLS syntax (see description). | Defines a Local BCA with multiple fields. The rowbuf passed in guides the actual binding process. Note that the actual DataObj passed in here can be the actual field type (in that case, rowbuf is bound directly using BoundIO::operator==()). See Note [1]. | The returned LocalBCA object is a valid BCA. |
Create local BPA for multiple parameters. |
template<class ParamObj> LocalBCA<ParamObj> BPA(ParamObj ¶mbuf, const BoundIOs &boundIOs); |
BoundIOs constructed using COLS syntax (see description). | Defines a Local BPA with multiple parameters. The parambuf passed in guides the actual binding process. | The returned LocalBCA object is a valid BPA. |
Create local BPA for single parameter. |
template<class ParamObj> LocalBCA<ParamObj> BPA(ParamObj ¶mbuf, const BoundIO &boundIO); |
BoundIOs constructed using COLS syntax (see description) . |
Defines a Local BPA with a single parameter. The parambuf passed in guides the actual binding process. Note that the actual ParamObj passed in here can be the actual field type (in that case, rowbuf is bound directly using BoundIO::operator==()). See Note [1]. |
The returned LocalBCA object is a valid BPA. |
BoundIOs, BCA, BPA, DBView, IndexedDBView
Copyright © 2002, Michael Gradman and Corwin Joy.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.