I am not very conversant with mysql++, but if there isn't a routine in the resultset class (or whatever is returned as part of the object return on call to execution of the query), then you will have to call fetch_row until there are no more rows available.
Also, fetch_row should be called after a check to see if there are rows available or not. So, to that order the while loop doesn't look robust.
I did not understand what you meant by:
Originally Posted by Red Squirrel
But the issue there is if the last query was not a select query, or if there was no query at all, this will crash.
But in a situation where I only want 1 result but there's a chance that there are less or more, is where it becomes a big problem.
My attempted solution was to just add a while() that calls fetchrow in the query function but that did not work.
I did not understand. Are you saying that your code fails if there are no rows returned? I don't see how that should happen when fetch_row's return (Row object) would evaluate to false in that case (overloaded bool operator). Just like the regular cases where you have data and you keep doing fetch_row and one past the end, the expression evaluates to false and exists the loop.
Or are you saying you get more than 1 row and you just wanted 1 row? May be your query is incorrect. Or may be, you could do fetch_row for the first row, use the data and then do fetch_row in an empty while loop till all results are consumed by the client code (your code) if the rest of the returned rows are not useful to you. But still the primary problem here would be the query.
One suggestion though. If you are not dealing with huge result sets being returned, why don't you use the Query::storein() or Query::store() members to pull back the results at once from the server?
Also, I think I am not sure, but if you are using .use() member function even on calls to queries that don't return rows, you should change that to the other calls like Query::execute()/Query::exec().
The only issue I've run into is having to call fetch row twice when I only want/get one result. The 2nd fetch row returns false and seems to "flush" the queue, but I was hoping there was a function made specifically for that, so I can just call it before each query, but suppose I can live with the way I'm doing it now.
I also prefer not using store as when dealing with database data normally the amount of data increases as the application is used, (more records, etc).