Result Tables
A result table represents a collection of tabular data that resides neither in a database nor in program memory. Instead, it is generated as the result of a database query.
NOTE: A result table of the DB Interface Module corresponds to the terms table expression, select expression, result set, and record set, which are used in other languages.
Result tables are produced by the table() method of class RWDBResult. Class RWDBResult represents a sequence of zero or more RWDBTable instances. An RWDBResult is returned whenever a database operation may produce results. This can happen more often than you may think. For example, the DB Interface Module recognizes that some database vendors provide:
*Stored procedures that can execute more than one SELECT statement
*Triggers that can cause results to be generated as the result of an INSERT, DELETE, or UPDATE statement
In the DB Interface Module, whenever the RWDBInserter, RWDBBulkInserter, RWDBDeleter, or RWDBUpdater calls its execute() method, an RWDBResult is produced.
Here is an introductory example that illustrates the interface for generating and reading result tables. Imagine that the getSqlInput() routine gets one or more SQL statements from somewhere, perhaps interactively from a user.
 
RWCString sql = getSqlInput();
RWDBResult results = myConnection.executeSql(sql);
RWDBTable resTab = results.table(); //1
while (resTab.isValid()) {
RWDBSchema resSchema = resTab.describe(RWDBTable::ColumnList); //2
int numCols = resSchema.entries();
std::cout << "Got result set with " << numCols << "columns";
RWDBReader rdr = resTab.reader(); //3
int numRows = 0;
while (rdr()) {
++numRows;
}
std::cout << " and " << numRows << " rows" << std::endl << std::endl;
resTab = results.table();
}
 
The RWDBTable instance declared on //1 is a result table. The tabular data it represents is not physically stored in the database or in memory, but is generated from the expression sent to the database server. Nevertheless, it uses what is by now a familiar interface. On //2 we retrieve the table's schema, just as we have done previously for database tables. On //3, we obtain a reader in the usual way. This reader has the same functionality as the readers you have encountered thus far; we have omitted processing the rows in order to keep the example compact.