From time to time, the following problem was discussed. However, there was never a solution to the problem. As I found out, there is a difference in repeating lines back and forth. Iterating forward with QSqlQuery::next() can lead to only one row, however, reverse iteration with QSqlQuery::previous() will always find all rows. Whether the forward iteration is explicitly set or not has no effect.
Edit: Deleted Links
Regarding the Qt documentation, the correct approach would be:
QSqlQuery q = db.exec("SELECT * FROM Table"); while (q.next()) { // Do something with row... }
However, this will result in only one line. The reverse iteration will contain all the lines.
QSqlQuery q = db.exec("SELECT * FROM Table"); if (q.last()) { do { // Do something with row... } while (q.previous()); }
Reverse iteration can be very slow and should be avoided. Does anyone know why this is not working in advanced iteration?
Edit: This behavior is not always reproducible for me, and sometimes it happens, sometimes not. The database contains more than one row in this case. The problem arises precisely in this piece of code. Is there anyone with the same problem?
Edit 2: It looks like the bug was fixed in Qt 4.8.5.
My current environment: Windows 7 (SP1), Qt 4.8.5.
source share