An Open SQL Stored Procedure Example
This example illustrates how to execute a stored procedure using an
RWDBOSql object. The stored procedure used here is assumed to take one input-output parameter of type
int. It returns two result sets: the first consists of character strings; the second of two columns of types
int and
RWDecimalPortable. The example assumes an error handler is associated with the connection in use, and doesn't check for any errors after calls to the
RWDBOSql object.
const size_t NUMBER_OF_ROWS = 10;
RWDBTBuffer<int> index; //1
index.paramType(RWDBColumn::inOutParameter); //2
index[0] = 100; //3
RWDBTBuffer<RWDBNativeType1> cursor1, cursor2; //4
RWDBTBuffer<RWCString> result1 (NUMBER_OF_ROWS); //5
RWDBTBuffer<int> result2_1 (NUMBER_OF_ROWS); //6
RWDBTBuffer<RWDecimalPortable> result2_2 (NUMBER_OF_ROWS); //7
RWDBOSql openSql ("BEGIN myProc (:index, :cursor1, :cursor2); END;",
RWDBOSql::Procedure); //8
openSql << index << cursor1 << cursor2; //9
openSql[0] >> result1; //10
openSql[1] >> result2_1 >> result2_2; //11
openSql.execute(conn); //12
long count = 0;
while ((count = openSql.fetch().rowsFetched()) > 0 ) { //13
for (int row = 0; row < count; row++) {
cout << "STRING VALUE :" << result1[row] << endl;
}
}
while ((count = openSql.fetch().rowsFetched()) > 0 ) { //14
for (int row = 0; row < count; row++) {
cout << "INT VALUE :" << result2_1[row] << endl;
cout << "DECIMAL VALUE: " << result2_2[row] << endl;
}
}
openSql.fetchReturnParams(); //15
cout << "OUT PARAM :" << index[0] << endl; //16