Skip to content
Permalink
Browse files
Merge pull request #44051 from elpaso/connections-api-results-widget
Connections api results widget
  • Loading branch information
elpaso committed Jul 10, 2021
2 parents 2071cd8 + a94e089 commit 91370a908255e5a3e7a7b6ef0a62a93ca4fd1156
Showing with 6,731 additions and 195 deletions.
  1. +21 −0 python/core/auto_additions/qgis.py
  2. +2 −0 python/core/auto_generated/browser/qgslayeritem.sip.in
  3. +66 −12 python/core/auto_generated/providers/qgsabstractdatabaseproviderconnection.sip.in
  4. +25 −0 python/core/auto_generated/qgis.sip.in
  5. +41 −1 python/core/auto_generated/qgsqueryresultmodel.sip.in
  6. +39 −0 python/gui/auto_generated/codeeditors/qgscodeeditorsql.sip.in
  7. +99 −0 python/gui/auto_generated/qgsqueryresultwidget.sip.in
  8. +1 −0 python/gui/gui_auto.sip
  9. +68 −0 src/app/browser/qgsinbuiltdataitemproviders.cpp
  10. +9 −0 src/core/browser/qgslayeritem.cpp
  11. +1 −0 src/core/browser/qgslayeritem.h
  12. +688 −7 src/core/providers/ogr/qgsgeopackageproviderconnection.cpp
  13. +14 −6 src/core/providers/ogr/qgsgeopackageproviderconnection.h
  14. +980 −2 src/core/providers/qgsabstractdatabaseproviderconnection.cpp
  15. +116 −45 src/core/providers/qgsabstractdatabaseproviderconnection.h
  16. +34 −0 src/core/qgis.h
  17. +52 −13 src/core/qgsqueryresultmodel.cpp
  18. +46 −6 src/core/qgsqueryresultmodel.h
  19. +3 −0 src/gui/CMakeLists.txt
  20. +43 −4 src/gui/codeeditors/qgscodeeditorsql.cpp
  21. +42 −1 src/gui/codeeditors/qgscodeeditorsql.h
  22. +502 −0 src/gui/qgsqueryresultwidget.cpp
  23. +213 −0 src/gui/qgsqueryresultwidget.h
  24. +14 −1 src/providers/hana/qgshanaproviderconnection.cpp
  25. +6 −4 src/providers/hana/qgshanaproviderconnection.h
  26. +27 −1 src/providers/mssql/qgsmssqlproviderconnection.cpp
  27. +4 −5 src/providers/mssql/qgsmssqlproviderconnection.h
  28. +4 −0 src/providers/oracle/qgsoracleconn.cpp
  29. +16 −25 src/providers/oracle/qgsoracleprovider.cpp
  30. +1,161 −1 src/providers/oracle/qgsoracleproviderconnection.cpp
  31. +4 −1 src/providers/oracle/qgsoracleproviderconnection.h
  32. +4 −2 src/providers/postgres/qgspostgresconn.h
  33. +1,013 −6 src/providers/postgres/qgspostgresproviderconnection.cpp
  34. +5 −5 src/providers/postgres/qgspostgresproviderconnection.h
  35. +583 −11 src/providers/spatialite/qgsspatialiteproviderconnection.cpp
  36. +11 −7 src/providers/spatialite/qgsspatialiteproviderconnection.h
  37. +234 −0 src/ui/qgsqueryresultwidgetbase.ui
  38. +2 −0 tests/src/gui/CMakeLists.txt
  39. +164 −0 tests/src/gui/testqgsqueryresultwidget.cpp
  40. +1 −1 tests/src/python/CMakeLists.txt
  41. +5 −1 tests/src/python/test_qgsnewvectortabledialog.py
  42. +86 −3 tests/src/python/test_qgsproviderconnection_base.py
  43. +17 −0 tests/src/python/test_qgsproviderconnection_mssql.py
  44. +52 −10 tests/src/python/test_qgsproviderconnection_ogr_gpkg.py
  45. +32 −9 tests/src/python/test_qgsproviderconnection_oracle.py
  46. +117 −1 tests/src/python/test_qgsproviderconnection_postgres.py
  47. +56 −2 tests/src/python/test_qgsproviderconnection_spatialite.py
  48. +8 −2 tests/src/python/test_qgsqueryresultmodel.py
  49. BIN tests/testdata/projects/relative_paths_gh30387.gpkg
  50. BIN tests/testdata/qgis_server/bug_gh30264_empty_layer_wrong_bbox.gpkg
@@ -315,6 +315,27 @@
# --
Qgis.VectorExportResult.baseClass = Qgis
# monkey patching scoped based enum
Qgis.SqlLayerDefinitionCapability.SubsetStringFilter.__doc__ = "SQL layer definition supports subset string filter"
Qgis.SqlLayerDefinitionCapability.GeometryColumn.__doc__ = "SQL layer definition supports geometry column"
Qgis.SqlLayerDefinitionCapability.PrimaryKeys.__doc__ = "SQL layer definition supports primary keys"
Qgis.SqlLayerDefinitionCapability.UnstableFeatureIds.__doc__ = "SQL layer definition supports disabling select at id"
Qgis.SqlLayerDefinitionCapability.__doc__ = 'SqlLayerDefinitionCapability enum lists the arguments supported by the provider when creating SQL query layers.\n\n.. versionadded:: 3.22\n\n' + '* ``SubsetStringFilter``: ' + Qgis.SqlLayerDefinitionCapability.SubsetStringFilter.__doc__ + '\n' + '* ``GeometryColumn``: ' + Qgis.SqlLayerDefinitionCapability.GeometryColumn.__doc__ + '\n' + '* ``PrimaryKeys``: ' + Qgis.SqlLayerDefinitionCapability.PrimaryKeys.__doc__ + '\n' + '* ``UnstableFeatureIds``: ' + Qgis.SqlLayerDefinitionCapability.UnstableFeatureIds.__doc__
# --
Qgis.SqlLayerDefinitionCapability.baseClass = Qgis
# monkey patching scoped based enum
Qgis.SqlKeywordCategory.Keyword.__doc__ = "SQL keyword"
Qgis.SqlKeywordCategory.Constant.__doc__ = "SQL constant"
Qgis.SqlKeywordCategory.Function.__doc__ = "SQL generic function"
Qgis.SqlKeywordCategory.Geospatial.__doc__ = "SQL spatial function"
Qgis.SqlKeywordCategory.Operator.__doc__ = "SQL operator"
Qgis.SqlKeywordCategory.Math.__doc__ = "SQL math function"
Qgis.SqlKeywordCategory.Aggregate.__doc__ = "SQL aggregate function"
Qgis.SqlKeywordCategory.String.__doc__ = "SQL string function"
Qgis.SqlKeywordCategory.Identifier.__doc__ = "SQL identifier"
Qgis.SqlKeywordCategory.__doc__ = 'SqlKeywordCategory enum represents the categories of the SQL keywords used by the SQL query editor.\n\n.. note::\n\n The category has currently no usage, but it was planned for future uses.\n\n.. versionadded:: 3.22\n\n' + '* ``Keyword``: ' + Qgis.SqlKeywordCategory.Keyword.__doc__ + '\n' + '* ``Constant``: ' + Qgis.SqlKeywordCategory.Constant.__doc__ + '\n' + '* ``Function``: ' + Qgis.SqlKeywordCategory.Function.__doc__ + '\n' + '* ``Geospatial``: ' + Qgis.SqlKeywordCategory.Geospatial.__doc__ + '\n' + '* ``Operator``: ' + Qgis.SqlKeywordCategory.Operator.__doc__ + '\n' + '* ``Math``: ' + Qgis.SqlKeywordCategory.Math.__doc__ + '\n' + '* ``Aggregate``: ' + Qgis.SqlKeywordCategory.Aggregate.__doc__ + '\n' + '* ``String``: ' + Qgis.SqlKeywordCategory.String.__doc__ + '\n' + '* ``Identifier``: ' + Qgis.SqlKeywordCategory.Identifier.__doc__
# --
Qgis.SqlKeywordCategory.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DriveType.Unknown.__doc__ = "Unknown type"
Qgis.DriveType.Invalid.__doc__ = "Invalid path"
Qgis.DriveType.Removable.__doc__ = "Removable drive"
@@ -140,6 +140,8 @@ Returns icon for point cloud layer

:return: the layer name
%End
virtual QgsAbstractDatabaseProviderConnection *databaseConnection() const;


};

@@ -82,13 +82,20 @@ Returns the next result row or an empty row if there are no rows left.
.. seealso:: :py:func:`rewind`
%End

qlonglong fetchedRowCount( ) const;
long long fetchedRowCount( ) const;
%Docstring
Returns the number of fetched rows.

.. seealso:: :py:func:`rowCount`
%End

long long rowCount( ) const;
%Docstring
Returns the number of rows returned by a SELECT query or Qgis.FeatureCountState.UnknownCount if unknown.

.. seealso:: :py:func:`fetchedRowCount`
%End


// Python iterator
QueryResult *__iter__();
@@ -118,9 +125,28 @@ Returns the number of fetched rows.



double queryExecutionTime( );
%Docstring
Returns the query execution time in milliseconds.
%End

void setQueryExecutionTime( double queryExecutionTime );
%Docstring
Sets the query execution time to ``queryExecutionTime`` milliseconds.
%End


};

struct SqlVectorLayerOptions
{
QString sql; //!< The SQL expression that defines the SQL (query) layer
QString filter; //!< Additional subset string (provider-side filter), not all data providers support this feature: check support with SqlLayerDefinitionCapability::Filters capability
QString layerName; //!< Optional name for the new layer
QStringList primaryKeyColumns; //!< List of primary key column names
QString geometryColumn; //!< Name of the geometry column
bool disableSelectAtId;
};

struct TableProperty
{
@@ -294,6 +320,11 @@ This information is calculated from the geometry columns types.

};

struct SpatialIndexOptions
{
QString geometryColumnName;
};

enum Capability
{
CreateVectorTable,
@@ -362,6 +393,13 @@ Returns connection geometry column capabilities (Z, M, SinglePart, Curves).
.. versionadded:: 3.16
%End

virtual Qgis::SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities();
%Docstring
Returns SQL layer definition capabilities (Filters, GeometryColumn, PrimaryKeys).

.. versionadded:: 3.22
%End


virtual QString tableUri( const QString &schema, const QString &name ) const throw( QgsProviderConnectionException );
%Docstring
@@ -434,7 +472,7 @@ Renames a raster table with given ``schema`` (schema is ignored if not supported
%Docstring
Creates a new schema with the specified ``name``.

:raises QgsProviderConnectionException:
:raises QgsProviderConnectionException: if any errors are encountered.
%End

virtual void dropSchema( const QString &name, bool force = false ) const throw( QgsProviderConnectionException );
@@ -486,7 +524,6 @@ Adds a field.
.. versionadded:: 3.16
%End


virtual void renameSchema( const QString &name, const QString &newName ) const throw( QgsProviderConnectionException );
%Docstring
Renames a schema with the specified ``name``.
@@ -496,7 +533,7 @@ Raises a :py:class:`QgsProviderConnectionException` if any errors are encountere

it is responsibility of the caller to handle open layers and registry entries.

:raises QgsProviderConnectionException:
:raises QgsProviderConnectionException: if any errors are encountered.
%End

virtual QList<QList<QVariant>> executeSql( const QString &sql, QgsFeedback *feedback = 0 ) const throw( QgsProviderConnectionException );
@@ -506,6 +543,15 @@ Executes raw ``sql`` and returns the (possibly empty) list of results in a multi
.. seealso:: :py:func:`execSql`

:raises QgsProviderConnectionException: if any errors are encountered.
%End

virtual QgsVectorLayer *createSqlVectorLayer( const SqlVectorLayerOptions &options ) const throw( QgsProviderConnectionException ) /Factory/;
%Docstring
Creates and returns a (possibly invalid) vector layer based on the ``sql`` statement and optional ``options``.

:raises QgsProviderConnectionException: if any errors are encountered or if SQL layer creation is not supported.

.. versionadded:: 3.22
%End

virtual QueryResult execSql( const QString &sql, QgsFeedback *feedback = 0 ) const throw( QgsProviderConnectionException );
@@ -526,11 +572,6 @@ Vacuum the database table with given ``schema`` and ``name`` (schema is ignored
:raises QgsProviderConnectionException: if any errors are encountered.
%End

struct SpatialIndexOptions
{
QString geometryColumnName;
};

virtual void createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options = QgsAbstractDatabaseProviderConnection::SpatialIndexOptions() ) const throw( QgsProviderConnectionException );
%Docstring
Creates a spatial index for the database table with given ``schema`` and ``name`` (schema is ignored if not supported by the backend).
@@ -601,8 +642,10 @@ Returns the fields of a ``table`` and ``schema``.

.. note::

The default implementation creates a temporary vector layer, providers may
choose to override this method for a greater efficiency.
the default implementation creates a temporary vector layer, providers may
choose to override this method for a greater efficiency of to overcome provider's
behavior when the layer does not expose all fields (GPKG for example hides geometry
and primary key column).

:raises QgsProviderConnectionException: if any errors are encountered.

@@ -613,7 +656,7 @@ Returns the fields of a ``table`` and ``schema``.
%Docstring
Returns a list of native types supported by the connection.

:raises QgsProviderConnectionException:
:raises QgsProviderConnectionException: if any errors are encountered.

.. versionadded:: 3.16
%End
@@ -623,6 +666,17 @@ Returns a list of native types supported by the connection.
Returns the provider key.

.. versionadded:: 3.16
%End

virtual QMap<Qgis::SqlKeywordCategory, QStringList> sqlDictionary();
%Docstring
Returns a dictionary of SQL keywords supported by the provider.
The default implementation returns an list of common reserved words under the
"Keyword" and "Constant" categories.

Subclasses should add provider- and/or connection- specific words.

.. versionadded:: 3.22
%End

protected:
@@ -226,6 +226,29 @@ The development version
UserCanceled,
};

enum class SqlLayerDefinitionCapability
{
SubsetStringFilter,
GeometryColumn,
PrimaryKeys,
UnstableFeatureIds
};
typedef QFlags<Qgis::SqlLayerDefinitionCapability> SqlLayerDefinitionCapabilities;


enum class SqlKeywordCategory
{
Keyword,
Constant,
Function,
Geospatial,
Operator,
Math,
Aggregate,
String,
Identifier
};

enum class DriveType
{
Unknown,
@@ -362,6 +385,8 @@ QFlags<Qgis::BrowserItemCapability> operator|(Qgis::BrowserItemCapability f1, QF

QFlags<Qgis::SublayerQueryFlag> operator|(Qgis::SublayerQueryFlag f1, QFlags<Qgis::SublayerQueryFlag> f2);

QFlags<Qgis::SqlLayerDefinitionCapability> operator|(Qgis::SqlLayerDefinitionCapability f1, QFlags<Qgis::SqlLayerDefinitionCapability> f2);




@@ -44,18 +44,58 @@ Constructs a QgsQueryResultModel from a ``queryResult`` with optional ``parent``
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;


virtual void fetchMore( const QModelIndex &parent );

virtual bool canFetchMore( const QModelIndex &parent ) const;


QStringList columns() const;
%Docstring
Returns the column names
%End

QgsAbstractDatabaseProviderConnection::QueryResult queryResult() const;
%Docstring
Returns the query result

.. versionadded:: 3.22
%End

public slots:

void rowsReady( const QList<QList<QVariant> > &rows );
%Docstring
Triggered when ``newRows`` have been fetched and can be added to the model
Triggered when ``newRows`` have been fetched and can be added to the model.
%End

void cancel();
%Docstring
Cancels the row fetching.
%End


signals:

void fetchingComplete();
%Docstring
Emitted when rows have been fetched (all of them or a batch if `maxRows` was passed to :py:func:`~QgsQueryResultModel.fetchMoreRows` )
or when the fetching has been stopped (canceled).

.. seealso:: :py:func:`fetchMoreRows`
%End

void fetchMoreRows( qlonglong maxRows );
%Docstring
Emitted when more rows are requested.

:param maxRows: the number of rows that will be fetched.
%End

void fetchingStarted();
%Docstring
Emitted when fetching of rows has started
%End

};

/************************************************************************
@@ -31,11 +31,50 @@ code autocompletion.
Constructor for QgsCodeEditorSQL
%End


virtual ~QgsCodeEditorSQL();

void setFields( const QgsFields &fields );
%Docstring
Set field names to be added to the lexer API.

.. versionadded:: 3.14
%End

void setFieldNames( const QStringList &fieldNames );
%Docstring
Set field names to ``fieldNames`` to be added to the lexer API.

.. versionadded:: 3.18
%End

QStringList fieldNames() const;
%Docstring
Returns field names from the lexer API.

.. versionadded:: 3.22
%End

void setExtraKeywords( const QStringList &extraKeywords );
%Docstring
Set extra keywords to ``extraKeywords``.

Extra keywords are usually added
from provider connections and represent function and other provider specific
keywords.

.. versionadded:: 3.22
%End

QStringList extraKeywords() const;
%Docstring
Returns the extra keywords.

Extra keywords are usually added
from provider connections and represent function and other provider specific
keywords.

.. versionadded:: 3.22
%End

protected:

0 comments on commit 91370a9

Please sign in to comment.