dtl


Local BCA and Local BPA

Category: functors Component type: concept

Description

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.

Refinement of

None.

Associated types

BoundIOs, BCA, BPA.

Example 1:

// 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 2:

// 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;
}

vector<Example> ReadDataLocalBCA_BPA()
{
    // declare our BCA locally
    // add a local BPA to support a parameter for our where clause
    
    Example rowbuf;  // object used by BCA() to guide binding process
    int param;  // parameter for where clause
    
   
    DBView<Example, int> 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
        ),
        "WHERE INT_VALUE = ?",
        BPA(param, COLS[0] << param)
    );

    DBView<Example, int>::iterator beg = view.begin();
    beg.Params() = 1;  // set value of parameter for where clause

    // copy DB_EXAMPLE records that matched the query into the vector and return
    vector<Example> results;
    copy(beg, view.end(), back_inserter(results));
    return results;
}



Usage

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 &parambuf, 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 &parambuf, 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.

 

Notes

[1] There is a bug if DataObj == string. Trying to build a IndexedDBView in such a situation results in a crash at runtime.

See also

BoundIOs, BCA, BPA, DBView, IndexedDBView


[DTL Home]

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.

SourceForge Logo

This site written using the ORB. [The ORB]