Results 1 to 2 of 2

Thread: Wierd behaviour of QSQLQuery

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Wierd behaviour of QSQLQuery

    Hi,

    I have a program that uses two QSQLQueries

    Qt Code:
    1. QSqlQuery lktable(database);
    2. QSqlQuery atable(database);
    To copy to clipboard, switch view to plain text mode 

    Using them like this
    Qt Code:
    1. sql = "SELECT SYS_COD,PLOT_COD,NUMSEASON,CROP_COD,ACTY_COD,FORA_COD FROM crpforamanfeed WHERE SYS_COD = 'KE20061129ILREMBMZCTB' AND LIVE_ICOD = '001'";
    2. if (lktable.exec(sql))
    3. {
    4. {
    5. while (lktable.next())
    6. {
    7. ...
    8. sql = "SELECT period_id,tim FROM crpforamanfeedperiods WHERE SYS_COD = 'KE20061129ILREMBMZCTB' AND PLOT_COD = '001' AND NUMSEASON = '01' AND CROP_COD = 'BX' AND ACTY_COD = '006' AND FORA_COD = '001' AND SYS_COD = 'KE20061129ILREMBMZCTB' AND LIVE_ICOD = '001'";
    9. if (atable.exec(sql))
    10. {
    11. temp = 0;
    12. while (atable.next());
    13. {
    14. if ((atable.value(0).toInt() >= 1) &&
    15. (atable.value(0).toInt() >= nperiods))
    16. m_items[pos2].currentValues[atable.value(0).toInt()-1] = atable.value(1);
    17. temp++;
    18. }
    19.  
    20. qWarning() << "End of Setting data:" << temp;
    21. }
    22. else
    23. {
    24. qWarning() << "Error: " << atable.lastError().databaseText();
    25. qWarning() << "Executing: " << sql;
    26. }
    27.  
    28. ...
    29. }
    30. }
    31. else
    32. {
    33. qWarning() << "Error: " << lktable.lastError().databaseText();
    34. qWarning() << "Executing: " << sql;
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

    exec() does not return false, but Although the sql excuted in "if (atable.exec(sql))" is correct (! tested in a terminal) an should return 12 rows. atable is invalid but enters into the while(atable.next()) resulting in temp = 1 ....

    Why if it is invalid next returns true!

    Thanks,
    Carlos.

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Re: Wierd behaviour of QSQLQuery

    Well!!!

    I am complete idiot!!

    I have while ending in ; ! while (atable.next());

    Fixed!

Similar Threads

  1. Replies: 1
    Last Post: 18th July 2011, 12:12
  2. Wierd Problem
    By kurrachow in forum Newbie
    Replies: 2
    Last Post: 25th April 2011, 09:50
  3. am I wierd?
    By stampecarlsson in forum Newbie
    Replies: 6
    Last Post: 2nd August 2010, 08:49
  4. Wierd behaviour in a slot routine
    By koenig in forum Newbie
    Replies: 7
    Last Post: 29th January 2010, 07:27
  5. Replies: 14
    Last Post: 19th March 2007, 08:48

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
  •  
Qt is a trademark of The Qt Company.