Class: QgsQueryResultWidget¶
A widget which allows users to enter and run an SQL query on a DB
connection (an instance of
QgsAbstractDatabaseProviderConnection).
Query results are displayed in a table view. Query execution and result fetching can be interrupted by pressing the “Stop” push button.
The widget supports a few QueryWidgetMode modes that pre-configure the widget appearance to be used in different contexts like when updating the SQL of an existing query layer.
Note
the ownership of the connection is transferred to the widget.
Added in version 3.22.
Class Hierarchy¶
Base classes¶
- class qgis.gui.QgsQueryResultWidget[source]¶
Bases:
QWidget- __init__(parent: QWidget | None = None, connection: QgsAbstractDatabaseProviderConnection | None = None)
Creates a QgsQueryResultWidget with the given
connection, ownership is transferred to the widget.- Parameters:
parent (Optional[QWidget] = None)
connection (Optional[QgsAbstractDatabaseProviderConnection] = None)
- class QueryWidgetMode(*values)¶
Bases:
IntEnumThe QueryWidgetMode enum represents various modes for the widget appearance.
SqlQueryMode: Defaults widget mode for SQL execution and SQL query layer creation.QueryLayerUpdateMode: SQL query layer update mode: the create SQL layer button is renamed to ‘Update’ and the SQL layer creation group box is expanded.
- QueryLayerUpdateMode = 2¶
- SqlQueryMode = 1¶
- copyResults(self)[source]¶
Copies the query results to the clipboard, as a formatted table.
Added in version 3.32.
copyResults(self, fromRow: int, toRow: int, fromColumn: int, toColumn: int) Copies a range of the query results to the clipboard, as a formatted table.
Added in version 3.32.
- signal createSqlVectorLayer[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- signal firstResultBatchFetched[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- notify(self, title: str | None, text: str | None, level: Qgis.MessageLevel = Qgis.MessageLevel.Info)[source]¶
Displays a message with
texttitleandlevelin the widget’s message bar.- Parameters:
title (Optional[str])
text (Optional[str])
level (Qgis.MessageLevel = Qgis.MessageLevel.Info)
- setConnection(self, connection: QgsAbstractDatabaseProviderConnection | None)[source]¶
Sets the connection to
connection, ownership is transferred to the widget.- Parameters:
connection (Optional[QgsAbstractDatabaseProviderConnection])
- setQuery(self, sql: str | None)[source]¶
Convenience method to set the SQL editor text to
sql.- Parameters:
sql (Optional[str])
- setSqlVectorLayerOptions(self, options: QgsAbstractDatabaseProviderConnection.SqlVectorLayerOptions)[source]¶
Initializes the widget from
options.- Parameters:
options (QgsAbstractDatabaseProviderConnection.SqlVectorLayerOptions)
- setWidgetMode(self, widgetMode: QgsQueryResultWidget.QueryWidgetMode)[source]¶
Sets the widget mode to
widgetMode, default is SqlQueryMode.- Parameters:
widgetMode (QgsQueryResultWidget.QueryWidgetMode)
- showError(self, title: str | None, message: str | None, isSqlError: bool = False)[source]¶
Hides the result table and shows the error
titleandmessagein the message bar or in the SQL error panel isisSqlErroris set.- Parameters:
title (Optional[str])
message (Optional[str])
isSqlError (bool = False)