Example: A count query using
a stored procedure. This illustrates the use of input and output parameters.
class EmptyDataObj
{
};
class ProcOutBCA
{
public:
void operator()(BoundIOs &boundIOs, EmptyDataObj &rowbuf)
{
}
};
class ProcOutParams {
public:
long long_criteria;
int numRecords;
friend ostream &operator<<(ostream &o, const ProcOutParams ¶ms)
{
cout << "ProcOutParams(" << params.long_criteria << ", " << params.numRecords << ")";
return o;
}
};
class ProcOutBPA {
public:
void operator()(BoundIOs &cols, ProcOutParams ¶ms)
{
cols[0] << params.long_criteria;
cols[1] >> params.numRecords;
}
};
#if 0
Create or replace procedure ExampleInfoProcOutParams
(LONG_CRITERIA IN integer, NUM_RECORDS OUT integer)
As
Begin
select count(*)
into NUM_RECORDS
from db_example
where EXAMPLE_LONG = LONG_CRITERIA;
End;
#endif
void StoredProcCountRecords() {
DBView<EmptyDataObj, ProcOutParams> view("{call ExampleInfoProcOutParams(?, ?)}",
ProcOutBCA(), "", ProcOutBPA());
DBView<EmptyDataObj, ProcOutParams>::sql_iterator print_it = view.begin();
print_it.Params().long_criteria = 22;
*print_it = EmptyDataObj();
++print_it;
cout << "number of records with EXAMPLE_LONG = 22 is "
<< print_it.Params().numRecords << endl;
}