Skip to content

Commit

Permalink
Merge pull request #39947 from m-kuhn/db_mgr_error
Browse files Browse the repository at this point in the history
[db manager] Show error messages directly in place
  • Loading branch information
m-kuhn committed Nov 29, 2020
2 parents 2e26204 + 2a30091 commit bcbf71e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 16 additions & 3 deletions python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -46,7 +46,7 @@
QStandardItemModel,
QStandardItem
)
from qgis.PyQt.Qsci import QsciAPIs
from qgis.PyQt.Qsci import QsciAPIs, QsciScintilla

from qgis.core import (
QgsProject,
Expand Down Expand Up @@ -392,6 +392,7 @@ def executeSqlCompleted(self):
model = self.modelAsync.model
quotedCols = []

self.showError(None)
self.viewResult.setModel(model)
self.lblResult.setText(self.tr("{0} rows, {1:.3f} seconds").format(model.affectedRows(), model.secs()))
cols = self.viewResult.model().columnNames()
Expand All @@ -403,7 +404,8 @@ def executeSqlCompleted(self):
self.writeQueryHistory(self.modelAsync.task.sql, model.affectedRows(), model.secs())
self.update()
elif not self.modelAsync.canceled:
DlgDbError.showError(self.modelAsync.error, self)
self.showError(self.modelAsync.error)

self.uniqueModel.clear()
self.geomCombo.clear()

Expand All @@ -426,11 +428,22 @@ def executeSql(self):
self.updateUiWhileSqlExecution(True)
QgsApplication.taskManager().addTask(self.modelAsync.task)
except Exception as e:
DlgDbError.showError(e, self)
self.showError(e)
self.uniqueModel.clear()
self.geomCombo.clear()
return

def showError(self, error):
'''Shows the error or hides it if error is None'''
if error:
self.viewResult.setVisible(False)
self.errorText.setVisible(True)
self.errorText.setText(error.msg)
self.errorText.setWrapMode(QsciScintilla.WrapWord)
else:
self.viewResult.setVisible(True)
self.errorText.setVisible(False)

def _getSqlLayer(self, _filter):
hasUniqueField = self.uniqueColumnCheck.checkState() == Qt.Checked
if hasUniqueField:
Expand Down
14 changes: 12 additions & 2 deletions python/plugins/db_manager/ui/DlgSqlWindow.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>679</width>
<height>525</height>
<width>995</width>
<height>716</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -248,6 +248,16 @@
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsCodeEditorSQL" name="errorText">
<property name="visible">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="viewResult">
<property name="sizePolicy">
Expand Down

0 comments on commit bcbf71e

Please sign in to comment.