5

I'm wondering does QtSql + Sqlite support QSqlQuery::size() function?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sebastian Dusza
  • 2,470
  • 2
  • 30
  • 54
  • I know its not supported. Maybe there is an alternative driver for QtSql that supports it ? – Sebastian Dusza Mar 21 '11 at 16:06
  • 1
    I 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 Answers3

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.

Community
  • 1
  • 1
hmuelner
  • 8,093
  • 1
  • 28
  • 39
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