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.