Skip to content

Commit b94d17a

Browse files
committedJul 3, 2017
More fixes about filtering safety
1 parent 66591f9 commit b94d17a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎src/core/qgsrelation.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,23 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
170170
{
171171
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );
172172
QgsField referencingField = referencingLayer()->fields().at( referencingIdx );
173+
const QString quotedColRef = QgsExpression::quotedColumnRef( fieldPair.referencingField() ) ;
173174

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

176177
if ( val.isNull() )
177178
{
178-
conditions << QStringLiteral( "\"%1\" IS NULL" ).arg( fieldPair.referencingField() );
179+
conditions << QStringLiteral( "%1 IS NULL" ).arg( quotedColRef );
179180
}
180181
else if ( referencingField.type() == QVariant::String )
181182
{
182183
// Use quotes
183-
conditions << QStringLiteral( "\"%1\" = %2" ).arg( fieldPair.referencingField(), QgsExpression::quotedValue( val.toString() ) );
184+
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( val.toString() ) );
184185
}
185186
else
186187
{
187188
// No quotes
188-
conditions << QStringLiteral( "\"%1\" = %2" ).arg( fieldPair.referencingField(), val.toString() );
189+
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, val.toString() );
189190
}
190191
}
191192

@@ -202,16 +203,17 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes
202203
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );
203204

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

206208
if ( referencedField.type() == QVariant::String )
207209
{
208210
// Use quotes
209-
conditions << QStringLiteral( "\"%1\" = '%2'" ).arg( fieldPair.referencedField(), attributes.at( referencingIdx ).toString() );
211+
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, QgsExpression::quotedValue( attributes.at( referencingIdx ).toString() ) );
210212
}
211213
else
212214
{
213215
// No quotes
214-
conditions << QStringLiteral( "\"%1\" = %2" ).arg( fieldPair.referencedField(), attributes.at( referencingIdx ).toString() );
216+
conditions << QStringLiteral( "%1 = %2" ).arg( quotedColRef, attributes.at( referencingIdx ).toString() );
215217
}
216218
}
217219

0 commit comments

Comments
 (0)
Please sign in to comment.