Don't use the SqliteTableModel class for querying row counts in export

When exporting a database to an SQL file we need to query the row count
of each table to calculate the progress later in the actual export. This
commit replaces the SqliteTableModel class which was used for this
purpose by a simple query function. This might be slightly faster here
but more importantly avoids a progress window being shown for each table
before finally seeing the one for the actual export.

See issue #1476.
This commit is contained in:
Martin Kleusberg
2018-08-10 14:26:00 +02:00
parent 2b6153d9b8
commit 75e4c32bc4
2 changed files with 35 additions and 5 deletions

View File

@@ -639,11 +639,8 @@ bool DBBrowserDB::dump(const QString& filePath,
it.remove();
} else {
// Otherwise get the number of records in this table
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();
numRecordsTotal += querySingeValueFromDb(QString("SELECT COUNT(*) FROM %1;")
.arg(sqlb::ObjectIdentifier("main", it.value()->name()).toString())).toUInt();
}
}
@@ -955,6 +952,35 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log
return true;
}
QVariant DBBrowserDB::querySingeValueFromDb(const QString& statement, bool log)
{
waitForDbRelease();
if(!_db)
return QVariant();
if(log)
logSQL(statement, kLogMsg_App);
QByteArray utf8Query = statement.toUtf8();
sqlite3_stmt* stmt;
if(sqlite3_prepare_v2(_db, utf8Query, utf8Query.size(), &stmt, nullptr) == SQLITE_OK)
{
if(sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_count(stmt) > 0)
{
if(sqlite3_column_type(stmt, 0) != SQLITE_NULL)
{
int bytes = sqlite3_column_bytes(stmt, 0);
if(bytes)
return QByteArray(static_cast<const char*>(sqlite3_column_blob(stmt, 0)), bytes);
else
return "";
}
}
}
return QVariant();
}
bool DBBrowserDB::getRow(const sqlb::ObjectIdentifier& table, const QString& rowid, QVector<QByteArray>& rowdata)
{
waitForDbRelease();

View File

@@ -88,9 +88,13 @@ public:
bool revertToSavepoint(const QString& pointname = "RESTOREPOINT");
bool releaseAllSavepoints();
bool revertAll();
bool dump(const QString& filename, const QStringList& tablesToDump, bool insertColNames, bool insertNew, bool exportSchema, bool exportData, bool keepOldSchema);
bool executeSQL(QString statement, bool dirtyDB = true, bool logsql = true);
bool executeMultiSQL(const QString& statement, bool dirty = true, bool log = false);
QVariant querySingeValueFromDb(const QString& statement, bool log = true);
const QString& lastError() const { return lastErrorMessage; }
/**