The QueryResult class is used to control the DataSource object returned by methods
executeQuery()andexecutePreparedQuery()of classes McoSqlEngine, RemoteSqlEngine and McoMultithreadedSqlEngine.For an overview see page C++ Classes
The QueryResult class inherits its principal methods from classes ResultSet and DataSource. These methods are listed below.
bool isNumberOfRecordsKnown()Returnstrueif methodnRecords()can be called successfully.Returns the number of Record objects in the result set.Cursor* records()Returns a Cursor over the result set.Vector<Field>* fields()Returns a Vector (a variable length array) of Field objects.Field* findField(char const * name );Field* findField(String * name );void extract(...)Extracts Record components to the corresponding C struct.Typically a QueryResult object is instantiated in a function or method that releases it on return as the QueryResult object goes out of scope. (Note that failing to release a DataSource object can lead to an application deadlock. The QueryResult class helps avoid this as the DataSource method
release()is called in the QueryResultdestructorwhich also correctly releases the DataSource in case of a thrown exception.)Example
The most common use of the QueryResult class is illustrated in the following code snippet:
void show_results( char * sql ) { QueryResult result(engine.executeQuery(sql)); Cursor* cursor = result->records(); while (cursor->hasNext()) { Record* rec = cursor->next(); _Person p; // Extract the Person record to the corresponding struct result->extract(rec, &p, sizeof(p)); printf("\t\t%d) Name=%s, Ordinal=%u\n", count, p.name, p.ordinal ); } }(Please see page Processing Query Results for further details.)