PDA

View Full Version : fast quering



codeman
29th December 2009, 10:34
what is the fastest method to select a query over thounds of datas. When I query a select statement to a mssql database it is very slow. I do it like this


QSqlDatabase usedDB = QSqlDatabase::database("mydb") ;
QSqlQuery q("my select statement",usedDB);
q.setForwardOnly(true);
while (q.next())
{
//do my stuff
}//while


is it possible that odbc connections are damn slow ???

P.S.: qt sdk 4.6(mingw) xp sp3

numbat
29th December 2009, 10:52
setForwardOnly must be called before using exec():


QSqlQuery q(usedDB);
q.setForwardOnly(true);
q.exec("My statement");

Other than that it depends on the code represented by '//Do my stuff'.

codeman
29th December 2009, 14:20
hmm thanks for that tip/correction

perhaps it is faster to set a query to a model and iterate over the model? have anbody some expierinces with this???

vcernobai
29th December 2009, 19:51
hmm thanks for that tip/correction

perhaps it is faster to set a query to a model and iterate over the model? have anbody some expierinces with this???

I do not recommend you to retrieve specific data from an sql model if you just need to sort out only some simple select statements. Use directly QSqlQuery::exec() or QSqlQuery::execBatch().
I especially insist on this, if you're using a remote database connection. The model/view approach works very poor remotely.