A typical SQL select fragment is
#include "mcllib/mcllib.h"
using namespace mcllib; using namespace mcllib::db; ... // connection string specifies a database type (mysql in this case) // and parameters to pass to the driver to connect to that database MCString connectionString("mcdb:mysql://user=admin;pwd=admin;db=mysql"); // get a database connection (login to database) MCDBConnection conn = MCDBDriver::getConnection(connectionString); // get a SQL statement from the connection MCSqlStatement stmt = conn.createStatement(); // construct a SELECT to execute MCStringStream str; str << "select name, age from people where age > " << ageMin; // execute the select - returns true if the query was a SELECT statement if (stmt.execute(str.getString())) { // got a result MCDBResultSet rslt = stmt.getResultSet(); // getRowCount() shows how many records in the result set cout << "Retrieved " << rslt.getRowCount() << " rows from table" << endl; // iterate over the result set while (rslt.next()) { // Columns in result set are numbered from 0 // and stored as variant types // extract column 0 as the name (string) MCVTString name(rslt.get(0)); // extract column 1 as the age (int) MCVTUInt32 age(rslt.get(1)); cout << "Name: " << (MCString)name << ", Age: " << (mcuint32)age << endl; } } else { cout << "Query did not return a result" << endl; }Typically, the database connection will be made once for many SQL statements. The execute() and getResultSet() will be called as often as necessary. If the SQL statement is in error, an exception is thrown.