MistyD
MistyD

Reputation: 17233

Get number of rows in a result set?

I am currently using the following way to access the content of a resultset from a prepared statement

std::string SQL = "....";
prep_stmt = con->prepareStatement(SQL);
res = prep_stmt->executeQuery();
if(res->next()) //If object exists
{
    res->getString("ColumnName"); //Access the content of a column
}

Is there any way for me to access the rows in a result set in advance before res->next()

Upvotes: 5

Views: 7548

Answers (2)

Kevin Guanche Darias
Kevin Guanche Darias

Reputation: 701

give a try to the rowsCount() method

cout << "Number of rows : " << res->rowsCount() << endl;

Edit: Notice rowsCount returns a size_t

Upvotes: 13

Kevin
Kevin

Reputation: 2730

Result = mysql_store_result( Connection );
if (Result) {
    RowsReturned = mysql_num_rows( Result );
} else {
    RowsReturned = 0;
}

See this relevant question (It's where I shamelessly copied the code from (a).

Upvotes: 3

Related Questions