I am using QT, on a Windows 10 box. I am connecting to a MS_SQL server
to pull records so that I can relocate them in a Postgres database.
I'm using the QSqlDatabase
class then an QSqlQuery
to pull rows. This is shockingly slow ~2 rows / second. I was expecting performance maybe 500 times faster than this. Is this the sort of performance I have to deal with, or am I missing something?
Here is a simplified version of what I'm trying to do. This performs at about 2Hz.
int main(int argc, char *argv[])
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
db.setDatabaseName("DRIVER={SQL Server};Server=10.10.1.32;Database=[DB_NAME];Uid=[UID];pwd=[PWD]");
if (!db.open()) return -1;
QSqlQuery query;
bool worked = query.exec("select * from [TABLE_NAME]");
if (!worked) return -2;
while(query.next())
{
QSqlRecord record = query.record();
for(int i = 0; i < query.record().count(); i++)
{
QVariant value = record.value(i);
fprintf(stdout, "%s\t",qPrintable(value.toString()));
}
fprintf(stdout, "\n");
}
}
答案 0 :(得分:0)
好吧,我的一个伙伴弄清楚了事情。事实证明,QQuery的默认设置是使用双向游标-至少与ODBC驱动程序一起使用。
QQuery具有属性“ forwardOnly”。将其设置为true,虽然代码不会加快500倍(就像我期望的那样),但确实可以加快250倍。是的,一点都不夸张。
这是上面示例的mod。
QSqlQuery query;
query.setForwardOnly(true);
bool worked = query.exec("select * from [TABLE_NAME]");