Class: QgsQueryResultWidget¶
The QgsQueryResultWidget
class 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¶
Enums
The QueryWidgetMode enum represents various modes for the widget appearance. |
Methods
Copies the query results to the clipboard, as a formatted table. |
|
Starts executing the query. |
|
Displays a message with text title and level in the widget's message bar. |
|
Sets the connection to connection, ownership is transferred to the widget. |
|
Convenience method to set the SQL editor text to sql. |
|
Initializes the widget from options. |
|
Sets the widget mode to widgetMode, default is SqlQueryMode. |
|
Hides the result table and shows the error title and message in the message bar or in the SQL error panel is isSqlError is set. |
|
Triggered when the threaded API fetcher has new tokens to add. |
Signals
Emitted when a new vector SQL (query) layer must be created. |
|
Emitted when the first batch of results has been fetched. |
- 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:
IntEnum
The 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)[source]
Copies a range of the query results to the clipboard, as a formatted table.
Added in version 3.32.
- Parameters:
fromRow (int)
toRow (int)
fromColumn (int)
toColumn (int)
- signal createSqlVectorLayer(providerKey: str, connectionUri: str, options: QgsAbstractDatabaseProviderConnection.SqlVectorLayerOptions)[source]¶
Emitted when a new vector SQL (query) layer must be created.
- Parameters:
providerKey (str) – name of the data provider
connectionUri (str) – the connection URI as returned by
QgsAbstractProviderConnection.uri()
options (QgsAbstractDatabaseProviderConnection.SqlVectorLayerOptions)
- signal firstResultBatchFetched[source]¶
Emitted when the first batch of results has been fetched.
Note
If the query returns no results this signal is not emitted.
- notify(self, title: str | None, text: str | None, level: Qgis.MessageLevel = Qgis.MessageLevel.Info)[source]¶
Displays a message with
text
title
andlevel
in 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
title
andmessage
in the message bar or in the SQL error panel isisSqlError
is set.- Parameters:
title (Optional[str])
message (Optional[str])
isSqlError (bool = False)