Skip to content
Permalink
Browse files

Drop orphaned TopoGeometry objects on deleteFeatures

  • Loading branch information
Sandro Santilli
Sandro Santilli committed Dec 7, 2012
1 parent 542f814 commit eedd89151366fc3c63f4dafcfea44ab4780d56c7
Showing with 36 additions and 3 deletions.
  1. +29 −2 src/providers/postgres/qgspostgresprovider.cpp
  2. +7 −1 src/providers/postgres/qgspostgresprovider.h
@@ -1857,6 +1857,23 @@ bool QgsPostgresProvider::getTopoLayerInfo( )
return true;
}

/* private */
void QgsPostgresProvider::dropOrphanedTopoGeoms( )
{
QString sql = QString( "DELETE FROM %1.relation WHERE layer_id = %2 AND "
"topogeo_id NOT IN ( SELECT id(%3) FROM %4.%5 )" )
.arg( quotedIdentifier(mTopoLayerInfo.topologyName) )
.arg( mTopoLayerInfo.layerId )
.arg( quotedIdentifier(mGeometryColumn) )
.arg( quotedIdentifier(mSchemaName) )
.arg( quotedIdentifier(mTableName) )
;

QgsDebugMsg( "TopoGeom orphans cleanup query: " + sql );

mConnectionRW->PQexecNR( sql );
}

QString QgsPostgresProvider::geomParam( int offset ) const
{
QString geometry;
@@ -2192,6 +2209,18 @@ bool QgsPostgresProvider::deleteFeatures( const QgsFeatureIds & id )

mConnectionRW->PQexecNR( "COMMIT" );

if ( mSpatialColType == sctTopoGeometry )
{
// NOTE: in presence of multiple TopoGeometry objects
// for the same table or when deleting a Geometry
// layer _also_ having a TopoGeometry component,
// orphans would still be left.
// TODO: decouple layer from table and signal table when
// records are added or removed
dropOrphanedTopoGeoms();
}


mFeaturesCounted -= id.size();
}
catch ( PGException &e )
@@ -2574,8 +2603,6 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
// Replace old TopoGeom with new TopoGeom, so that
// any hierarchically defined TopoGeom will still have its
// definition and we'll leave no orphans
// TODO: move this logic into a method using mTopoLayerInfo and
// taking a topogeo_id (to be reused for deleteFeatures)
QString replace = QString( "DELETE FROM %1.relation WHERE "
"layer_id = %2 AND topogeo_id = %3" )
.arg( quotedIdentifier( mTopoLayerInfo.topologyName ) )
@@ -437,16 +437,22 @@ class QgsPostgresProvider : public QgsVectorDataProvider

bool getGeometryDetails();

//! @{ Only used with TopoGeometry layers

struct TopoLayerInfo
{
QString topologyName;
long layerId;
};

TopoLayerInfo mTopoLayerInfo; //! only used with TopoGeometry layers
TopoLayerInfo mTopoLayerInfo;

bool getTopoLayerInfo();

void dropOrphanedTopoGeoms();

//! @}

/* Use estimated metadata. Uses fast table counts, geometry type and extent determination */
bool mUseEstimatedMetadata;

0 comments on commit eedd891

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