|Home||How To||Online Documentation||Support||Download||Order|
Fetching result set
To execute a command and process a result set you should do the following:
For example, let's fetch rows from the table EMPLOYEES ( NAME CHAR(25), AGE INTEGER) .
Step 1. Creating a command object and setting a command text.
SACommand cmd(&Connection, "select name, age from employees where age>:1");
The line 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 the command text. This command will select all rows from the table EMPLOYEES where the value of field AGE more than some input value.
Step 2. Binding input parameters.
To associate a value with input variable use SACommand::operator<<:
cmd << 25;
This line sets the input parameter marked by :1 to value 25.
The Library provides several ways for binding input variables. To get more details see Binding input parameters.
Step 3. Execute the command.
To execute a command use SACommand::Execute method:
This command selects all rows from the table where field AGE value more than 25. The result of command execution is the result set - a set of rows corresponding with the request.
To check whether a result set exists after the command execution use SACommand::isResultSet method:
bool is_result = cmd.isResultSet();
Step 4. Processing the result set.
After the command execution a set of SAFieldobjects is created implicitly. Each SAField object represents a column in the result set. To get the number of columns in the result set call SACommand::FieldCount method:
long col_count = cmd.FieldCount();
Each field can be reached by its name or position. To get a field information (name, type, size, etc) directly after the command execution you can call SACommand::Field method:
SAField& Field = cmd.Field("age");
The line above associates the column AGE in the result set with Field variable. We can do the same getting column AGE by its position in the result set:
SAField& Field = cmd.Field(2);
A field value is updated only after row fetching. To fetch row by row from the result set use SACommand::FetchNext method:
You can use SAField operators for quick accessing values. In this case you can organize a fetching process as shown below:
Processing Long, BLob and CLob data can have some differences from processing other data types. See Working with Long or Lob(CLob, BLob) Data to get more information.
Problems and Questions
If you haven't found the answer to your questions or have some problems on using the Library, please, send e-mail to email@example.com.