QueryResult_AutoPtr results = db.ExecuteQuery("SELECT * FROM customers"); while(results->NextRow()) { std::cout << "Customer ID: " << results->GetInt(0) << std::endl; std::cout << "Customer Name: " << results->GetString(1) << std::endl; }
QueryResult_AutoPtr results = db.ExecuteQuery("SELECT COUNT(*) FROM orders WHERE status='shipped'"); if(results->NextRow()) { int numShippedOrders = results->GetInt(0); std::cout << "Number of shipped orders: " << numShippedOrders << std::endl; }In this example, we are counting the number of orders with a status of "shipped" and printing out the result. Since the `COUNT` function returns a single value, we only need to fetch the first (and only) row in the result set. Package/library: This code could be using any SQL library in C++, such as `mysql++`, `SQLiteCpp`, or `pqxx`.