Count QSqlquery results!!
-
You can check if driver support feature by "hasFeature method":http://developer.qt.nokia.com/doc/qt-4.8/qsqldriver.html#hasFeature.
If you need a result count after while loop then you can do this:
@
int recCount = 0;
while( query.next() )
{
recCount++;
// code
}
@ -
If all you need is to distinguish the cases where you have 0, 1 or >1 results (that's what I gather from your opening post), then you don't need to count the results at all. Counting by iterating through the result set is potentially very expensive, so I would avoid it.
Just perform your query, and try to get the first result. If you don't have any results, you know at this point. If there is a result, cache the values in an object, and try to get the next result. If that works, you have >1 result, if not, you have only 1. No counting needed at all.
-
You should write something:
@
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
@P.S. Use <code>int numRowsAffected()</code>
-
[quote author="abbas farahmand" date="1326023459"]I'm using mysqli . support it?
if no , how can i get the size or number of row in results?i used
@query.numRowsAffected()
@
too
but its not worked![/quote][quote author="tucnak" date="1326032692"]You should write something:
@
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
@P.S. Use <code>int numRowsAffected()</code>[/quote]
Conclusion:
[quote]
I will read previous posts before replying.
...
[/quote] -
[quote author="tucnak" date="1326032692"]You should write something:
@
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
I will read documentation.
@P.S. Use <code>int numRowsAffected()</code>[/quote]
Let me now think about your proposal and read the numRowsAffected documentation:
[quote]
Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined. Note that for SELECT statements, the value is undefined; use size() instead.
[/quote] -
Hi and welcome to devnet,
Row length and row count are not the same thing. The row length is the number of field in the row, while the row count is the number of row returned by your query.
-
Hi and welcome to devnet,
Row length and row count are not the same thing. The row length is the number of field in the row, while the row count is the number of row returned by your query.