Skip to content

Commit b3eaede

Browse files
committed
Consider pk/fid in wfs transaction
1 parent 551547a commit b3eaede

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/server/qgsowsserver.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,10 @@ QString QgsOWSServer::featureGmlId( const QgsFeature* f, const QgsAttributeList&
7272
return QString();
7373
}
7474

75-
if ( pkAttributes.isEmpty() )
75+
if ( pkAttributes.size() != 1 )
7676
{
7777
return QString::number( f->id() );
7878
}
7979

80-
QString pkId;
81-
QgsAttributeList::const_iterator it = pkAttributes.constBegin();
82-
for ( ; it != pkAttributes.constEnd(); ++it )
83-
{
84-
pkId.append( f->attribute( *it ).toString() );
85-
}
86-
return pkId;
80+
return f->attribute( pkAttributes.at( 0 ) ).toString();
8781
}

src/server/qgswfsserver.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,25 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( const QDomElement& filterEl
18721872
fid = fidElem.attribute( "fid" );
18731873
if ( fid.contains( "." ) )
18741874
fid = fid.section( ".", 1, 1 );
1875-
fids.insert( fid.toLongLong( &conversionSuccess ) );
1875+
if ( provider->pkAttributeIndexes().size() == 1 )
1876+
{
1877+
//assume ID is the primary key, as it is more stable than the feature ID
1878+
QgsFeature feature;
1879+
const QgsFields& fields = provider->fields();
1880+
QString fieldName = fields[provider->pkAttributeIndexes().at( 0 )].name();
1881+
QgsExpression pkExpression( fieldName + " = " + fid );
1882+
QgsExpressionContext exprContext = QgsExpressionContextUtils::createFeatureBasedContext( feature, fields );
1883+
QgsFeatureRequest fReq( pkExpression, exprContext );
1884+
QgsFeatureIterator fIt = provider->getFeatures( fReq );
1885+
if ( fIt.nextFeature( feature ) )
1886+
{
1887+
fids.insert( feature.id() );
1888+
}
1889+
}
1890+
else //assume it is the feture id
1891+
{
1892+
fids.insert( fid.toLongLong( &conversionSuccess ) );
1893+
}
18761894
}
18771895
}
18781896
else

0 commit comments

Comments
 (0)