I'm wondering does QtSql + Sqlite support QSqlQuery::size() function?
Asked
Active
Viewed 5,560 times
5
-
I know its not supported. Maybe there is an alternative driver for QtSql that supports it ? – Sebastian Dusza Mar 21 '11 at 16:06
-
1I don't think so, because the SQlite API does not provide this information (see http://winmerge.org/ and http://sqlite.org/c3ref/step.html) – hmuelner Mar 21 '11 at 17:04
-
True, C/C++ API doesn't provide it. But look -> http://php.net/manual/en/function.sqlite-num-rows.php . How can PHP folks do it, if its not possible ? :-) – Sebastian Dusza Mar 21 '11 at 19:01
3 Answers
10
No, it doesn't. However, you can use last() and at() together to get the result.
QSqlQuery q;
q.exec("select * from table");
q.last();
qDebug() << q.at() + 1;

Pluto
- 133
- 1
- 5
4
No, it does't. SQLite is one of the databases for which the size of the query is not directly available. BTW: A Google-query for "qt sqlite QSqlQuery size" had this StackOverflow question as first answer.
-
Well I googled it for a while and couldn't find anything precise. Anyway thx for answer. Franky I think its strange, sqlite api for PHP has num_rows function. – Sebastian Dusza Mar 21 '11 at 16:05
-
1I ran that search today and first result was for *this* question. – Antonio Pérez Sep 15 '15 at 11:05
-
0
I also faced the same issue with SQLite and Qt.
As a solution I used
if (query.next())
{
}
to identify the query returns values or not.
But be careful it directs you to the first record. And if you need the no of records exactly, then this is not a solution.

Hareen Laks
- 1,432
- 2
- 17
- 33