Skip to content

Commit 35646bb

Browse files
committed
partly fix #6610
1 parent bb426f4 commit 35646bb

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

src/providers/postgres/qgspgsourceselect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
456456
QString srid = layer.srid;
457457
if ( !layer.geometryColName.isNull() )
458458
{
459-
if ( type == "GEOMETRY" || type.isNull() || srid.isEmpty() )
459+
if ( QgsPostgresConn::wkbTypeFromPostgis( type ) == QGis::WKBUnknown || srid.isEmpty() )
460460
{
461461
addSearchGeometryColumn( layer );
462462
type = "";

src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
7474
mSchemaMap[ layerProperty.schemaName ] = schemaItem;
7575
}
7676

77-
if ( layerProperty.type == "GEOMETRY" )
77+
if ( QgsPostgresConn::wkbTypeFromPostgis( layerProperty.type ) == QGis::WKBUnknown )
7878
{
7979
if ( !columnTypeThread )
8080
{

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ bool QgsPostgresProvider::loadFields()
11661166
}
11671167
else
11681168
{
1169-
QgsMessageLog::logMessage( tr( "Field %1 ignored, because of unsupported type %2" ).arg( fieldName ).arg( fieldTType ), tr( "PostGIS" ) );
1169+
QgsMessageLog::logMessage( tr( "Field %1 ignored, because of unsupported type type %2" ).arg( fieldName ).arg( fieldTType ), tr( "PostGIS" ) );
11701170
continue;
11711171
}
11721172

@@ -2413,27 +2413,31 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
24132413
.arg( pkParamWhereClause( 2 ) );
24142414

24152415
QString getid = QString( "SELECT id(%1) FROM %2 WHERE %3" )
2416-
.arg( quotedIdentifier( mGeometryColumn ) )
2417-
.arg( mQuery )
2418-
.arg( pkParamWhereClause( 1 ) );
2416+
.arg( quotedIdentifier( mGeometryColumn ) )
2417+
.arg( mQuery )
2418+
.arg( pkParamWhereClause( 1 ) );
24192419

24202420
QgsDebugMsg( "getting old topogeometry id: " + getid );
24212421

24222422
result = mConnectionRO->PQprepare( "getid", getid, 1, NULL );
2423-
if ( result.PQresultStatus() != PGRES_COMMAND_OK ) {
2424-
QgsDebugMsg( QString("Exception thrown due to PQprepare of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK).arg(getid) );
2423+
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
2424+
{
2425+
QgsDebugMsg( QString( "Exception thrown due to PQprepare of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3" )
2426+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( getid ) );
24252427
throw PGException( result );
24262428
}
24272429

24282430
QString replace = QString( "UPDATE %1 SET %2="
2429-
"( topology_id(%2),layer_id(%2),$1,type(%2) )"
2430-
"WHERE %3" )
2431-
.arg( mQuery )
2432-
.arg( quotedIdentifier( mGeometryColumn ) )
2433-
.arg( pkParamWhereClause( 2 ) );
2431+
"( topology_id(%2),layer_id(%2),$1,type(%2) )"
2432+
"WHERE %3" )
2433+
.arg( mQuery )
2434+
.arg( quotedIdentifier( mGeometryColumn ) )
2435+
.arg( pkParamWhereClause( 2 ) );
24342436
result = mConnectionRW->PQprepare( "replacetopogeom", replace, 2, NULL );
2435-
if ( result.PQresultStatus() != PGRES_COMMAND_OK ) {
2436-
QgsDebugMsg( QString("Exception thrown due to PQprepare of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK).arg(replace) );
2437+
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
2438+
{
2439+
QgsDebugMsg( QString( "Exception thrown due to PQprepare of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3" )
2440+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( replace ) );
24372441
throw PGException( result );
24382442
}
24392443

@@ -2450,8 +2454,10 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
24502454
QgsDebugMsg( "updating: " + update );
24512455

24522456
result = mConnectionRW->PQprepare( "updatefeatures", update, 2, NULL );
2453-
if ( result.PQresultStatus() != PGRES_COMMAND_OK ) {
2454-
QgsDebugMsg( QString("Exception thrown due to PQprepare of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK).arg(update) );
2457+
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
2458+
{
2459+
QgsDebugMsg( QString( "Exception thrown due to PQprepare of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3" )
2460+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( update ) );
24552461
throw PGException( result );
24562462
}
24572463

@@ -2476,13 +2482,15 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
24762482
QStringList params;
24772483
appendPkParams( iter.key(), params );
24782484
result = mConnectionRO->PQexecPrepared( "getid", params );
2479-
if ( result.PQresultStatus() != PGRES_TUPLES_OK ) {
2480-
QgsDebugMsg( QString("Exception thrown due to PQexecPrepared of 'getid' returning != PGRES_COMMAND_OK (%1 != expected %2)").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK) );
2485+
if ( result.PQresultStatus() != PGRES_TUPLES_OK )
2486+
{
2487+
QgsDebugMsg( QString( "Exception thrown due to PQexecPrepared of 'getid' returning != PGRES_COMMAND_OK (%1 != expected %2)" )
2488+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ) );
24812489
throw PGException( result );
24822490
}
24832491
// TODO: watch out for NULL , handle somehow
2484-
old_tg_id = result.PQgetvalue( 0, 0 ).toLong();
2485-
QgsDebugMsg( QString("Old TG id is %1").arg(old_tg_id) );
2492+
old_tg_id = result.PQgetvalue( 0, 0 ).toLong();
2493+
QgsDebugMsg( QString( "Old TG id is %1" ).arg( old_tg_id ) );
24862494
}
24872495

24882496
QStringList params;
@@ -2493,7 +2501,8 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
24932501
int expected_status = ( mSpatialColType == sctTopoGeometry ) ? PGRES_TUPLES_OK : PGRES_COMMAND_OK;
24942502
if ( result.PQresultStatus() != expected_status )
24952503
{
2496-
QgsDebugMsg( QString("Exception thrown due to PQexecPrepared of 'getid' returning != PGRES_COMMAND_OK (%1 != expected %2)").arg(result.PQresultStatus()).arg(expected_status) );
2504+
QgsDebugMsg( QString( "Exception thrown due to PQexecPrepared of 'getid' returning != PGRES_COMMAND_OK (%1 != expected %2)" )
2505+
.arg( result.PQresultStatus() ).arg( expected_status ) );
24972506
throw PGException( result );
24982507
}
24992508

@@ -2508,43 +2517,49 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
25082517
// definition and we'll leave no orphans
25092518
QString replace = QString( "DELETE FROM %1.relation WHERE "
25102519
"layer_id = %2 AND topogeo_id = %3" )
2511-
.arg( quotedIdentifier(toponame) )
2520+
.arg( quotedIdentifier( toponame ) )
25122521
.arg( layer_id )
25132522
.arg( old_tg_id );
25142523
result = mConnectionRW->PQexec( replace );
2515-
if ( result.PQresultStatus() != PGRES_COMMAND_OK ) {
2516-
QgsDebugMsg( QString("Exception thrown due to PQexec of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK).arg(replace) );
2524+
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
2525+
{
2526+
QgsDebugMsg( QString( "Exception thrown due to PQexec of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3" )
2527+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( replace ) );
25172528
throw PGException( result );
25182529
}
25192530
replace = QString( "UPDATE %1.relation SET topogeo_id = %2 "
25202531
"WHERE layer_id = %3 AND topogeo_id = %4" )
2521-
.arg( quotedIdentifier(toponame) )
2532+
.arg( quotedIdentifier( toponame ) )
25222533
.arg( old_tg_id )
25232534
.arg( layer_id )
25242535
.arg( new_tg_id );
25252536
QgsDebugMsg( "relation swap: " + replace );
25262537
result = mConnectionRW->PQexec( replace );
2527-
if ( result.PQresultStatus() != PGRES_COMMAND_OK ) {
2528-
QgsDebugMsg( QString("Exception thrown due to PQexec of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK).arg(replace) );
2538+
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
2539+
{
2540+
QgsDebugMsg( QString( "Exception thrown due to PQexec of this query returning != PGRES_COMMAND_OK (%1 != expected %2): %3" )
2541+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ).arg( replace ) );
25292542
throw PGException( result );
25302543
}
25312544
// Change the ID of the TopoGeometry object put in the table again
25322545
params = QStringList();
25332546
params << QString::number( old_tg_id );
25342547
appendPkParams( iter.key(), params );
2535-
QgsDebugMsg( "Replacing topogeom reference to use id " + QString::number(old_tg_id) );
2548+
QgsDebugMsg( "Replacing topogeom reference to use id " + QString::number( old_tg_id ) );
25362549
result = mConnectionRW->PQexecPrepared( "replacetopogeom", params );
25372550
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
25382551
{
2539-
QgsDebugMsg( QString("Exception thrown due to PQexecPrepared of 'replacetopogeom' returning != PGRES_COMMAND_OK (%1 != expected %2)").arg(result.PQresultStatus()).arg(PGRES_COMMAND_OK) );
2552+
QgsDebugMsg( QString( "Exception thrown due to PQexecPrepared of 'replacetopogeom' returning != PGRES_COMMAND_OK (%1 != expected %2)" )
2553+
.arg( result.PQresultStatus() ).arg( PGRES_COMMAND_OK ) );
25402554
throw PGException( result );
25412555
}
25422556
} // if TopoGeometry
25432557

25442558
} // for each feature
25452559

25462560
mConnectionRW->PQexecNR( "DEALLOCATE updatefeatures" );
2547-
if ( mSpatialColType == sctTopoGeometry ) {
2561+
if ( mSpatialColType == sctTopoGeometry )
2562+
{
25482563
mConnectionRO->PQexecNR( "DEALLOCATE getid" );
25492564
mConnectionRW->PQexecNR( "DEALLOCATE replacetopogeom" );
25502565
}
@@ -2555,7 +2570,8 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
25552570
pushError( tr( "PostGIS error while changing geometry values: %1" ).arg( e.errorMessage() ) );
25562571
mConnectionRW->PQexecNR( "ROLLBACK" );
25572572
mConnectionRW->PQexecNR( "DEALLOCATE updatefeatures" );
2558-
if ( mSpatialColType == sctTopoGeometry ) {
2573+
if ( mSpatialColType == sctTopoGeometry )
2574+
{
25592575
mConnectionRO->PQexecNR( "DEALLOCATE getid" );
25602576
mConnectionRW->PQexecNR( "DEALLOCATE replacetopogeom" );
25612577
}

0 commit comments

Comments
 (0)