Skip to content

Commit

Permalink
postgres: also accept PGRES_TUPLES_OK as positive result for UPDATE/D…
Browse files Browse the repository at this point in the history
…ELETE/INSERT (fixes #9738)
  • Loading branch information
jef-n committed May 31, 2014
1 parent bbb7518 commit 7f6663a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsapplication.cpp
Expand Up @@ -1045,6 +1045,6 @@ void QgsApplication::setMaxThreads( int maxThreads )

// set max thread count in QThreadPool
QThreadPool::globalInstance()->setMaxThreadCount( maxThreads );
QgsDebugMsg( QString( "set QThreadPool max thread count to %d" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
QgsDebugMsg( QString( "set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
}

2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -302,7 +302,7 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
if ( mSource->mForce2d )
{
geom = QString( "%1(%2)" )
.arg( mConn->majorVersion() < 2 ? "force2d" : "st_force2d" )
.arg( mConn->majorVersion() < 2 ? "force_2d" : "st_force_2d" )
.arg( geom );
}

Expand Down
17 changes: 7 additions & 10 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1825,7 +1825,7 @@ bool QgsPostgresProvider::deleteFeatures( const QgsFeatureIds & id )

//send DELETE statement and do error handling
QgsPostgresResult result = mConnectionRW->PQexec( sql );
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
if ( result.PQresultStatus() != PGRES_COMMAND_OK && result.PQresultStatus() != PGRES_TUPLES_OK )
throw PGException( result );

mShared->removeFid( *it );
Expand Down Expand Up @@ -2036,7 +2036,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
sql += QString( " WHERE %1" ).arg( whereClause( fid ) );

QgsPostgresResult result = mConnectionRW->PQexec( sql );
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
if ( result.PQresultStatus() != PGRES_COMMAND_OK && result.PQresultStatus() != PGRES_TUPLES_OK )
throw PGException( result );

// update feature id map if key was changed
Expand Down Expand Up @@ -2165,7 +2165,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
QgsDebugMsg( "updating: " + update );

result = mConnectionRW->PQprepare( "updatefeatures", update, 2, NULL );
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
if ( result.PQresultStatus() != PGRES_COMMAND_OK && result.PQresultStatus() != PGRES_TUPLES_OK )
{
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 ) );
Expand Down Expand Up @@ -2203,13 +2203,8 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
appendPkParams( iter.key(), params );

result = mConnectionRW->PQexecPrepared( "updatefeatures", params );
int expected_status = ( mSpatialColType == sctTopoGeometry ) ? PGRES_TUPLES_OK : PGRES_COMMAND_OK;
if ( result.PQresultStatus() != expected_status )
{
QgsDebugMsg( QString( "Exception thrown due to PQexecPrepared of 'updatefeatures' returning %1 != expected %2" )
.arg( result.PQresultStatus() ).arg( expected_status ) );
if ( result.PQresultStatus() != PGRES_COMMAND_OK && result.PQresultStatus() != PGRES_TUPLES_OK )
throw PGException( result );
}

if ( mSpatialColType == sctTopoGeometry )
{
Expand Down Expand Up @@ -2695,6 +2690,7 @@ bool QgsPostgresProvider::getGeometryDetails()
}
layerProperty.geometryColName = mGeometryColumn;
layerProperty.geometryColType = sctNone;
layerProperty.force2d = false;

QString delim = "";

Expand Down Expand Up @@ -2762,7 +2758,8 @@ bool QgsPostgresProvider::getGeometryDetails()
// store whether the geometry includes measure value
if ( detectedType == "POINTM" || detectedType == "MULTIPOINTM" ||
detectedType == "LINESTRINGM" || detectedType == "MULTILINESTRINGM" ||
detectedType == "POLYGONM" || detectedType == "MULTIPOLYGONM" )
detectedType == "POLYGONM" || detectedType == "MULTIPOLYGONM" ||
mForce2d )
{
// explicitly disable adding new features and editing of geometries
// as this would lead to corruption of measures
Expand Down

0 comments on commit 7f6663a

Please sign in to comment.