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