Skip to content

Commit 40b67e2

Browse files
committedFeb 21, 2018
Use @@ as primary key separator
1 parent a3de8e2 commit 40b67e2

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed
 

‎src/server/qgsowsserver.cpp

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

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

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

‎src/server/qgsowsserver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class QgsOWSServer
5555
*/
5656
static void restoreLayerFilters( const QHash < QgsMapLayer*, QString >& filterMap );
5757

58+
static QString pkSeparator() { return "@@"; }
59+
5860
private:
5961
QgsOWSServer() {}
6062

‎src/server/qgswfsserver.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,13 +1872,31 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( const QDomElement& filterEl
18721872
fid = fidElem.attribute( "fid" );
18731873
if ( fid.contains( "." ) )
18741874
fid = fid.section( ".", 1, 1 );
1875-
if ( provider->pkAttributeIndexes().size() == 1 )
1875+
QgsAttributeList pkAttributes = provider->pkAttributeIndexes();
1876+
if ( pkAttributes.isEmpty() )
1877+
{
1878+
fids.insert( fid.toLongLong( &conversionSuccess ) );
1879+
}
1880+
else
18761881
{
18771882
//assume ID is the primary key, as it is more stable than the feature ID
18781883
QgsFeature feature;
18791884
const QgsFields& fields = provider->fields();
1880-
QString fieldName = fields[provider->pkAttributeIndexes().at( 0 )].name();
1881-
QgsExpression pkExpression( fieldName + " = " + fid );
1885+
1886+
QString expressionString;
1887+
QStringList pkValues = fid.split( pkSeparator() );
1888+
int pkExprSize = qMin( pkAttributes.size(), pkValues.size() );
1889+
for ( int i = 0; i < pkExprSize; ++i )
1890+
{
1891+
if ( i > 0 )
1892+
{
1893+
expressionString.append( " AND " );
1894+
}
1895+
QString fieldName = fields[ pkAttributes.at( i )].name();
1896+
expressionString.append( fieldName + " = " + pkValues.at( i ) );
1897+
}
1898+
QgsExpression pkExpression( expressionString );
1899+
18821900
QgsExpressionContext exprContext = QgsExpressionContextUtils::createFeatureBasedContext( feature, fields );
18831901
QgsFeatureRequest fReq( pkExpression, exprContext );
18841902
QgsFeatureIterator fIt = provider->getFeatures( fReq );
@@ -1887,10 +1905,6 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( const QDomElement& filterEl
18871905
fids.insert( feature.id() );
18881906
}
18891907
}
1890-
else //assume it is the feture id
1891-
{
1892-
fids.insert( fid.toLongLong( &conversionSuccess ) );
1893-
}
18941908
}
18951909
}
18961910
else

0 commit comments

Comments
 (0)
Please sign in to comment.