Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of rows in a result set?

Tags:

c++

mysql

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()

like image 913
MistyD Avatar asked Jun 05 '13 18:06

MistyD


2 Answers

give a try to the rowsCount() method

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

Edit: Notice rowsCount returns a size_t

like image 133
Kevin Guanche Darias Avatar answered Oct 02 '22 11:10

Kevin Guanche Darias


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).

like image 25
Kevin Avatar answered Oct 02 '22 12:10

Kevin