Results 1 to 6 of 6

Thread: QSqlQuery: can't find any issues and should return data but isValid = false

  1. #1
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default QSqlQuery: can't find any issues and should return data but isValid = false

    Hello,
    I have a QSqlQuery where query.isValid = false and query.size() = 0, but I can't figure out why. It was working fine a couple weeks ago (famous last words). I have checked and confirmed the following:

    -DB is open.
    -query.exec() = true
    -query.lastError() = QSqlError("", "", "")
    -SQL syntax is valid (query works fine and returns results when output with qDebug() and run in Sequel Pro; also changing or simplifying the query doesn't affect anything)
    -There is data to be returned, so it is not that the query has no results (see above)

    Qt Code:
    1. QString orderID = appInfo->orderID;
    2.  
    3. QString queryString = "SELECT order_item.qty_ordered, order_item.sku, order_item.name, order_item.price FROM order_item JOIN order ON order_item.order_id = order.entity_id WHERE order_item.qty_ordered > 0 AND order.increment_id = '" + orderID + "';";
    4.  
    5. QSqlQuery query(queryString, QSqlDatabase::database("gx_db")); // I have multiple DBs connected, just specifying which one here
    6.  
    7. while(query.next()) {
    8. qDebug() << "Why isn't this showing up??";
    9. QJsonObject obj;
    10. obj.insert("qty", query.value("qty_ordered").toString());
    11. obj.insert("sku", query.value("sku").toString());
    12. obj.insert("description", query.value("name").toString());
    13. obj.insert("salePrice", query.value("price").toString());
    14.  
    15. array.append(obj);
    16. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas? I'm stumped.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQuery: can't find any issues and should return data but isValid = false

    Try removing the semicolon from inside the query string.

  3. #3
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QSqlQuery: can't find any issues and should return data but isValid = false

    Hi Chris,
    I forgot to mention in my post, that was something that I had actually already tried. Still no luck.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery: can't find any issues and should return data but isValid = false

    What is the result of QSqlDatabase::database("gx_db").isValid() ?

  5. #5
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QSqlQuery: can't find any issues and should return data but isValid = false

    Both isValid() and isOpen() return true.

  6. #6
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QSqlQuery: can't find any issues and should return data but isValid = false

    This is looking like an issue with our test server that I was using. It works on our other server. So thanks for the trouble-shooting attempts, but it seems like a behind the scenes problem!

Similar Threads

  1. Replies: 1
    Last Post: 3rd May 2015, 22:38
  2. Replies: 1
    Last Post: 18th July 2011, 13:12
  3. Why does QSqlQuery::prepare() return false?
    By NotANoob in forum Qt Programming
    Replies: 2
    Last Post: 20th April 2011, 20:05
  4. qdbus connect return always FALSE
    By ciberkids in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2009, 15:17
  5. QSqlQuery::isValid returns false
    By mismael85 in forum Qt Programming
    Replies: 24
    Last Post: 8th September 2008, 00:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.