Spec-Zone .ru
спецификации, руководства, описания, API

22.4.6.3. MySQL Connector/C++ Fetching Results

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. The preview version does buffer 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 that you must free sql::Statement, sql::Connection and sql::ResultSet objects explicitly using delete.

Cursor usage is demonstrated in the examples contained in the download package.