It is possible to process more than one result set returned from a batch or stored procedure using SQLAPI++. To execute a command and process multiple result sets you should do the following:
For example, let's fetch rows from this sample query (batch):
Select 'aaa' union select 'bbb'
Select 1 union select 2 union select 3
"Select 'aaa' as fstr union select 'bbb'\n"
"Select 1 as fnum union select 2 union select 3");
The code above creates a command object cmd based on previously created and connected connection object Connection (for creating and connection Connection object see Connecting to databases). Second parameter is our sample command text.
The Library provides several ways for binding input variables. To get more details see Binding input parameters. There is nothing to bind in our example.
To execute a command use SACommand::Execute method:
Now we have to process all result sets returned.
// Process first result set
// do something special with first result set
SAString s = cmd["fstr"];
printf("fstr: %s\n", s);
// Process second result set
// do something special with second result set
long n = cmd["fnum"];
printf("fnum: %s\n", n);
If number of result sets is not known at compile time we can process result sets while SACommand::isResultSet returns true:
int nResulSets = 0;
printf("Processing result set #%d", ++nResulSets);
// do something special with this result set
SAString s = cmd.asString();
printf("field value: %s\n", s);
If you haven't found the answer to your questions or have some problems using the Library, please, send an e-mail to email@example.com