Skip to content
Permalink
Browse files

Also implement hasSpatialIndex for postgres and spatialite

  • Loading branch information
nyalldawson committed Mar 17, 2020
1 parent 066cc10 commit 60da8d2e5c23808f1525bc308b4f46e24829f623
@@ -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 )
@@ -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
@@ -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;
@@ -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

0 comments on commit 60da8d2

Please sign in to comment.
You can’t perform that action at this time.