Skip to content
Permalink
Browse files

Do not differentiate strings from non string in conditions

  • Loading branch information
pblottiere committed Jul 3, 2017
1 parent b94d17a commit 8e43acabae76098f61c322ec0720ea90ecf53e06
Showing with 2 additions and 18 deletions.
  1. +2 −18 src/core/qgsrelation.cpp
@@ -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 ) );
}
}

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

1 comment on commit 8e43aca

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson commented on 8e43aca Jul 3, 2017

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.
You can’t perform that action at this time.