diff --git a/python/core/auto_additions/qgis.py b/python/core/auto_additions/qgis.py index 2e8bf6e9a163..0421ba0d5dd8 100644 --- a/python/core/auto_additions/qgis.py +++ b/python/core/auto_additions/qgis.py @@ -315,6 +315,27 @@ # -- Qgis.VectorExportResult.baseClass = Qgis # monkey patching scoped based enum +Qgis.SqlLayerDefinitionCapability.Filter.__doc__ = "SQL layer definition supports filter" +Qgis.SqlLayerDefinitionCapability.GeometryColumn.__doc__ = "SQL layer definition supports geometry column" +Qgis.SqlLayerDefinitionCapability.PrimaryKeys.__doc__ = "SQL layer definition supports primary keys" +Qgis.SqlLayerDefinitionCapability.SelectAtId.__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' + '* ``Filter``: ' + Qgis.SqlLayerDefinitionCapability.Filter.__doc__ + '\n' + '* ``GeometryColumn``: ' + Qgis.SqlLayerDefinitionCapability.GeometryColumn.__doc__ + '\n' + '* ``PrimaryKeys``: ' + Qgis.SqlLayerDefinitionCapability.PrimaryKeys.__doc__ + '\n' + '* ``SelectAtId``: ' + Qgis.SqlLayerDefinitionCapability.SelectAtId.__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" diff --git a/python/core/auto_additions/qgsabstractdatabaseproviderconnection.py b/python/core/auto_additions/qgsabstractdatabaseproviderconnection.py index a6c02fc66b52..bc4b97cdd7c0 100644 --- a/python/core/auto_additions/qgsabstractdatabaseproviderconnection.py +++ b/python/core/auto_additions/qgsabstractdatabaseproviderconnection.py @@ -8,7 +8,3 @@ QgsAbstractDatabaseProviderConnection.GeometryColumnCapability.baseClass = QgsAbstractDatabaseProviderConnection QgsAbstractDatabaseProviderConnection.GeometryColumnCapabilities.baseClass = QgsAbstractDatabaseProviderConnection GeometryColumnCapabilities = QgsAbstractDatabaseProviderConnection # dirty hack since SIP seems to introduce the flags in module -QgsAbstractDatabaseProviderConnection.SqlLayerDefinitionCapability.baseClass = QgsAbstractDatabaseProviderConnection -QgsAbstractDatabaseProviderConnection.SqlLayerDefinitionCapabilities.baseClass = QgsAbstractDatabaseProviderConnection -SqlLayerDefinitionCapabilities = QgsAbstractDatabaseProviderConnection # dirty hack since SIP seems to introduce the flags in module -QgsAbstractDatabaseProviderConnection.SqlKeywordCategory.baseClass = QgsAbstractDatabaseProviderConnection diff --git a/python/core/auto_generated/providers/qgsabstractdatabaseproviderconnection.sip.in b/python/core/auto_generated/providers/qgsabstractdatabaseproviderconnection.sip.in index 50e02338dcdd..4bc46909afa1 100644 --- a/python/core/auto_generated/providers/qgsabstractdatabaseproviderconnection.sip.in +++ b/python/core/auto_generated/providers/qgsabstractdatabaseproviderconnection.sip.in @@ -82,14 +82,14 @@ 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 - qlonglong rowCount( ) const; + long long rowCount( ) const; %Docstring Returns the number of rows returned by a SELECT query or -1 if unknown @@ -130,12 +130,12 @@ Returns the number of rows returned by a SELECT query or -1 if unknown 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; //! If SelectAtId is disabled (default is false), not all data providers support this feature: check support with SqlLayerDefinitionCapability::SelectAtId capability + 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; //!< If SelectAtId is disabled (default is false), not all data providers support this feature: check support with SqlLayerDefinitionCapability::SelectAtId capability }; struct TableProperty @@ -351,31 +351,6 @@ This information is calculated from the geometry columns types. typedef QFlags GeometryColumnCapabilities; - enum SqlLayerDefinitionCapability - { - Filter, - GeometryColumn, - PrimaryKeys, - SelectAtId - }; - - typedef QFlags SqlLayerDefinitionCapabilities; - - - enum SqlKeywordCategory - { - Keyword, - Constant, - Function, - Geospatial, - Operator, - Math, - Aggregate, - String, - Identifier - }; - - QgsAbstractDatabaseProviderConnection( const QString &name ); %Docstring Creates a new connection with ``name`` by reading its configuration from the settings. @@ -404,7 +379,7 @@ Returns connection geometry column capabilities (Z, M, SinglePart, Curves) .. versionadded:: 3.16 %End - virtual SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities(); + virtual Qgis::SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities(); %Docstring Returns SQL layer definition capabilities (Filter, GeometryColumn, PrimaryKeys) @@ -703,7 +678,7 @@ Returns the provider key .. versionadded:: 3.16 %End - virtual QMap sqlDictionary(); + virtual QMap sqlDictionary(); %Docstring Returns a dictionary of SQL keywords supported by the provider. The default implementation returns an list of common reserved words under the @@ -719,7 +694,7 @@ Subclasses should add provider- and/or connection- specific words. void checkCapability( Capability capability ) const; %Docstring -Checks if ``capability`` is supported and throws and exception if it's not +Checks if ``capability`` is supported and throws and exception if it's not. :raises QgsProviderConnectionException: %End diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 3d1fcb27ea15..a82101074947 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -226,6 +226,31 @@ The development version UserCanceled, }; + enum class SqlLayerDefinitionCapability + { + Filter, + GeometryColumn, + PrimaryKeys, + SelectAtId + }; + + typedef QFlags SqlLayerDefinitionCapabilities; + + + enum class SqlKeywordCategory + { + Keyword, + Constant, + Function, + Geospatial, + Operator, + Math, + Aggregate, + String, + Identifier + }; + + enum class DriveType { Unknown, diff --git a/src/app/browser/qgsinbuiltdataitemproviders.cpp b/src/app/browser/qgsinbuiltdataitemproviders.cpp index 099951b13c84..420ce4ed6dea 100644 --- a/src/app/browser/qgsinbuiltdataitemproviders.cpp +++ b/src/app/browser/qgsinbuiltdataitemproviders.cpp @@ -1063,75 +1063,70 @@ void QgsDatabaseItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu * } // SQL dialog - if ( std::unique_ptr conn( item->databaseConnection() ); conn ) + if ( std::unique_ptr conn( item->databaseConnection() ); conn && conn->capabilities().testFlag( QgsAbstractDatabaseProviderConnection::Capability::ExecuteSql ) ) { + QAction *sqlAction = new QAction( QObject::tr( "Run SQL command…" ), menu ); - if ( conn->capabilities().testFlag( QgsAbstractDatabaseProviderConnection::Capability::ExecuteSql ) ) + QObject::connect( sqlAction, &QAction::triggered, item, [ item, context ] { - - QAction *sqlAction = new QAction( QObject::tr( "Run SQL command…" ), menu ); - - QObject::connect( sqlAction, &QAction::triggered, item, [ item, context ] + std::unique_ptr conn2( item->databaseConnection() ); + // This should never happen but let's play safe + if ( ! conn2 ) { - std::unique_ptr conn2( item->databaseConnection() ); - // This should never happen but let's play safe - if ( ! conn2 ) - { - QgsMessageLog::logMessage( tr( "Connection to the database (%1) was lost." ).arg( item->name() ) ); - return; - } + QgsMessageLog::logMessage( tr( "Connection to the database (%1) was lost." ).arg( item->name() ) ); + return; + } - // Create the SQL dialog: this might become an independent class dialog in the future, for now - // we are still prototyping the features that this dialog will have. + // Create the SQL dialog: this might become an independent class dialog in the future, for now + // we are still prototyping the features that this dialog will have. - QgsDialog dialog; - dialog.setObjectName( QStringLiteral( "SQLCommandsDialog" ) ); - dialog.setWindowTitle( tr( "%1 — Run SQL Commands" ).arg( item->name() ) ); + QgsDialog dialog; + dialog.setObjectName( QStringLiteral( "SQLCommandsDialog" ) ); + dialog.setWindowTitle( tr( "%1 — Run SQL Commands" ).arg( item->name() ) ); - // If this is a layer item (or below the hierarchy) we can pre-set the query to something - // meaningful - QString sql; + // If this is a layer item (or below the hierarchy) we can pre-set the query to something + // meaningful + QString sql; - if ( qobject_cast( item ) ) + if ( qobject_cast( item ) ) + { + if ( conn2->capabilities().testFlag( QgsAbstractDatabaseProviderConnection::Capability::Schemas ) ) { - if ( conn2->capabilities().testFlag( QgsAbstractDatabaseProviderConnection::Capability::Schemas ) ) - { - // Ok, this is gross: we lack a connection API for quoting properly... - sql = QStringLiteral( "SELECT * FROM %1.%2 LIMIT 10" ).arg( QgsSqliteUtils::quotedIdentifier( item->parent()->name() ), QgsSqliteUtils::quotedIdentifier( item->name() ) ); - } - else - { - // Ok, this is gross: we lack a connection API for quoting properly... - sql = QStringLiteral( "SELECT * FROM %1 LIMIT 10" ).arg( QgsSqliteUtils::quotedIdentifier( item->name() ) ); - } + // Ok, this is gross: we lack a connection API for quoting properly... + sql = QStringLiteral( "SELECT * FROM %1.%2 LIMIT 10" ).arg( QgsSqliteUtils::quotedIdentifier( item->parent()->name() ), QgsSqliteUtils::quotedIdentifier( item->name() ) ); + } + else + { + // Ok, this is gross: we lack a connection API for quoting properly... + sql = QStringLiteral( "SELECT * FROM %1 LIMIT 10" ).arg( QgsSqliteUtils::quotedIdentifier( item->name() ) ); } + } - QgsGui::enableAutoGeometryRestore( &dialog ); - QgsQueryResultWidget *widget { new QgsQueryResultWidget( &dialog, conn2.release() ) }; - widget->setQuery( sql ); - widget->layout()->setMargin( 0 ); - dialog.layout()->addWidget( widget ); + QgsGui::enableAutoGeometryRestore( &dialog ); + QgsQueryResultWidget *widget { new QgsQueryResultWidget( &dialog, conn2.release() ) }; + widget->setQuery( sql ); + widget->layout()->setMargin( 0 ); + dialog.layout()->addWidget( widget ); - connect( widget, &QgsQueryResultWidget::createSqlVectorLayer, widget, [ item, context ]( const QString &, const QString &, const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions & options ) + connect( widget, &QgsQueryResultWidget::createSqlVectorLayer, widget, [ item, context ]( const QString &, const QString &, const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions & options ) + { + std::unique_ptr conn3( item->databaseConnection() ); + try { - std::unique_ptr conn3( item->databaseConnection() ); - try - { - QgsMapLayer *sqlLayer { conn3->createSqlVectorLayer( options ) }; - QgsProject::instance()->addMapLayers( { sqlLayer } ); - } - catch ( QgsProviderConnectionException &ex ) - { - notify( QObject::tr( "New SQL Layer Creation Error" ), QObject::tr( "Error creating new SQL layer: %1" ).arg( ex.what() ), context, Qgis::MessageLevel::Critical ); - } + QgsMapLayer *sqlLayer { conn3->createSqlVectorLayer( options ) }; + QgsProject::instance()->addMapLayers( { sqlLayer } ); + } + catch ( QgsProviderConnectionException &ex ) + { + notify( QObject::tr( "New SQL Layer Creation Error" ), QObject::tr( "Error creating new SQL layer: %1" ).arg( ex.what() ), context, Qgis::MessageLevel::Critical ); + } - } ); - dialog.exec(); + } ); + dialog.exec(); - } ); - menu->addAction( sqlAction ); - } + } ); + menu->addAction( sqlAction ); } } } diff --git a/src/core/providers/ogr/qgsgeopackageproviderconnection.cpp b/src/core/providers/ogr/qgsgeopackageproviderconnection.cpp index 1cd79becc224..ae431215b3a8 100644 --- a/src/core/providers/ogr/qgsgeopackageproviderconnection.cpp +++ b/src/core/providers/ogr/qgsgeopackageproviderconnection.cpp @@ -381,9 +381,9 @@ void QgsGeoPackageProviderConnection::setDefaultCapabilities() }; mSqlLayerDefinitionCapabilities = { - SqlLayerDefinitionCapability::Filter, - SqlLayerDefinitionCapability::PrimaryKeys, - SqlLayerDefinitionCapability::GeometryColumn, + Qgis::SqlLayerDefinitionCapability::Filter, + Qgis::SqlLayerDefinitionCapability::PrimaryKeys, + Qgis::SqlLayerDefinitionCapability::GeometryColumn, }; } @@ -618,7 +618,7 @@ bool QgsGeoPackageProviderResultIterator::hasNextRowPrivate() const return ! mNextRow.isEmpty(); } -qlonglong QgsGeoPackageProviderResultIterator::rowCountPrivate() const +long long QgsGeoPackageProviderResultIterator::rowCountPrivate() const { return mRowCount; } @@ -704,7 +704,7 @@ QgsFields QgsGeoPackageProviderConnection::fields( const QString &schema, const return fieldList; } -QMap QgsGeoPackageProviderConnection::sqlDictionary() +QMap QgsGeoPackageProviderConnection::sqlDictionary() { /* * last_insert_rowid + list from: http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.0.html @@ -728,7 +728,7 @@ QMap Qgs return QgsAbstractDatabaseProviderConnection::sqlDictionary().unite( { { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Math, { + Qgis::SqlKeywordCategory::Math, { // SQL math functions QStringLiteral( "Abs( x [Double precision] )" ), QStringLiteral( "Acos( x [Double precision] )" ), @@ -758,7 +758,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Function, { + Qgis::SqlKeywordCategory::Function, { // Specific QStringLiteral( "last_insert_rowid" ), @@ -846,7 +846,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Geospatial, { + Qgis::SqlKeywordCategory::Geospatial, { // SQL functions reporting GEOS / LWGEOM errors and warnings QStringLiteral( "GEOS_GetLastWarningMsg( [void] )" ), QStringLiteral( "GEOS_GetLastErrorMsg( [void] )" ), diff --git a/src/core/providers/ogr/qgsgeopackageproviderconnection.h b/src/core/providers/ogr/qgsgeopackageproviderconnection.h index 937f597d42a7..03c394929fb2 100644 --- a/src/core/providers/ogr/qgsgeopackageproviderconnection.h +++ b/src/core/providers/ogr/qgsgeopackageproviderconnection.h @@ -44,11 +44,11 @@ struct QgsGeoPackageProviderResultIterator: public QgsAbstractDatabaseProviderCo QVariantList mNextRow; QString mGeometryColumnName; QString mPrimaryKeyColumnName; - qlonglong mRowCount = -1; + long long mRowCount = -1; QVariantList nextRowPrivate() override; bool hasNextRowPrivate() const override; - qlonglong rowCountPrivate() const override; + long long rowCountPrivate() const override; QVariantList nextRowInternal(); }; @@ -81,7 +81,7 @@ class QgsGeoPackageProviderConnection : public QgsAbstractDatabaseProviderConnec QIcon icon() const override; QList nativeTypes() const override; QgsFields fields( const QString &schema, const QString &table ) const override; - QMap sqlDictionary() override; + QMap sqlDictionary() override; private: diff --git a/src/core/providers/qgsabstractdatabaseproviderconnection.cpp b/src/core/providers/qgsabstractdatabaseproviderconnection.cpp index 7964b14cba79..899ff779186e 100644 --- a/src/core/providers/qgsabstractdatabaseproviderconnection.cpp +++ b/src/core/providers/qgsabstractdatabaseproviderconnection.cpp @@ -43,7 +43,7 @@ QgsAbstractDatabaseProviderConnection::GeometryColumnCapabilities QgsAbstractDat return mGeometryColumnCapabilities; } -QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapabilities QgsAbstractDatabaseProviderConnection::sqlLayerDefinitionCapabilities() +Qgis::SqlLayerDefinitionCapabilities QgsAbstractDatabaseProviderConnection::sqlLayerDefinitionCapabilities() { return mSqlLayerDefinitionCapabilities; } @@ -74,13 +74,13 @@ QString QgsAbstractDatabaseProviderConnection::providerKey() const ///@endcond -QMap QgsAbstractDatabaseProviderConnection::sqlDictionary() +QMap QgsAbstractDatabaseProviderConnection::sqlDictionary() { return { // Common constants { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Constant, { + Qgis::SqlKeywordCategory::Constant, { QStringLiteral( "NULL" ), QStringLiteral( "FALSE" ), QStringLiteral( "TRUE" ), @@ -89,7 +89,7 @@ QMap Qgs // Common SQL reserved words // From: GET https://en.wikipedia.org/wiki/SQL_reserved_words| grep 'style="background: #ececec; color: black; font-weight: bold;'| sed -e 's/.*>//'|sort { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Keyword, + Qgis::SqlKeywordCategory::Keyword, { QStringLiteral( "ABORT " ), QStringLiteral( "ABORTSESSION" ), @@ -1429,7 +1429,7 @@ QList QgsAbstractDatabaseProviderConnection::QueryResult::nextRow() co } -qlonglong QgsAbstractDatabaseProviderConnection::QueryResult::fetchedRowCount() const +long long QgsAbstractDatabaseProviderConnection::QueryResult::fetchedRowCount() const { if ( ! mResultIterator ) { @@ -1438,11 +1438,11 @@ qlonglong QgsAbstractDatabaseProviderConnection::QueryResult::fetchedRowCount() return mResultIterator->fetchedRowCount(); } -qlonglong QgsAbstractDatabaseProviderConnection::QueryResult::rowCount() const +long long QgsAbstractDatabaseProviderConnection::QueryResult::rowCount() const { if ( ! mResultIterator ) { - return -1; + return static_cast( Qgis::FeatureCountState::UnknownCount ); } return mResultIterator->rowCount(); } @@ -1485,13 +1485,13 @@ bool QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::ha return hasNextRowPrivate(); } -qlonglong QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::fetchedRowCount() +long long QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::fetchedRowCount() { QMutexLocker lock( &mMutex ); return mFetchedRowCount; } -qlonglong QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::rowCount() +long long QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::rowCount() { QMutexLocker lock( &mMutex ); return rowCountPrivate(); diff --git a/src/core/providers/qgsabstractdatabaseproviderconnection.h b/src/core/providers/qgsabstractdatabaseproviderconnection.h index f4064ff6d223..3d32bdec8b88 100644 --- a/src/core/providers/qgsabstractdatabaseproviderconnection.h +++ b/src/core/providers/qgsabstractdatabaseproviderconnection.h @@ -117,14 +117,14 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv * * \see rowCount() */ - qlonglong fetchedRowCount( ) const; + long long fetchedRowCount( ) const; /** * Returns the number of rows returned by a SELECT query or -1 if unknown * * \see fetchedRowCount() */ - qlonglong rowCount( ) const; + long long rowCount( ) const; #ifdef SIP_RUN @@ -168,10 +168,10 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv bool hasNextRow() const; //! Returns the number of actually fetched rows - qlonglong fetchedRowCount(); + long long fetchedRowCount(); - //! Returns the total number of rows returned by a SELECT query or -1 if this is not known. - qlonglong rowCount(); + //! Returns the total number of rows returned by a SELECT query or Qgis::FeatureCountState::UnknownCount ( -1 ) if this is not supported by the provider. + long long rowCount(); virtual ~QueryResultIterator() = default; @@ -179,7 +179,7 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv virtual QVariantList nextRowPrivate() = 0; virtual bool hasNextRowPrivate() const = 0; - virtual qlonglong rowCountPrivate() const = 0; + virtual long long rowCountPrivate() const = 0; mutable qlonglong mFetchedRowCount = 0; mutable QMutex mMutex; @@ -221,12 +221,12 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv */ struct CORE_EXPORT 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; //! If SelectAtId is disabled (default is false), not all data providers support this feature: check support with SqlLayerDefinitionCapability::SelectAtId capability + 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; //!< If SelectAtId is disabled (default is false), not all data providers support this feature: check support with SqlLayerDefinitionCapability::SelectAtId capability }; /** @@ -484,52 +484,16 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv */ enum GeometryColumnCapability { - Z = 1 << 1, //! Supports Z dimension - M = 1 << 2, //! Supports M dimension - SinglePart = 1 << 3, //! Multi and single part types are distinct types - Curves = 1 << 4 //! Supports curves + Z = 1 << 1, //!< Supports Z dimension + M = 1 << 2, //!< Supports M dimension + SinglePart = 1 << 3, //!< Multi and single part types are distinct types + Curves = 1 << 4 //!< Supports curves }; Q_ENUM( GeometryColumnCapability ) Q_DECLARE_FLAGS( GeometryColumnCapabilities, GeometryColumnCapability ) Q_FLAG( GeometryColumnCapabilities ) - /** - * \brief The SqlLayerDefinitionCapability enum lists the arguments supported by the provider when creating SQL query layers. - * \since QGIS 3.22 - */ - enum SqlLayerDefinitionCapability - { - Filter = 1 << 1, //! SQL layer definition supports filter - GeometryColumn = 1 << 2, //! SQL layer definition supports geometry column - PrimaryKeys = 1 << 3, //! SQL layer definition supports primary keys - SelectAtId = 1 << 4 //! SQL layer definition supports disabling select at id - }; - - Q_ENUM( SqlLayerDefinitionCapability ) - Q_DECLARE_FLAGS( SqlLayerDefinitionCapabilities, SqlLayerDefinitionCapability ) - Q_FLAG( SqlLayerDefinitionCapabilities ) - - /** - * \brief The SqlKeywordCategory enum represents the categories of the SQL keywords used by the SQL query editor. - * \note The category has currently no usage, but it was planned for future uses. - * \since QGIS 3.22 - */ - enum SqlKeywordCategory - { - Keyword, //! SQL keyword - Constant, //! SQL constant - Function, //! SQL generic function - Geospatial, //! SQL spatial function - Operator, //! SQL operator - Math, //! SQL math function - Aggregate, //! SQL aggregate function - String, //! SQL string function - Identifier //! SQL identifier - }; - - Q_ENUM( SqlKeywordCategory ) - /** * Creates a new connection with \a name by reading its configuration from the settings. * If a connection with this name cannot be found, an empty connection will be returned. @@ -561,7 +525,7 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv * Returns SQL layer definition capabilities (Filter, GeometryColumn, PrimaryKeys) * \since QGIS 3.22 */ - virtual SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities(); + virtual Qgis::SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities(); // Operations interface @@ -803,14 +767,14 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv * * \since QGIS 3.22 */ - virtual QMap sqlDictionary(); + virtual QMap sqlDictionary(); protected: ///@cond PRIVATE /** - * Checks if \a capability is supported and throws and exception if it's not + * Checks if \a capability is supported and throws and exception if it's not. * \throws QgsProviderConnectionException */ void checkCapability( Capability capability ) const; @@ -818,7 +782,7 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv Capabilities mCapabilities = Capabilities() SIP_SKIP; GeometryColumnCapabilities mGeometryColumnCapabilities = GeometryColumnCapabilities() SIP_SKIP; - SqlLayerDefinitionCapabilities mSqlLayerDefinitionCapabilities = SqlLayerDefinitionCapabilities() SIP_SKIP; + Qgis::SqlLayerDefinitionCapabilities mSqlLayerDefinitionCapabilities = Qgis::SqlLayerDefinitionCapabilities() SIP_SKIP; QString mProviderKey; }; diff --git a/src/core/qgis.h b/src/core/qgis.h index 71c886d09ebd..0dc301f448cd 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -330,6 +330,41 @@ class CORE_EXPORT Qgis }; Q_ENUM( VectorExportResult ) + /** + * SqlLayerDefinitionCapability enum lists the arguments supported by the provider when creating SQL query layers. + * \since QGIS 3.22 + */ + enum class SqlLayerDefinitionCapability : int + { + Filter = 1 << 1, //!< SQL layer definition supports filter + GeometryColumn = 1 << 2, //!< SQL layer definition supports geometry column + PrimaryKeys = 1 << 3, //!< SQL layer definition supports primary keys + SelectAtId = 1 << 4 //!< SQL layer definition supports disabling select at id + }; + + Q_ENUM( SqlLayerDefinitionCapability ) + Q_DECLARE_FLAGS( SqlLayerDefinitionCapabilities, SqlLayerDefinitionCapability ) + + /** + * SqlKeywordCategory enum represents the categories of the SQL keywords used by the SQL query editor. + * \note The category has currently no usage, but it was planned for future uses. + * \since QGIS 3.22 + */ + enum class SqlKeywordCategory : int + { + Keyword, //!< SQL keyword + Constant, //!< SQL constant + Function, //!< SQL generic function + Geospatial, //!< SQL spatial function + Operator, //!< SQL operator + Math, //!< SQL math function + Aggregate, //!< SQL aggregate function + String, //!< SQL string function + Identifier //!< SQL identifier + }; + Q_ENUM( SqlKeywordCategory ) + + /** * Drive types * \since QGIS 3.20 diff --git a/src/core/qgsqueryresultmodel.cpp b/src/core/qgsqueryresultmodel.cpp index 65f54d9de2ab..9669a894547f 100644 --- a/src/core/qgsqueryresultmodel.cpp +++ b/src/core/qgsqueryresultmodel.cpp @@ -141,9 +141,9 @@ QVariant QgsQueryResultModel::headerData( int section, Qt::Orientation orientati const int QgsQueryResultFetcher::ROWS_BATCH_COUNT = 200; -void QgsQueryResultFetcher::fetchRows( qlonglong maxRows ) +void QgsQueryResultFetcher::fetchRows( long long maxRows ) { - qlonglong rowCount { 0 }; + long long rowCount { 0 }; QList> newRows; newRows.reserve( ROWS_BATCH_COUNT ); while ( mStopFetching == 0 && mQueryResult->hasNextRow() && ( maxRows < 0 || rowCount < maxRows ) ) diff --git a/src/core/qgsqueryresultmodel.h b/src/core/qgsqueryresultmodel.h index f236b2a6dc2f..6cc8485bbbb8 100644 --- a/src/core/qgsqueryresultmodel.h +++ b/src/core/qgsqueryresultmodel.h @@ -44,7 +44,7 @@ class QgsQueryResultFetcher: public QObject {} //! Start fetching at most \a maxRows, default value of -1 fetches all rows. - void fetchRows( qlonglong maxRows = -1 ); + void fetchRows( long long maxRows = -1 ); //! Stop fetching void stopFetching(); diff --git a/src/gui/qgsqueryresultwidget.cpp b/src/gui/qgsqueryresultwidget.cpp index ce55a6453d6d..7ccf1556a359 100644 --- a/src/gui/qgsqueryresultwidget.cpp +++ b/src/gui/qgsqueryresultwidget.cpp @@ -15,6 +15,7 @@ ***************************************************************************/ #include "qgsqueryresultwidget.h" #include "qgsabstractdatabaseproviderconnection.h" +#include "qgsexpressionutils.h" #include "qgscodeeditorsql.h" #include "qgsmessagelog.h" #include "qgsquerybuilder.h" @@ -45,7 +46,7 @@ QgsQueryResultWidget::QgsQueryResultWidget( QWidget *parent, QgsAbstractDatabase } } ); - connect( mSqlEditor, &QgsCodeEditorSQL::textChanged, this, [ = ] { updateButtons(); } ); + connect( mSqlEditor, &QgsCodeEditorSQL::textChanged, this, &QgsQueryResultWidget::updateButtons ); connect( mFilterToolButton, &QToolButton::pressed, this, [ = ] { if ( mConnection ) @@ -82,20 +83,20 @@ QgsQueryResultWidget::QgsQueryResultWidget( QWidget *parent, QgsAbstractDatabase if ( ! collapsed ) { // Configure the load layer interface - const bool showPkConfig { connection &&connection->sqlLayerDefinitionCapabilities().testFlag( QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapability::PrimaryKeys )}; + const bool showPkConfig { connection &&connection->sqlLayerDefinitionCapabilities().testFlag( Qgis::SqlLayerDefinitionCapability::PrimaryKeys )}; mPkColumnsCheckBox->setVisible( showPkConfig ); mPkColumnsComboBox->setVisible( showPkConfig ); - const bool showGeometryColumnConfig {connection &&connection->sqlLayerDefinitionCapabilities().testFlag( QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapability::GeometryColumn )}; + const bool showGeometryColumnConfig {connection &&connection->sqlLayerDefinitionCapabilities().testFlag( Qgis::SqlLayerDefinitionCapability::GeometryColumn )}; mGeometryColumnCheckBox->setVisible( showGeometryColumnConfig ); mGeometryColumnComboBox->setVisible( showGeometryColumnConfig ); - const bool showFilterConfig { connection &&connection->sqlLayerDefinitionCapabilities().testFlag( QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapability::Filter ) }; + const bool showFilterConfig { connection &&connection->sqlLayerDefinitionCapabilities().testFlag( Qgis::SqlLayerDefinitionCapability::Filter ) }; mFilterLabel->setVisible( showFilterConfig ); mFilterToolButton->setVisible( showFilterConfig ); mFilterLineEdit->setVisible( showFilterConfig ); - const bool showDisableSelectAtId{ connection &&connection->sqlLayerDefinitionCapabilities().testFlag( QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapability::SelectAtId ) }; + const bool showDisableSelectAtId{ connection &&connection->sqlLayerDefinitionCapabilities().testFlag( Qgis::SqlLayerDefinitionCapability::SelectAtId ) }; mAvoidSelectingAsFeatureIdCheckBox->setVisible( showDisableSelectAtId ); } @@ -120,7 +121,7 @@ void QgsQueryResultWidget::executeQuery() if ( mConnection ) { - const auto sql = mSqlEditor->text( ); + const QString sql { mSqlEditor->text( ) }; mWasCanceled = false; mFeedback = std::make_unique(); @@ -158,7 +159,7 @@ void QgsQueryResultWidget::executeQuery() } else { - showError( tr( "Connection error" ), tr( "Cannot execute query: connection to the database not set." ) ); + showError( tr( "Connection error" ), tr( "Cannot execute query: connection to the database is not available." ) ); } } @@ -186,8 +187,8 @@ void QgsQueryResultWidget::updateSqlLayerColumns( ) const bool hasPkInformation { ! mSqlVectorLayerOptions.primaryKeyColumns.isEmpty() }; const bool hasGeomColInformation { ! mSqlVectorLayerOptions.geometryColumn.isEmpty() }; static const QStringList geomColCandidates { QStringLiteral( "geom" ), QStringLiteral( "geometry" ), QStringLiteral( "the_geom" ) }; - const auto constCols { mModel->columns() }; - for ( const auto &c : constCols ) + const QStringList constCols { mModel->columns() }; + for ( const QString &c : constCols ) { const bool pkCheckedState = hasPkInformation ? mSqlVectorLayerOptions.primaryKeyColumns.contains( c ) : c.contains( QStringLiteral( "id" ), Qt::CaseSensitivity::CaseInsensitive ); // Only check first match @@ -241,7 +242,7 @@ void QgsQueryResultWidget::startFetching() } else { - if ( mQueryResultWatcher.result().rowCount() > 0 ) + if ( mQueryResultWatcher.result().rowCount() != static_cast( Qgis::FeatureCountState::UnknownCount ) ) { mStatusLabel->setText( QStringLiteral( "Query executed successfully (%1 rows)" ).arg( QLocale().toString( mQueryResultWatcher.result().rowCount() ) ) ); } @@ -278,9 +279,9 @@ void QgsQueryResultWidget::startFetching() } } mStatusLabel->setText( tr( "Fetched rows: %1/%2 %3" ) - .arg( QLocale().toString( mModel->rowCount( mModel->index( -1, -1 ) ) ) ) - .arg( mActualRowCount != -1 ? QLocale().toString( mActualRowCount ) : tr( "unknown" ) ) - .arg( mWasCanceled ? tr( "(stopped)" ) : QString() ) ); + .arg( QLocale().toString( mModel->rowCount( mModel->index( -1, -1 ) ) ), + mActualRowCount != -1 ? QLocale().toString( mActualRowCount ) : tr( "unknown" ), + mWasCanceled ? tr( "(stopped)" ) : QString() ) ); if ( mActualRowCount != -1 ) { mProgressBar->setValue( mModel->rowCount( mModel->index( -1, -1 ) ) ); @@ -361,7 +362,7 @@ void QgsQueryResultWidget::setConnection( QgsAbstractDatabaseProviderConnection { // Add provider specific APIs - const auto keywordsDict { connection->sqlDictionary() }; + const QMap keywordsDict { connection->sqlDictionary() }; QStringList keywords; for ( auto it = keywordsDict.constBegin(); it != keywordsDict.constEnd(); it++ ) { @@ -421,12 +422,17 @@ void QgsConnectionsApiFetcher::fetchTokens() for ( const auto &schema : std::as_const( schemas ) ) { - if ( mStopFetching ) { return; } + + if ( mStopFetching ) + { + return; + } + QStringList tableNames; try { - const auto tables = mConnection->tables( schema ); - for ( const auto &table : std::as_const( tables ) ) + const QList tables = mConnection->tables( schema ); + for ( const QgsAbstractDatabaseProviderConnection::TableProperty &table : std::as_const( tables ) ) { if ( mStopFetching ) { return; } tableNames.push_back( table.tableName() ); @@ -441,7 +447,12 @@ void QgsConnectionsApiFetcher::fetchTokens() // Get fields for ( const auto &table : std::as_const( tableNames ) ) { - if ( mStopFetching ) { return; } + + if ( mStopFetching ) + { + return; + } + QStringList fieldNames; try { @@ -478,9 +489,7 @@ QgsQueryResultItemDelegate::QgsQueryResultItemDelegate( QObject *parent ) QString QgsQueryResultItemDelegate::displayText( const QVariant &value, const QLocale &locale ) const { Q_UNUSED( locale ) - // TODO: use https://github.com/qgis/QGIS/pull/43705/files#diff-03e9f0d1977751f918b16f080b6595ff4f2183944e8aa6ac602d345325d8bcd5R440 - // when merged - QString result { QStyledItemDelegate::displayText( value, QLocale() ) }; + QString result { QgsExpressionUtils::toLocalizedString( value ) }; // Show no more than 255 characters if ( result.length() > 255 ) { diff --git a/src/gui/qgsqueryresultwidget.h b/src/gui/qgsqueryresultwidget.h index d520830eb86a..7f07c53106a2 100644 --- a/src/gui/qgsqueryresultwidget.h +++ b/src/gui/qgsqueryresultwidget.h @@ -78,7 +78,7 @@ class GUI_EXPORT QgsConnectionsApiFetcher: public QObject private: - const QgsAbstractDatabaseProviderConnection *mConnection; + const QgsAbstractDatabaseProviderConnection *mConnection = nullptr; QAtomicInt mStopFetching = 0; }; @@ -161,6 +161,11 @@ class GUI_EXPORT QgsQueryResultWidget: public QWidget, private Ui::QgsQueryResul void syncSqlOptions(); + /** + * Updates buttons status. + */ + void updateButtons(); + private: std::unique_ptr mConnection; @@ -175,10 +180,6 @@ class GUI_EXPORT QgsQueryResultWidget: public QWidget, private Ui::QgsQueryResul QString mSqlErrorMessage; qlonglong mActualRowCount = -1; - /** - * Updates buttons status. - */ - void updateButtons(); /** * Updates SQL layer columns. diff --git a/src/providers/hana/qgshanaproviderconnection.cpp b/src/providers/hana/qgshanaproviderconnection.cpp index a2b7a7468b9e..c8319ac5989e 100644 --- a/src/providers/hana/qgshanaproviderconnection.cpp +++ b/src/providers/hana/qgshanaproviderconnection.cpp @@ -52,10 +52,10 @@ bool QgsHanaProviderResultIterator::hasNextRowPrivate() const return mNextRow; } -qlonglong QgsHanaProviderResultIterator::rowCountPrivate() const +long long QgsHanaProviderResultIterator::rowCountPrivate() const { // TODO: hana team, this is for you. - return -1; + return static_cast( Qgis::FeatureCountState::UnknownCount ); } QgsHanaProviderConnection::QgsHanaProviderConnection( const QString &name ) diff --git a/src/providers/hana/qgshanaproviderconnection.h b/src/providers/hana/qgshanaproviderconnection.h index 6af659b8e666..24f535abfe68 100644 --- a/src/providers/hana/qgshanaproviderconnection.h +++ b/src/providers/hana/qgshanaproviderconnection.h @@ -27,7 +27,7 @@ struct QgsHanaEmptyProviderResultIterator: public QgsAbstractDatabaseProviderCon private: QVariantList nextRowPrivate() override; bool hasNextRowPrivate() const override; - qlonglong rowCountPrivate() const override { return 0; }; + long long rowCountPrivate() const override { return 0; }; }; struct QgsHanaProviderResultIterator: public QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator @@ -43,7 +43,7 @@ struct QgsHanaProviderResultIterator: public QgsAbstractDatabaseProviderConnecti private: QVariantList nextRowPrivate() override; bool hasNextRowPrivate() const override; - qlonglong rowCountPrivate() const override; + long long rowCountPrivate() const override; }; class QgsHanaConnectionRef; diff --git a/src/providers/mssql/qgsmssqlproviderconnection.cpp b/src/providers/mssql/qgsmssqlproviderconnection.cpp index 537512b0267d..c77bd469a7f8 100644 --- a/src/providers/mssql/qgsmssqlproviderconnection.cpp +++ b/src/providers/mssql/qgsmssqlproviderconnection.cpp @@ -101,10 +101,10 @@ void QgsMssqlProviderConnection::setDefaultCapabilities() }; mSqlLayerDefinitionCapabilities = { - SqlLayerDefinitionCapability::Filter, - SqlLayerDefinitionCapability::PrimaryKeys, - SqlLayerDefinitionCapability::GeometryColumn, - SqlLayerDefinitionCapability::SelectAtId, + Qgis::SqlLayerDefinitionCapability::Filter, + Qgis::SqlLayerDefinitionCapability::PrimaryKeys, + Qgis::SqlLayerDefinitionCapability::GeometryColumn, + Qgis::SqlLayerDefinitionCapability::SelectAtId, }; } @@ -331,7 +331,7 @@ QVariantList QgssMssqlProviderResultIterator::nextRowInternal() return row; } -qlonglong QgssMssqlProviderResultIterator::rowCountPrivate() const +long long QgssMssqlProviderResultIterator::rowCountPrivate() const { return mQuery.size(); } diff --git a/src/providers/mssql/qgsmssqlproviderconnection.h b/src/providers/mssql/qgsmssqlproviderconnection.h index f6179a167805..625f365234ce 100644 --- a/src/providers/mssql/qgsmssqlproviderconnection.h +++ b/src/providers/mssql/qgsmssqlproviderconnection.h @@ -41,7 +41,7 @@ struct QgssMssqlProviderResultIterator: public QgsAbstractDatabaseProviderConnec // QueryResultIterator interface - qlonglong rowCountPrivate() const override; + long long rowCountPrivate() const override; }; class QgsMssqlProviderConnection : public QgsAbstractDatabaseProviderConnection diff --git a/src/providers/oracle/qgsoracleproviderconnection.cpp b/src/providers/oracle/qgsoracleproviderconnection.cpp index fce3e1dc92f7..45940d48557c 100644 --- a/src/providers/oracle/qgsoracleproviderconnection.cpp +++ b/src/providers/oracle/qgsoracleproviderconnection.cpp @@ -124,9 +124,9 @@ void QgsOracleProviderConnection::setDefaultCapabilities() }; mSqlLayerDefinitionCapabilities = { - SqlLayerDefinitionCapability::Filter, - SqlLayerDefinitionCapability::GeometryColumn, - SqlLayerDefinitionCapability::PrimaryKeys, + Qgis::SqlLayerDefinitionCapability::Filter, + Qgis::SqlLayerDefinitionCapability::GeometryColumn, + Qgis::SqlLayerDefinitionCapability::PrimaryKeys, }; } @@ -178,22 +178,22 @@ QgsVectorLayer *QgsOracleProviderConnection::createSqlVectorLayer( const QgsAbst // Try to guess the geometry and srid if ( ! vl->isValid() ) { - const auto limit { QgsDataSourceUri( uri() ).useEstimatedMetadata() ? QStringLiteral( "AND ROWNUM < 100" ) : QString() }; - const auto sql { QStringLiteral( R"( + const QString limit { QgsDataSourceUri( uri() ).useEstimatedMetadata() ? QStringLiteral( "AND ROWNUM < 100" ) : QString() }; + const QString sql { QStringLiteral( R"( SELECT DISTINCT a.%1.SDO_GTYPE As gtype, a.%1.SDO_SRID FROM (%2) a WHERE a.%1 IS NOT NULL %3 ORDER BY a.%1.SDO_GTYPE )" ).arg( options.geometryColumn, options.sql, limit ) }; - const auto candidates { executeSql( sql ) }; - for ( const auto &row : std::as_const( candidates ) ) + const QList> candidates { executeSql( sql ) }; + for ( const QList &row : std::as_const( candidates ) ) { bool ok; - const auto type { row[ 0 ].toInt( &ok ) }; + const int type { row[ 0 ].toInt( &ok ) }; if ( ok ) { - const auto srid { row[ 0 ].toInt( &ok ) }; + const int srid { row[ 0 ].toInt( &ok ) }; if ( ok ) { @@ -322,12 +322,12 @@ QList QgsOracleProviderConnection::nativeType return types; } -QMap QgsOracleProviderConnection::sqlDictionary() +QMap QgsOracleProviderConnection::sqlDictionary() { return { { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Keyword, + Qgis::SqlKeywordCategory::Keyword, { // From: http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm QStringLiteral( "ACCESS" ), @@ -875,7 +875,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Function, + Qgis::SqlKeywordCategory::Function, { // From: https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm QStringLiteral( "CAST" ), @@ -895,7 +895,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Math, + Qgis::SqlKeywordCategory::Math, { QStringLiteral( "ABS" ), QStringLiteral( "ACOS" ), @@ -929,7 +929,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::String, + Qgis::SqlKeywordCategory::String, { QStringLiteral( "CHR" ), QStringLiteral( "CONCAT" ), @@ -962,7 +962,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Aggregate, + Qgis::SqlKeywordCategory::Aggregate, { QStringLiteral( "AVG" ), QStringLiteral( "COLLECT" ), @@ -1012,7 +1012,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Geospatial, + Qgis::SqlKeywordCategory::Geospatial, { // From http://docs.oracle.com/cd/B19306_01/appdev.102/b14255/toc.htm // Spatial operators @@ -1286,7 +1286,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Operator, + Qgis::SqlKeywordCategory::Operator, { QStringLiteral( "AND" ), QStringLiteral( "OR" ), @@ -1325,7 +1325,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Constant, + Qgis::SqlKeywordCategory::Constant, { QStringLiteral( "NULL" ), QStringLiteral( "FALSE" ), @@ -1407,7 +1407,7 @@ QVariantList QgsOracleProviderResultIterator::nextRowInternal() return row; } -qlonglong QgsOracleProviderResultIterator::rowCountPrivate() const +long long QgsOracleProviderResultIterator::rowCountPrivate() const { return mQuery.size(); } diff --git a/src/providers/oracle/qgsoracleproviderconnection.h b/src/providers/oracle/qgsoracleproviderconnection.h index cc5e032c5112..3749375cd501 100644 --- a/src/providers/oracle/qgsoracleproviderconnection.h +++ b/src/providers/oracle/qgsoracleproviderconnection.h @@ -37,7 +37,7 @@ struct QgsOracleProviderResultIterator: public QgsAbstractDatabaseProviderConnec QVariantList mNextRow; QVariantList nextRowInternal(); - qlonglong rowCountPrivate() const override; + long long rowCountPrivate() const override; }; class QgsOracleProviderConnection : public QgsAbstractDatabaseProviderConnection @@ -72,7 +72,7 @@ class QgsOracleProviderConnection : public QgsAbstractDatabaseProviderConnection void remove( const QString &name ) const override; QIcon icon() const override; QList nativeTypes() const override; - QMap sqlDictionary() override; + QMap sqlDictionary() override; QgsVectorLayer *createSqlVectorLayer( const SqlVectorLayerOptions &options ) const override; private: diff --git a/src/providers/postgres/qgspostgresproviderconnection.cpp b/src/providers/postgres/qgspostgresproviderconnection.cpp index 5bd55786ecd2..4f5d474529db 100644 --- a/src/providers/postgres/qgspostgresproviderconnection.cpp +++ b/src/providers/postgres/qgspostgresproviderconnection.cpp @@ -85,10 +85,10 @@ void QgsPostgresProviderConnection::setDefaultCapabilities() }; mSqlLayerDefinitionCapabilities = { - SqlLayerDefinitionCapability::Filter, - SqlLayerDefinitionCapability::PrimaryKeys, - SqlLayerDefinitionCapability::GeometryColumn, - SqlLayerDefinitionCapability::SelectAtId, + Qgis::SqlLayerDefinitionCapability::Filter, + Qgis::SqlLayerDefinitionCapability::PrimaryKeys, + Qgis::SqlLayerDefinitionCapability::GeometryColumn, + Qgis::SqlLayerDefinitionCapability::SelectAtId, }; } @@ -427,9 +427,9 @@ bool QgsPostgresProviderResultIterator::hasNextRowPrivate() const return result && mRowIndex < result->PQntuples(); } -qlonglong QgsPostgresProviderResultIterator::rowCountPrivate() const +long long QgsPostgresProviderResultIterator::rowCountPrivate() const { - return result ? result->PQntuples() : -1; + return result ? result->PQntuples() : static_cast< long long >( Qgis::FeatureCountState::UnknownCount ); } @@ -797,15 +797,17 @@ QgsVectorLayer *QgsPostgresProviderConnection::createSqlVectorLayer( const SqlVe tUri.setGeometryColumn( options.geometryColumn ); } - return new QgsVectorLayer{ tUri.uri(), options.layerName.isEmpty() ? QStringLiteral( "QueryLayer" ) : options.layerName, providerKey() }; + QgsVectorLayer::LayerOptions vectorLayerOptions { false, true }; + vectorLayerOptions.skipCrsValidation = true; + return new QgsVectorLayer{ tUri.uri(), options.layerName.isEmpty() ? QStringLiteral( "QueryLayer" ) : options.layerName, providerKey(), vectorLayerOptions }; } -QMap QgsPostgresProviderConnection::sqlDictionary() +QMap QgsPostgresProviderConnection::sqlDictionary() { return QgsAbstractDatabaseProviderConnection::sqlDictionary().unite( { { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Keyword, + Qgis::SqlKeywordCategory::Keyword, { QStringLiteral( "absolute" ), QStringLiteral( "action" ), @@ -1224,7 +1226,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Aggregate, + Qgis::SqlKeywordCategory::Aggregate, { QStringLiteral( "Max" ), QStringLiteral( "Min" ), @@ -1240,7 +1242,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Math, + Qgis::SqlKeywordCategory::Math, { QStringLiteral( "Abs" ), QStringLiteral( "ACos" ), @@ -1269,7 +1271,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Geospatial, + Qgis::SqlKeywordCategory::Geospatial, { // List from: // import requests, re, html; diff --git a/src/providers/postgres/qgspostgresproviderconnection.h b/src/providers/postgres/qgspostgresproviderconnection.h index 45f51d34c495..722a56dd3d53 100644 --- a/src/providers/postgres/qgspostgresproviderconnection.h +++ b/src/providers/postgres/qgspostgresproviderconnection.h @@ -31,10 +31,10 @@ struct QgsPostgresProviderResultIterator: public QgsAbstractDatabaseProviderConn QVariantList nextRowPrivate() override; bool hasNextRowPrivate() const override; - qlonglong rowCountPrivate() const override; + long long rowCountPrivate() const override; bool mResolveTypes = true; - qlonglong mRowIndex = 0; + long long mRowIndex = 0; }; class QgsPostgresProviderConnection : public QgsAbstractDatabaseProviderConnection @@ -77,7 +77,7 @@ class QgsPostgresProviderConnection : public QgsAbstractDatabaseProviderConnecti QIcon icon() const override; QList nativeTypes() const override; QgsVectorLayer *createSqlVectorLayer( const SqlVectorLayerOptions &options ) const override; - QMap sqlDictionary() override; + QMap sqlDictionary() override; private: diff --git a/src/providers/spatialite/qgsspatialiteproviderconnection.cpp b/src/providers/spatialite/qgsspatialiteproviderconnection.cpp index 6a9616b01304..1eb90ad86433 100644 --- a/src/providers/spatialite/qgsspatialiteproviderconnection.cpp +++ b/src/providers/spatialite/qgsspatialiteproviderconnection.cpp @@ -319,8 +319,8 @@ QList QgsSpatiaLiteProviderConne // Need to store it here because provider (and underlying gaia library) returns views as spatial table if they have geometries QStringList viewNames; - const auto viewRows { executeSqlPrivate( QStringLiteral( "SELECT name FROM sqlite_master WHERE type = 'view'" ) ).rows() }; - for ( const auto &tn : std::as_const( viewRows ) ) + const QList> viewRows { executeSqlPrivate( QStringLiteral( "SELECT name FROM sqlite_master WHERE type = 'view'" ) ).rows() }; + for ( const QList &tn : std::as_const( viewRows ) ) { viewNames.push_back( tn.first().toString() ); } @@ -328,14 +328,14 @@ QList QgsSpatiaLiteProviderConne // Another weirdness: table names are converted to lowercase when out of spatialite gaia functions, let's get them back to their real case here, // may need LAUNDER on open, but let's try to make it consistent with how GPKG works. QgsStringMap tableNotLowercaseNames; - const auto lowerTables { executeSqlPrivate( QStringLiteral( "SELECT name FROM sqlite_master WHERE LOWER(name) != name" ) ).rows() }; - for ( const auto &tn : std::as_const( lowerTables ) ) + const QList> lowerTables { executeSqlPrivate( QStringLiteral( "SELECT name FROM sqlite_master WHERE LOWER(name) != name" ) ).rows() }; + for ( const QList &tn : std::as_const( lowerTables ) ) { const QString tName { tn.first().toString() }; tableNotLowercaseNames.insert( tName.toLower(), tName ); } - const auto constTables = connection.tables(); + const QList constTables = connection.tables(); for ( const QgsSpatiaLiteConnection::TableEntry &entry : constTables ) { QString tableName { tableNotLowercaseNames.value( entry.tableName, entry.tableName ) }; @@ -365,9 +365,9 @@ QList QgsSpatiaLiteProviderConne property.setFlag( QgsSpatiaLiteProviderConnection::TableFlag::View ); } - const auto constPkIdxs { vl->dataProvider()->pkAttributeIndexes() }; + const QgsAttributeList constPkIdxs { vl->dataProvider()->pkAttributeIndexes() }; QStringList pkNames; - for ( const auto &pkIdx : std::as_const( constPkIdxs ) ) + for ( const int &pkIdx : std::as_const( constPkIdxs ) ) { // Better safe than sorry if ( pkIdx < vl->fields().count() ) @@ -439,8 +439,8 @@ void QgsSpatiaLiteProviderConnection::setDefaultCapabilities() }; mSqlLayerDefinitionCapabilities = { - SqlLayerDefinitionCapability::Filter, - SqlLayerDefinitionCapability::GeometryColumn + Qgis::SqlLayerDefinitionCapability::Filter, + Qgis::SqlLayerDefinitionCapability::GeometryColumn }; } @@ -622,7 +622,7 @@ QVariantList QgsSpatialiteProviderResultIterator::nextRowInternal() return row; } -qlonglong QgsSpatialiteProviderResultIterator::rowCountPrivate() const +long long QgsSpatialiteProviderResultIterator::rowCountPrivate() const { return mRowCount; } @@ -663,7 +663,7 @@ QString QgsSpatiaLiteProviderConnection::pathFromUri() const return dsUri.database(); } -QMap QgsSpatiaLiteProviderConnection::sqlDictionary() +QMap QgsSpatiaLiteProviderConnection::sqlDictionary() { /* * List from: http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.0.html @@ -687,7 +687,7 @@ QMap Qgs return QgsAbstractDatabaseProviderConnection::sqlDictionary().unite( { { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Math, { + Qgis::SqlKeywordCategory::Math, { // SQL math functions QStringLiteral( "Abs( x [Double precision] )" ), QStringLiteral( "Acos( x [Double precision] )" ), @@ -717,7 +717,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Function, { + Qgis::SqlKeywordCategory::Function, { // Specific QStringLiteral( "last_insert_rowid" ), @@ -805,7 +805,7 @@ QMap Qgs } }, { - QgsAbstractDatabaseProviderConnection::SqlKeywordCategory::Geospatial, { + Qgis::SqlKeywordCategory::Geospatial, { // SQL functions reporting GEOS / LWGEOM errors and warnings QStringLiteral( "GEOS_GetLastWarningMsg( [void] )" ), QStringLiteral( "GEOS_GetLastErrorMsg( [void] )" ), diff --git a/src/providers/spatialite/qgsspatialiteproviderconnection.h b/src/providers/spatialite/qgsspatialiteproviderconnection.h index c99f83c4e54c..15266133168e 100644 --- a/src/providers/spatialite/qgsspatialiteproviderconnection.h +++ b/src/providers/spatialite/qgsspatialiteproviderconnection.h @@ -47,8 +47,8 @@ struct QgsSpatialiteProviderResultIterator: public QgsAbstractDatabaseProviderCo // QueryResultIterator interface private: - qlonglong rowCountPrivate() const override; - qlonglong mRowCount = -1; + long long rowCountPrivate() const override; + long long mRowCount = -1; }; @@ -79,7 +79,7 @@ class QgsSpatiaLiteProviderConnection : public QgsAbstractDatabaseProviderConnec QIcon icon() const override; void deleteField( const QString &fieldName, const QString &schema, const QString &tableName, bool force ) const override; QList nativeTypes() const override; - QMap sqlDictionary() override; + QMap sqlDictionary() override; private: