Example: Reading a set of records
from an Oracle stored procedure.
#if 0
Create or replace package ExampleInfo as
Type ExampleRec is record
(
INT_VALUE integer,
STRING_VALUE varchar2(50)
);
Type ExampleCursor is ref cursor return
ExampleRec;
End ExampleInfo;
Create or replace procedure ExampleInfoProc
(LONG_CRITERIA IN integer, empcursor IN OUT
ExampleInfo.ExampleCursor)
As
Begin
Open empcursor For
select INT_VALUE, STRING_VALUE
from db_example
where EXAMPLE_LONG = LONG_CRITERIA;
End;
#endif
class ProcBCA {
public:
void operator()(BoundIOs &cols, variant_row &row)
{
cols["INT_VALUE"] >> row._int();
cols["STRING_VALUE"] >> row._string();
cols.BindVariantRow(row);
}
};
class ProcParams {
public:
long long_criteria;
};
class ProcBPA {
public:
void operator()(BoundIOs &cols, ProcParams &row)
{
cols[0] << row.long_criteria;
}
};
void StoredProcReadData() {
DBView<variant_row, ProcParams> view("{call ExampleInfoProc(?)}",
ProcBCA(), "", ProcBPA());
variant_row s(view.GetDataObj());
vector<string> colNames = s.GetNames();
for (vector<string>::iterator name_it = colNames.begin(); name_it != colNames.end(); ++name_it)
cout << (*name_it) << " ";
cout << endl;
DBView<variant_row, ProcParams>::sql_iterator print_it = view.begin();
print_it.Params().long_criteria = 22;
for (; print_it != view.end(); ++print_it)
{
variant_row r = *print_it;
for (size_t i = 0; i < r.size(); ++i)
cout << r[i] << " ";
cout << endl;
}
}