Skip to content

Commit

Permalink
Also implement hasSpatialIndex for postgres and spatialite
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 17, 2020
1 parent 066cc10 commit 60da8d2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3312,6 +3312,19 @@ QgsVectorDataProvider::Capabilities QgsPostgresProvider::capabilities() const
return mEnabledCapabilities;
}

QgsFeatureSource::SpatialIndexPresence QgsPostgresProvider::hasSpatialIndex() const
{
QgsPostgresProviderConnection conn( mUri.uri(), QVariantMap() );
try
{
return conn.spatialIndexExists( mUri.schema(), mUri.table(), mUri.geometryColumn() ) ? SpatialIndexPresent : SpatialIndexNotPresent;
}
catch ( QgsProviderConnectionException & )
{
return SpatialIndexUnknown;
}
}

bool QgsPostgresProvider::setSubsetString( const QString &theSQL, bool updateFeatureCount )
{
if ( theSQL.trimmed() == mSqlWhereClause )
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -192,6 +192,7 @@ class QgsPostgresProvider final: public QgsVectorDataProvider
bool setSubsetString( const QString &theSQL, bool updateFeatureCount = true ) override;
bool supportsSubsetString() const override { return true; }
QgsVectorDataProvider::Capabilities capabilities() const override;
SpatialIndexPresence hasSpatialIndex() const;

/**
* The Postgres provider does its own transforms so we return
Expand Down
14 changes: 14 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -4273,6 +4273,20 @@ bool QgsSpatiaLiteProvider::createAttributeIndex( int field )
return true;
}

QgsFeatureSource::SpatialIndexPresence QgsSpatiaLiteProvider::hasSpatialIndex() const
{
QgsDataSourceUri u = uri();
QgsSpatiaLiteProviderConnection conn( u.uri(), QVariantMap() );
try
{
return conn.spatialIndexExists( u.schema(), u.table(), u.geometryColumn() ) ? SpatialIndexPresent : SpatialIndexNotPresent;
}
catch ( QgsProviderConnectionException & )
{
return SpatialIndexUnknown;
}
}

bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds &id )
{
sqlite3_stmt *stmt = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/providers/spatialite/qgsspatialiteprovider.h
Expand Up @@ -124,6 +124,7 @@ class QgsSpatiaLiteProvider final: public QgsVectorDataProvider
QVariant defaultValue( int fieldId ) const override;
bool skipConstraintCheck( int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value = QVariant() ) const override;
bool createAttributeIndex( int field ) override;
SpatialIndexPresence hasSpatialIndex() const override;

/**
* The SpatiaLite provider does its own transforms so we return
Expand Down

0 comments on commit 60da8d2

Please sign in to comment.