Skip to content

Commit 8c39192

Browse files
author
Sandro Santilli
committedNov 5, 2012
Only change the TopoGeometry definition, not its reference, on edit
Refactor the TopoGeometry editor to avoid touching the edited table and directly act on the topology relation instead. Fixes #6621 but also generally makes less writes to the database.
1 parent cd69be6 commit 8c39192

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,9 +2407,10 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
24072407
// Later, we'll replace the old TopoGeometry with the new one,
24082408
// to avoid orphans and retain higher level in an eventual
24092409
// 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" )
24132414
.arg( mQuery )
24142415
.arg( quotedIdentifier( mGeometryColumn ) )
24152416
.arg( geomParam( 1 ) )
@@ -2531,6 +2532,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
25312532
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( replace ) );
25322533
throw PGException( result );
25332534
}
2535+
// TODO: use prepared query here
25342536
replace = QString( "UPDATE %1.relation SET topogeo_id = %2 "
25352537
"WHERE layer_id = %3 AND topogeo_id = %4" )
25362538
.arg( quotedIdentifier( toponame ) )
@@ -2545,20 +2547,6 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
25452547
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( replace ) );
25462548
throw PGException( result );
25472549
}
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())) );
25622550
} // if TopoGeometry
25632551

25642552
} // for each feature

0 commit comments

Comments
 (0)
Please sign in to comment.