Results 1 to 4 of 4

Thread: SQLQuery->first() not working

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default SQLQuery->first() not working

    Hello!

    I'm developing a software where I need to do some queries in a MySQL server. I created a C++ class where functions are used with a global query to call the data from the server and than be used in the app.

    Till now everything was fine and I managed to do some code with the query working well, till I got a specific case where, for reasons I can't comprehend, the query is always returning "false" for the first() function. Here is the code:

    Qt Code:
    1. bool SQLFunctions::pesquisaTabelaTendencia(QString passagem, int inicio, int fim)
    2. {
    3. if (global_query->exec("SELECT DATE_FORMAT(ev_datetime, '%d-%m-%Y'), TIME(ev_datetime),"
    4. "EV_VALOR_ECG, EV_VALOR_RESP, EV_VALOR_OXI, EV_VALOR_TEMP1, EV_VALOR_TEMP2, EV_VALOR_PI1, EV_VALOR_PI2, "
    5. "EV_VALOR_PNI, EV_VALOR_CAP, EV_VALOR_ST_I, EV_VALOR_ST_II, EV_VALOR_ST_III, EV_VALOR_ST_aVR, EV_VALOR_ST_aVL, EV_VALOR_ST_aVF, EV_VALOR_ST_V "
    6. "FROM tendencia_1_5 "
    7. "WHERE pt_passagem_prontuario = '" + passagem + "' "
    8. "ORDER BY ev_datetime DESC LIMIT " + QString::number(inicio) + ", " + QString::number(fim)))
    9. {
    10. qDebug() << "Deu certo" << global_query->isActive() << global_query->isValid() << global_query->isSelect();
    11. global_query->first();
    12. qDebug() << "Deu certo" << global_query->isActive() << global_query->isValid() << global_query->isSelect();
    13. if (global_query->first())
    14. return true;
    15. else
    16. return false;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    Actually this functions is a little bit different to the one I'm actually wanting tu use, since I modified it to do my research in the problem.

    So the results are that the exec() function works very well, but the first() function always return false (isActive() and isSelect() also returns true while isValid() always returns false, as one would expect given that first() doesn't work).

    It's good to remember that the class has similar functions that only have the QString in the exec() function different, and it has performed very nice till now; the unique problem happens with this function, where the first() returns false and I can't see why. Also I'm sure that the sql select statement is correct, since it was taken from another software that works fine with it.

    Does anyone have any explanation?


    Thanks,

    Momergil

  2. #2
    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: SQLQuery->first() not working

    Looks like an empty result set. Are you sure that the query will return any records ?

  3. The following user says thank you to Lesiok for this useful post:

    Momergil (25th October 2012)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQLQuery->first() not working

    Quote Originally Posted by Lesiok View Post
    Looks like an empty result set. Are you sure that the query will return any records ?
    Yes. Performing the same query with that other working software I mentioned several data is found.

    How can I see if it's the case of an 'empty result set'?

    ---
    Complementing:

    I tryied using QSQLDatabase::lastError() and QSqlQuery::lastError(), but nothing appeared.


    Added after 5 minutes:


    Actually, you're right! The first paramenter was being passed empty because I missed a line of code I though I had already written :P

    Thanks very much,

    Momergil
    Last edited by Momergil; 25th October 2012 at 19:51.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQLQuery->first() not working

    It's better to use hasNext() and next() rather than first().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. from sqlquery to qstringlist
    By ditsikts in forum Newbie
    Replies: 4
    Last Post: 4th February 2016, 19:18
  2. SQLQuery assigning column
    By nethanjavier in forum Qt Programming
    Replies: 8
    Last Post: 30th July 2012, 03:53
  3. SOLVED : SqlQuery can't insert data.
    By naptizaN in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2012, 14:32
  4. SQLQuery usage of RAM
    By Momergil in forum Qt Programming
    Replies: 5
    Last Post: 21st May 2012, 13:45
  5. sqlQuery executing return nothing
    By ar_a24 in forum Qt Programming
    Replies: 0
    Last Post: 26th February 2011, 07:04

Tags for this Thread

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.