Skip to content

Commit 8e43aca

Browse files
committedJul 3, 2017
Do not differentiate strings from non string in conditions
1 parent b94d17a commit 8e43aca

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed
 

‎src/core/qgsrelation.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,9 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
178178
{
179179
conditions << QStringLiteral( "%1 IS NULL" ).arg( quotedColRef );
180180
}
181-
else if ( referencingField.type() == QVariant::String )
182-
{
183-
// Use quotes
184-
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( val.toString() ) );
185-
}
186181
else
187182
{
188-
// No quotes
189-
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, val.toString() );
183+
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( val ) );
190184
}
191185
}
192186

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

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

208-
if ( referencedField.type() == QVariant::String )
209-
{
210-
// Use quotes
211-
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( attributes.at( referencingIdx ).toString() ) );
212-
}
213-
else
214-
{
215-
// No quotes
216-
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, attributes.at( referencingIdx ).toString() );
217-
}
201+
conditions << QStringLiteral( "%1 = %2" ).arg( QgsExpression::quotedColumnRef( fieldPair.referencedField() ), QgsExpression::quotedValue( attributes.at( referencingIdx ) ) );
218202
}
219203

220204
QgsFeatureRequest myRequest;

1 commit comments

Comments
 (1)

nyalldawson commented on Jul 3, 2017

@nyalldawson
Collaborator

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.