Example: Selecting records from a view using a sql_iterator
class JoinExample
{
public: // tablename.columnname:
int exampleInt; // DB_EXAMPLE.INT_VALUE
string exampleStr; // DB_EXAMPLE.STRING_VALUE
double exampleDouble; // DB_EXAMPLE.DOUBLE_VALUE
unsigned long sampleLong; // DB_SAMPLE.SAMPLE_LONG
double extraDouble; // DB_SAMPLE.EXTRA_FLOAT
};
class JoinParamObj
{
public:
int intValue;
string strValue;
int sampleInt;
string sampleStr;
};
class BCAJoinExample
{
public:
void operator()(BoundIOs &cols, JoinExample &row)
{
cols["INT_VALUE"] >> row.exampleInt;
cols["STRING_VALUE"] >> row.exampleStr;
cols["DOUBLE_VALUE"] >> row.exampleDouble;
cols["SAMPLE_LONG"] >> row.sampleLong;
cols["EXTRA_FLOAT"] >> row.extraDouble;
}
};
class BPAJoinParamObj
{
public:
void operator()(BoundIOs ¶ms, JoinParamObj ¶mObj)
{
params[0] << paramObj.intValue;
params[1] << paramObj.strValue;
params[2] << paramObj.sampleInt;
params[3] << paramObj.sampleStr;
}
};
vector ReadJoinedData()
{
vector results;
DBView<JoinExample, ParamObj> view("SELECT INT_VALUE, STRING_VALUE, DOUBLE_VALUE, "
"SAMPLE_LONG, EXTRA_FLOAT FROM DB_EXAMPLE, DB_SAMPLE WHERE (INT_VALUE = (?) AND STRING_VALUE = (?)) AND "
"(SAMPLE_INT = (?) OR SAMPLE_STR = (?)) "
"ORDER BY SAMPLE_LONG", BCAJoinExample(), "",
BPAJoinParamObj());
DBView<JoinExample, JoinParamObj>::sql_iterator read_it = view.begin();
read_it.Params().intValue = 3;
read_it.Params().strValue = "Join Example";
read_it.Params().sampleInt = 1;
read_it.Params().sampleStr = "Joined Tables";
for ( ; read_it != view.end(); ++read_it)
{
results.push_back(*read_it);
}
return results;
}