Why QSqlQuery query.next() returns false
-
wrote on 28 Feb 2014, 09:55 last edited by
Hello... Why query.next() returns false, when query.isSelected() and query.isActive() return true. And datas for column numbers and index of EventNote are correct and i'm sure that there is data in the database. Here is the code:
@
QVector<QString> DataBase::GetEventNote(int eventId)
{QSqlQuery query; query.prepare("SELECT * FROM Events WHERE idEvent=(?)"); query.addBindValue("eventId");
if(!query.exec()) // -> returns true
{
QMessageBox mb;
mb.setText(query.lastError().text());
mb.setWindowIcon(QIcon("icon.png"));
mb.exec();
}
QVector<QString> debug1;
bool v = query.isValid(); // -> returns false
bool s = query.isSelect(); // -> returns true
bool a = query.isActive(); // -> returns true
bool b = query.first(); // -> returns false
bool l = query.last(); // -> returns false
bool p = query.previous(); // -> returns false
QSqlRecord sr = query.record();
int brsr = sr.count(); // -> returns correct number of columns
QString str = query.lastQuery();const QSqlResult *r =query.result();
int nameCol = sr.indexOf("EventNote"); // index of the field "EventNote" is correct (index 5)
while (query.next()) // -> returns false
{
QString debug2 = query.value(nameCol).toString(); // output all EventNote
debug1.push_back(debug2);
}return debug1;
}@
-
wrote on 10 Mar 2014, 14:37 last edited by
Hi,
in your comments there are some strange values (first returns false, last returns false, ....).
Can you print lastError after first()? -
wrote on 11 Mar 2014, 22:25 last edited by
Somehow i fix this :)