QSqlQuery returns record not in right order.
-
I execute some sql request using QSqlQuery. In text i put "ORDER BY SomeParam" in the end. Nex i make a loop:
@while(query.next) {
QSqlRecord record = query.record();
// some code
}@
And my records comes not in that order as in sql table which i can see on my sql browser. What is the reason ? -
Just to amke sure: when you execute the same query in your sql browser the query/result is ok?
-
Query which i use i get from this:
@ QSqlQuery query;
bool bOk = AReportsModel::applyFilter(props, query);@In applyFilter method I do next :
@
bool AReportsModel::applyFilter(const sxProperties & props, QSqlQuery & rQuery) {QSqlQuery query(GET_DATABASE());
query.clear();
// post filter (applies only for new table) QString sPostFilter = getPostFilterString(); bool bResult; if (sPostFilter.isEmpty()) bResult = query.exec(QString("SELECT * FROM %1 ORDER BY %2").arg(tableName()).arg(sxDB::cmd_list::CMD_TIME)); else bResult = query.exec(QString("SELECT * FROM %1 WHERE %2 ORDER BY %3").arg(tableName()).arg(sPostFilter).arg(sxDB::cmd_list::CMD_TIME)); setQuery(query); rQuery = query; return bResult;
}
@
Im using qt version 4.8.4 and PostgreSQL as database.I store QString value of query.lastQuery() before my while loop and execute it in SQL Browser and get right result.