Fix code to determine the total row number before a SQL dump

Before running the actual SQL dump we need to determine the total number
of rows in the database in order to show a progress bar. This code
didn't work as expected since the multithreading changes. On the one
hand it would produce occasional error messages in the console and maybe
even crash. On the other hand the resulting value would always be zero
which in turn leads to the progress bar not working. Both issues are
fixed by rewriting the code here.

See issue #1476.
This commit is contained in:
Martin Kleusberg
2018-07-14 19:12:15 +02:00
parent 9d4c20e603
commit fdc0a6a514

View File

@@ -628,9 +628,11 @@ bool DBBrowserDB::dump(const QString& filePath,
it.remove();
} else {
// Otherwise get the number of records in this table
SqliteTableModel tableModel(*this);
tableModel.setTable(sqlb::ObjectIdentifier("main", it.value()->name()));
numRecordsTotal += tableModel.rowCount();
SqliteTableModel m(*this);
m.setQuery(QString("SELECT COUNT(*) FROM %1;")
.arg(sqlb::ObjectIdentifier("main", it.value()->name()).toString()));
if(m.completeCache())
numRecordsTotal += m.data(m.index(0, 0)).toUInt();
}
}