diff --git a/src/gui/qgsqueryresultwidget.cpp b/src/gui/qgsqueryresultwidget.cpp index 138e24c1dab4..bcaec9468ba1 100644 --- a/src/gui/qgsqueryresultwidget.cpp +++ b/src/gui/qgsqueryresultwidget.cpp @@ -172,7 +172,11 @@ void QgsQueryResultWidget::executeQuery() cancelRunningQuery(); if ( mConnection ) { - const QString sql { mSqlEditor->text( ) }; + QString sql { mSqlEditor->text() }; + if ( mSqlEditor->hasSelectedText() ) + { + sql = mSqlEditor->selectedText(); + } bool ok = false; mCurrentHistoryEntryId = QgsGui::historyProviderRegistry()->addEntry( QStringLiteral( "dbquery" ),