Skip to content

Commit

Permalink
Consider pk/fid in wfs transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Feb 19, 2018
1 parent 551547a commit b3eaede
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/server/qgsowsserver.cpp
Expand Up @@ -72,16 +72,10 @@ QString QgsOWSServer::featureGmlId( const QgsFeature* f, const QgsAttributeList&
return QString();
}

if ( pkAttributes.isEmpty() )
if ( pkAttributes.size() != 1 )
{
return QString::number( f->id() );
}

QString pkId;
QgsAttributeList::const_iterator it = pkAttributes.constBegin();
for ( ; it != pkAttributes.constEnd(); ++it )
{
pkId.append( f->attribute( *it ).toString() );
}
return pkId;
return f->attribute( pkAttributes.at( 0 ) ).toString();
}
20 changes: 19 additions & 1 deletion src/server/qgswfsserver.cpp
Expand Up @@ -1872,7 +1872,25 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( const QDomElement& filterEl
fid = fidElem.attribute( "fid" );
if ( fid.contains( "." ) )
fid = fid.section( ".", 1, 1 );
fids.insert( fid.toLongLong( &conversionSuccess ) );
if ( provider->pkAttributeIndexes().size() == 1 )
{
//assume ID is the primary key, as it is more stable than the feature ID
QgsFeature feature;
const QgsFields& fields = provider->fields();
QString fieldName = fields[provider->pkAttributeIndexes().at( 0 )].name();
QgsExpression pkExpression( fieldName + " = " + fid );
QgsExpressionContext exprContext = QgsExpressionContextUtils::createFeatureBasedContext( feature, fields );
QgsFeatureRequest fReq( pkExpression, exprContext );
QgsFeatureIterator fIt = provider->getFeatures( fReq );
if ( fIt.nextFeature( feature ) )
{
fids.insert( feature.id() );
}
}
else //assume it is the feture id
{
fids.insert( fid.toLongLong( &conversionSuccess ) );
}
}
}
else
Expand Down

0 comments on commit b3eaede

Please sign in to comment.