Hi. I'm exporting some data from a Firebird database to a text file.
The code is as follow:
db.setHostName("127.0.0.1");
db.setDatabaseName("DATABASE");
db.setPort(3052);
db.setUserName("USER");
db.setPassword("PASS");
if (db.open()) {
query.prepare(SQL);
query.setForwardOnly(true);
if (query.exec()) {
QFile file("C:/Users/NAME/Desktop/Sync.txt");
while (query.next()) {
for (int i = 0; i < query.record().count(); ++i) {
rec = rec + query.value(i).toString().append("|");
}
file.write(rec.append("\n").toStdString().c_str());
}
file.close();
} else {
qDebug() << "Error: " << file.errorString();
}
} else {
qDebug() << "Error: " << query.lastError().text();
}
} else {
qDebug() << "Error: " << db.lastError().databaseText();
}
QSqlDatabase db = QSqlDatabase::addDatabase("QIBASE");
db.setHostName("127.0.0.1");
db.setDatabaseName("DATABASE");
db.setPort(3052);
db.setUserName("USER");
db.setPassword("PASS");
if (db.open()) {
QSqlQuery query(db);
query.prepare(SQL);
query.setForwardOnly(true);
if (query.exec()) {
QFile file("C:/Users/NAME/Desktop/Sync.txt");
if (file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
while (query.next()) {
QString rec;
for (int i = 0; i < query.record().count(); ++i) {
rec = rec + query.value(i).toString().append("|");
}
file.write(rec.append("\n").toStdString().c_str());
}
file.close();
} else {
qDebug() << "Error: " << file.errorString();
}
} else {
qDebug() << "Error: " << query.lastError().text();
}
} else {
qDebug() << "Error: " << db.lastError().databaseText();
}
To copy to clipboard, switch view to plain text mode
The table referenced in the SQL has 10k records. And the exported file is around 1MB.
Using QIBase it takes 05:41 approximately.
The same table in a MySQL database with the same data takes around 01:13.
However, this same firebird database accessed through Delphi. Generate this file under 10 seconds.
Could this poor performance be related to the Qt SQL drivers?
Is there any way I could improve the overall performance of this type of code?
Thanks!
Bookmarks