Skip to content

Commit

Permalink
Do not differentiate strings from non string in conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jul 3, 2017
1 parent b94d17a commit 8e43aca
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/core/qgsrelation.cpp
Expand Up @@ -178,15 +178,9 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
{
conditions << QStringLiteral( "%1 IS NULL" ).arg( quotedColRef );
}
else if ( referencingField.type() == QVariant::String )
{
// Use quotes
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( val.toString() ) );
}
else
{
// No quotes
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, val.toString() );
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( val ) );
}
}

Expand All @@ -203,18 +197,8 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );

QgsField referencedField = referencedLayer()->fields().at( referencedIdx );
const QString quotedColRef = QgsExpression::quotedColumnRef( fieldPair.referencedField() ) ;

if ( referencedField.type() == QVariant::String )
{
// Use quotes
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( attributes.at( referencingIdx ).toString() ) );
}
else
{
// No quotes
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, attributes.at( referencingIdx ).toString() );
}
conditions << QStringLiteral( "%1 = %2" ).arg( QgsExpression::quotedColumnRef( fieldPair.referencedField() ), QgsExpression::quotedValue( attributes.at( referencingIdx ) ) );
}

QgsFeatureRequest myRequest;
Expand Down

1 comment on commit 8e43aca

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thinking more about this, we should probably add a reusable function somewhere for creating attribute=value expressions - there's many other parts of the code which create these type of expressions and it'd be good for them to gain the auto-conversion to "is null" expressions too. Maybe something like a static QgsExpression::createFieldEqualsValueExpression( field, value ) function? (Less clumsy naming welcome!)

Please sign in to comment.