From bbecffdb659ce3b5d33d11fa93290f7c04b9cbff Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 31 Oct 2012 23:34:21 +0100 Subject: [PATCH] Add initial support for editing TopoGeometry objects This is pretty hackish in that it basically creates a new TopoGeometry on every edit, leaving loads of orphaned ones around. --- .../postgres/qgspostgresprovider.cpp | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index 976f0514cfc..402905c0cc9 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -2412,11 +2412,28 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map ) // Start the PostGIS transaction mConnectionRW->PQexecNR( "BEGIN" ); - QString update = QString( "UPDATE %1 SET %2=%3 WHERE %4" ) - .arg( mQuery ) - .arg( quotedIdentifier( mGeometryColumn ) ) - .arg( geomParam( 1 ) ) - .arg( pkParamWhereClause( 2 ) ); + QString update; + + if ( mSpatialColType == sctTopoGeometry ) { + // NOTE: We are creating a new TopoGeometry objects with the new shape. + // TODO: _replace_ the initial TopoGeometry instead, so that it keeps + // the same identifier and thus still partecipates in any + // hierarchical definition. Also creating a new object results + // in orphaned topogeometries! + update = QString( "UPDATE %1 SET %2=toTopoGeom(%3,t.name,layer_id(%2))" + " FROM topology.topology t WHERE t.id = topology_id(%2)" + " AND %4" ) + .arg( mQuery ) + .arg( quotedIdentifier( mGeometryColumn ) ) + .arg( geomParam( 1 ) ) + .arg( pkParamWhereClause( 2 ) ); + } else { + update = QString( "UPDATE %1 SET %2=%3 WHERE %4" ) + .arg( mQuery ) + .arg( quotedIdentifier( mGeometryColumn ) ) + .arg( geomParam( 1 ) ) + .arg( pkParamWhereClause( 2 ) ); + } QgsDebugMsg( "updating: " + update );