List:MySQL++« Previous MessageNext Message »
From:Chris Morgan Date:December 30 2010 8:52pm
Subject:Re: Return the number of fields in a 'vector<Row> myresultset;'.
View as plain text  
On Thu, Dec 30, 2010 at 12:35, Eric Sepich <sepich.eric@stripped> wrote:
>
> Does anyone know how to return the number of fields in a 'vector<Row>
> myresultset;'? The reference manual states there is a size() method but that
> is returning the number of rows fetched. I want the number of columns.
> Thanks.

Hi Eric,

I'm not sure why you're using std::vector<Row> when
mysqlpp::StoreQueryResult
(http://tangentsoft.net/mysql++/doc/html/refman/classmysqlpp_1_1StoreQueryResult.html)
is available.

Without seeing your code, I'm guessing you're doing something like
this, which gives you the number of Rows in the result set:

mysqlpp::StoreQueryResult myresultset = query.store();
std::cout << "Total Rows: " << myresultset.size() << std::endl;

If you want the number of columns in a particular mysqlpp::Row, you
need to use myslqpp::Row::size()
(http://tangentsoft.net/mysql++/doc/html/refman/classmysqlpp_1_1Row.html#4ba1776cc55d5ff72acbb36b8cb4ae49)
instead:

mysqlpp::StoreQueryResult myresultset = query.store();

for (unsigned int i = 0; i < myresultset.num_rows(); i++)
{
  std::cout << "Row " << i << " Size: " << myresultset[i].size()
<< std::endl;
}

HTH,

Chris
Thread
Return the number of fields in a 'vector<Row> myresultset;'.Eric Sepich30 Dec
  • Re: Return the number of fields in a 'vector<Row> myresultset;'.Tomalak Geret'kal30 Dec
    • Re: Return the number of fields in a 'vector<Row> myresultset;'.Warren Young30 Dec
  • Re: Return the number of fields in a 'vector<Row> myresultset;'.Chris Morgan30 Dec
    • Re: Return the number of fields in a 'vector<Row> myresultset;'.Warren Young30 Dec
      • Re: Return the number of fields in a 'vector<Row> myresultset;'.Eric Sepich31 Dec