I can confirm the observation - also moving data from SQL Server DB via ODBC to Postgres Database.
The following code executes fairly quickly:
...
// lesen
tabModelSource.setTable(sTableSource);
if (!tabModelSource.select()) {
qCritical() << tabModelSource.lastError();
return;
}
int r = tabModelSource.rowCount();
while (tabModelSource.canFetchMore()) {
tabModelSource.fetchMore();
}
qDebug() << "Total number of rows =" << r;
QSqlDatabase odbcsql = QSqlDatabase::addDatabase("QODBC", "odbcsql");
...
QSqlDatabase odbcsql = QSqlDatabase::database("odbcsql");
// lesen
QSqlTableModel tabModelSource(nullptr, odbcsql);
tabModelSource.setTable(sTableSource);
if (!tabModelSource.select()) {
qCritical() << tabModelSource.lastError();
return;
}
int r = tabModelSource.rowCount();
while (tabModelSource.canFetchMore()) {
tabModelSource.fetchMore();
}
qDebug() << "Total number of rows =" << r;
To copy to clipboard, switch view to plain text mode
This code takes less than a second for 160000 entries - way too many records to transfer in 1 seconds over my slow internet connection. So apparently data is not transferred and cached in the calls to fetchMore(), yet.
Now, when I start to access the data:
qDebug() << "Caching table data";
std::vector<QList<QVariant> > data;
for (int i=0; i<r; ++i) {
QSqlRecord rec
(tabModelSource.
record(i
));
// <--- very slow access QList<QVariant> vals;
for (int j=0; j<rec.count(); ++j)
vals.append(rec.value(j));
data.push_back(vals);
}
qDebug() << "Caching table data";
std::vector<QList<QVariant> > data;
for (int i=0; i<r; ++i) {
QSqlRecord rec(tabModelSource.record(i)); // <--- very slow access
QList<QVariant> vals;
for (int j=0; j<rec.count(); ++j)
vals.append(rec.value(j));
data.push_back(vals);
}
To copy to clipboard, switch view to plain text mode
Every time I access a record, the data is crawling over my internet connection at about 30...56kB/s (and my network really isn't than slow!)
Conclusion:
1. ODBC-driver doesn't do any caching
2. ODBC-driver is basically unusable for real-life data in Qt model/view classes
Questions:
Does anyone know how to tell the ODBC-driver to retrieve the data in larger chunks, instead value-by-value?
-Andreas
Bookmarks