Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use @@ as primary key separator
  • Loading branch information
mhugent committed Feb 21, 2018
1 parent a3de8e2 commit 40b67e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/server/qgsowsserver.cpp
Expand Up @@ -72,10 +72,20 @@ QString QgsOWSServer::featureGmlId( const QgsFeature* f, const QgsAttributeList&
return QString();
}

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

return f->attribute( pkAttributes.at( 0 ) ).toString();
QString pkId;
QgsAttributeList::const_iterator it = pkAttributes.constBegin();
for ( ; it != pkAttributes.constEnd(); ++it )
{
if ( it != pkAttributes.constBegin() )
{
pkId.append( pkSeparator() );
}
pkId.append( f->attribute( *it ).toString() );
}
return pkId;
}
2 changes: 2 additions & 0 deletions src/server/qgsowsserver.h
Expand Up @@ -55,6 +55,8 @@ class QgsOWSServer
*/
static void restoreLayerFilters( const QHash < QgsMapLayer*, QString >& filterMap );

static QString pkSeparator() { return "@@"; }

private:
QgsOWSServer() {}

Expand Down
28 changes: 21 additions & 7 deletions src/server/qgswfsserver.cpp
Expand Up @@ -1872,13 +1872,31 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( const QDomElement& filterEl
fid = fidElem.attribute( "fid" );
if ( fid.contains( "." ) )
fid = fid.section( ".", 1, 1 );
if ( provider->pkAttributeIndexes().size() == 1 )
QgsAttributeList pkAttributes = provider->pkAttributeIndexes();
if ( pkAttributes.isEmpty() )
{
fids.insert( fid.toLongLong( &conversionSuccess ) );
}
else
{
//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 );

QString expressionString;
QStringList pkValues = fid.split( pkSeparator() );
int pkExprSize = qMin( pkAttributes.size(), pkValues.size() );
for ( int i = 0; i < pkExprSize; ++i )
{
if ( i > 0 )
{
expressionString.append( " AND " );
}
QString fieldName = fields[ pkAttributes.at( i )].name();
expressionString.append( fieldName + " = " + pkValues.at( i ) );
}
QgsExpression pkExpression( expressionString );

QgsExpressionContext exprContext = QgsExpressionContextUtils::createFeatureBasedContext( feature, fields );
QgsFeatureRequest fReq( pkExpression, exprContext );
QgsFeatureIterator fIt = provider->getFeatures( fReq );
Expand All @@ -1887,10 +1905,6 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( const QDomElement& filterEl
fids.insert( feature.id() );
}
}
else //assume it is the feture id
{
fids.insert( fid.toLongLong( &conversionSuccess ) );
}
}
}
else
Expand Down

0 comments on commit 40b67e2

Please sign in to comment.