MySQL Forums
Forum List  »  Connector/C++

Extracting results from SELECT count(*) query
Posted by: Ryan Breed
Date: August 17, 2009 04:16PM

I'm trying to determine the size of a table with the following code:

stringstream ssCountRecordsQuery;

ssCountRecordsQuery << "SELECT COUNT(*) FROM " << m_pszDatabaseName;
ssCountRecordsQuery << "." << m_pszTableName << ";";

auto_ptr< Statement > pCountRecordsStatement(m_pzConnection->m_pConnection->createStatement());

try
{
auto_ptr<ResultSet> results(pCountRecordsStatement->executeQuery(ssCountRecordsQuery.str()));
int nRecordCount = results->getInt(0);
}

I've tried all flavors of get* to extract the results, which I believe will be in the form of a single column named count(*) with a single numerical (integer?) result. As none of these have worked I'm wondering if I'm going about this incorrectly.

I've also tried getInt("COUNT(*)")

I've also tried getInt(1).

Can someone please assist?

Thanks in advance,
Ryan

Options: ReplyQuote


Subject
Views
Written By
Posted
Extracting results from SELECT count(*) query
4431
August 17, 2009 04:16PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.