Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlquery size returns -1 when forwardOnly is enabled

QSqlquery size returns -1 when forwardOnly is enabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 213 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiruahxh
    wrote on last edited by Kiruahxh
    #1

    Hi,
    With a postgres database on linux with QPSQL driver, I cannot retrieve the number of results of a query with "size()" method, it always returns -1.
    Ex:

    bool hasSupport = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize);
    QSqlQuery query;
    query.setForwardOnly(true); // this prevents from getting nbRows
    query.exec("select 123");
    int nbRows = query.size();
    query.first();
    int val = query.value(0).toInt();
    
    "hasSupport => true"
    "nbRows => -1"
    "val => 123"
    

    I guess that when using QPSQL driver, setForwardOnly() is incompatible with size()?
    I didn't see it documented anywhere

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      ForwardOnly queries can't return the complete query size.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved