Skip to content
Permalink
Browse files

More fixes about filtering safety

  • Loading branch information
pblottiere committed Jul 3, 2017
1 parent 66591f9 commit b94d17a7dc904b02f5fcf82cf2d94a1a72c9aab0
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/core/qgsrelation.cpp
@@ -170,22 +170,23 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
{
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );
QgsField referencingField = referencingLayer()->fields().at( referencingIdx );
const QString quotedColRef = QgsExpression::quotedColumnRef( fieldPair.referencingField() ) ;

QVariant val( feature.attribute( fieldPair.referencedField() ) );

if ( val.isNull() )
{
conditions << QStringLiteral( "\"%1\" IS NULL" ).arg( fieldPair.referencingField() );
conditions << QStringLiteral( "%1 IS NULL" ).arg( quotedColRef );
}
else if ( referencingField.type() == QVariant::String )
{
// Use quotes
conditions << QStringLiteral( "\"%1\" = %2" ).arg( fieldPair.referencingField(), QgsExpression::quotedValue( val.toString() ) );
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( val.toString() ) );
}
else
{
// No quotes
conditions << QStringLiteral( "\"%1\" = %2" ).arg( fieldPair.referencingField(), val.toString() );
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, val.toString() );
}
}

@@ -202,16 +203,17 @@ 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( fieldPair.referencedField(), attributes.at( referencingIdx ).toString() );
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( attributes.at( referencingIdx ).toString() ) );
}
else
{
// No quotes
conditions << QStringLiteral( "\"%1\" = %2" ).arg( fieldPair.referencedField(), attributes.at( referencingIdx ).toString() );
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, attributes.at( referencingIdx ).toString() );
}
}

0 comments on commit b94d17a

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