From b9595b9b7e78fe5ae56e9a106802874ddbea4d35 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 22 Oct 2017 18:36:51 +0200 Subject: [PATCH] Remove the valid flag from the SqliteTableModel class Remove the valid flag from the SqliteTableModel class and remove its usage in the Execute SQL tab of the main window. I believe this hasn't been used for some time now because the main sources of error should really be noticed before the query is even handed over to the model. Additionally the valid flag wasn't as realible either anymore because of the multi-threaded execution of the model queries. --- src/MainWindow.cpp | 21 +++++++-------------- src/sqlitetablemodel.cpp | 8 +------- src/sqlitetablemodel.h | 4 ---- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 85fcaef8..627d9b1b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1081,20 +1081,13 @@ void MainWindow::executeQuery() case SQLITE_ROW: { sqlWidget->getModel()->setQuery(queryPart); - if(sqlWidget->getModel()->valid()) - { - // The query takes the last placeholder as it may itself contain the sequence '%' + number - statusMessage = tr("%1 rows returned in %2ms from: %3").arg( - sqlWidget->getModel()->totalRowCount()).arg(timer.elapsed()).arg(queryPart.trimmed()); - ui->actionSqlResultsSave->setEnabled(true); - ui->actionSqlResultsSaveAsView->setEnabled(!db.readOnly()); - sql3status = SQLITE_OK; - } - else - { - statusMessage = tr("Error executing query: %1").arg(queryPart); - sql3status = SQLITE_ERROR; - } + + // The query takes the last placeholder as it may itself contain the sequence '%' + number + statusMessage = tr("%1 rows returned in %2ms from: %3").arg( + sqlWidget->getModel()->totalRowCount()).arg(timer.elapsed()).arg(queryPart.trimmed()); + ui->actionSqlResultsSave->setEnabled(true); + ui->actionSqlResultsSaveAsView->setEnabled(!db.readOnly()); + sql3status = SQLITE_OK; } case SQLITE_DONE: case SQLITE_OK: diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index f24962d8..e8abe5b2 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -17,7 +17,6 @@ SqliteTableModel::SqliteTableModel(DBBrowserDB& db, QObject* parent, size_t chun , m_db(db) , m_rowCountAdjustment(0) , m_chunkSize(chunkSize) - , m_valid(false) , m_encoding(encoding) { reset(); @@ -132,11 +131,7 @@ void SqliteTableModel::setQuery(const QString& sQuery, bool dontClearHeaders) // do a count query to get the full row count in a fast manner m_rowCountAdjustment = 0; m_rowCount = QtConcurrent::run([=]() { - int count = getQueryRowCount(); - if(count == -1) - m_valid = false; - - return count; + return getQueryRowCount(); }); // headers @@ -148,7 +143,6 @@ void SqliteTableModel::setQuery(const QString& sQuery, bool dontClearHeaders) // now fetch the first entries clearCache(); fetchData(0, m_chunkSize); - m_valid = true; emit layoutChanged(); } diff --git a/src/sqlitetablemodel.h b/src/sqlitetablemodel.h index ea957d70..1734a214 100644 --- a/src/sqlitetablemodel.h +++ b/src/sqlitetablemodel.h @@ -46,8 +46,6 @@ public: Qt::ItemFlags flags(const QModelIndex& index) const; - bool valid() const { return m_valid; } - bool isBinary(const QModelIndex& index) const; void setEncoding(const QString& encoding) { m_encoding = encoding; } @@ -124,8 +122,6 @@ private: */ size_t m_chunkSize; - bool m_valid; //! tells if the current query is valid. - QString m_encoding; /**