MySQL Connector/C++ Release Notes
The API for fetching result sets is identical for (simple)
statements and prepared statements. If your query returns one
result set, use
sql::Statement::executeQuery()
or
sql::PreparedStatement::executeQuery()
to
run your query. Both methods return
sql::ResultSet
objects. By default, Connector/C++
buffers all result sets on the client to support cursors.
// ...
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
// ...
stmt = con->createStatement();
// ...
res = stmt->executeQuery("SELECT id, label FROM test ORDER BY id ASC");
while (res->next()) {
// You can use either numeric offsets...
cout << "id = " << res->getInt(1); // getInt(1) returns the first column
// ... or column names for accessing results.
// The latter is recommended.
cout << ", label = '" << res->getString("label") << "'" << endl;
}
delete res;
delete stmt;
delete con;
Note
In the preceding code snippet, column indexing starts from 1.
Note
You must free the sql::Statement
,
sql::Connection
, and
sql::ResultSet
objects explicitly using
delete
.
Cursor usage is demonstrated in the examples contained in the download package.