@@ -2407,9 +2407,10 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
2407
2407
// Later, we'll replace the old TopoGeometry with the new one,
2408
2408
// to avoid orphans and retain higher level in an eventual
2409
2409
// hierarchical definition
2410
- update = QString ( " UPDATE %1 o SET %2 = toTopoGeom(%3, t.name, layer_id(%2))"
2411
- " FROM topology.topology t WHERE t.id = topology_id(%2)"
2412
- " AND %4 RETURNING layer_id(%2), id(%2), t.name" )
2410
+ update = QString ( " WITH tg AS ( SELECT t.name, "
2411
+ " toTopoGeom(%3, t.name, layer_id(o.%2)) as tg"
2412
+ " FROM %1 o, topology.topology t WHERE t.id = topology_id(o.%2)"
2413
+ " AND %4 ) SELECT layer_id(tg.tg), id(tg.tg), tg.name FROM tg" )
2413
2414
.arg ( mQuery )
2414
2415
.arg ( quotedIdentifier ( mGeometryColumn ) )
2415
2416
.arg ( geomParam ( 1 ) )
@@ -2531,6 +2532,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
2531
2532
.arg ( result.PQresultStatus () ).arg ( PGRES_COMMAND_OK ).arg ( replace ) );
2532
2533
throw PGException ( result );
2533
2534
}
2535
+ // TODO: use prepared query here
2534
2536
replace = QString ( " UPDATE %1.relation SET topogeo_id = %2 "
2535
2537
" WHERE layer_id = %3 AND topogeo_id = %4" )
2536
2538
.arg ( quotedIdentifier ( toponame ) )
@@ -2545,20 +2547,6 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
2545
2547
.arg ( result.PQresultStatus () ).arg ( PGRES_COMMAND_OK ).arg ( replace ) );
2546
2548
throw PGException ( result );
2547
2549
}
2548
- // Change the ID of the TopoGeometry object put in the table again
2549
- params = QStringList ();
2550
- params << QString::number ( old_tg_id );
2551
- appendPkParams ( iter.key (), params );
2552
- QgsDebugMsg ( " Replacing topogeom reference to use id " + QString::number ( old_tg_id ) );
2553
- QgsDebugMsg ( " Params are: " + params.join (" ," ));
2554
- result = mConnectionRW ->PQexecPrepared ( " replacetopogeom" , params );
2555
- if ( result.PQresultStatus () != PGRES_COMMAND_OK )
2556
- {
2557
- QgsDebugMsg ( QString ( " Exception thrown due to PQexecPrepared of 'replacetopogeom' returning != PGRES_COMMAND_OK (%1 != expected %2)" )
2558
- .arg ( result.PQresultStatus () ).arg ( PGRES_COMMAND_OK ) );
2559
- throw PGException ( result );
2560
- }
2561
- QgsDebugMsg ( QString ( " TopoGeom swap affected " + QString::number (result.PQntuples ())) );
2562
2550
} // if TopoGeometry
2563
2551
2564
2552
} // for each feature
0 commit comments