Skip to content
Permalink
Browse files

Use @@ as primary key separator

  • Loading branch information
mhugent committed Feb 21, 2018
1 parent a3de8e2 commit 40b67e28d4e774eaa842b8e17042431d99dffe3b
Showing with 35 additions and 9 deletions.
  1. +12 −2 src/server/qgsowsserver.cpp
  2. +2 −0 src/server/qgsowsserver.h
  3. +21 −7 src/server/qgswfsserver.cpp
@@ -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;
}
@@ -55,6 +55,8 @@ class QgsOWSServer
*/
static void restoreLayerFilters( const QHash < QgsMapLayer*, QString >& filterMap );

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

private:
QgsOWSServer() {}

@@ -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 );
@@ -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

0 comments on commit 40b67e2

Please sign in to comment.
You can’t perform that action at this time.