Skip to content

Commit 9e0893f

Browse files
committed
fix where clause when multiple features are filtered by ids (fixes #12616, followup d1e23a6)
(cherry picked from commit 02f5c73)
1 parent 464646d commit 9e0893f

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/providers/oracle/qgsoracleprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ QString QgsOracleUtils::whereClause( QgsFeatureIds featureIds, const QgsFields &
461461
{
462462
whereClauses << whereClause( featureId, fields, primaryKeyType, primaryKeyAttrs, sharedData );
463463
}
464-
return whereClauses.join( " AND " );
464+
return whereClauses.isEmpty() ? "" : whereClauses.join( " OR " ).prepend( "(" ).append( ")" );
465465
}
466466

467467

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ QString QgsPostgresUtils::whereClause( QgsFeatureIds featureIds, const QgsFields
545545
whereClauses << whereClause( featureId, fields, conn, pkType, pkAttrs, sharedData );
546546
}
547547

548-
return whereClauses.join( " OR " );
548+
return whereClauses.isEmpty() ? "" : whereClauses.join( " OR " ).prepend( "(" ).append( ")" );
549549
}
550550

551551
QString QgsPostgresProvider::filterWhereClause() const

src/providers/spatialite/qgsspatialitefeatureiterator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeature
4444
whereClause += whereClauseFid();
4545
}
4646

47+
if ( request.filterType() == QgsFeatureRequest::FilterFids )
48+
{
49+
whereClause += whereClauseFids();
50+
}
51+
4752
if ( !mSource->mSubsetString.isEmpty() )
4853
{
4954
if ( !whereClause.isEmpty() )
@@ -196,6 +201,16 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseFid()
196201
return QString( "%1=%2" ).arg( quotedPrimaryKey() ).arg( mRequest.filterFid() );
197202
}
198203

204+
QString QgsSpatiaLiteFeatureIterator::whereClauseFids()
205+
{
206+
QStringList whereClauses;
207+
foreach ( const QgsFeatureId featureId, mRequest.filterFids() )
208+
{
209+
whereClauses << QString( "%1=%2" ).arg( quotedPrimaryKey() ).arg( featureId );
210+
}
211+
return whereClauses.isEmpty() ? "" : whereClauses.join( " OR " ).prepend( "(" ).append( ")" );
212+
}
213+
199214
QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
200215
{
201216
QgsRectangle rect = mRequest.filterRect();

src/providers/spatialite/qgsspatialitefeatureiterator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class QgsSpatiaLiteFeatureIterator : public QgsAbstractFeatureIteratorFromSource
7171

7272
QString whereClauseRect();
7373
QString whereClauseFid();
74+
QString whereClauseFids();
7475
QString mbr( const QgsRectangle& rect );
7576
bool prepareStatement( QString whereClause );
7677
QString quotedPrimaryKey();

0 commit comments

Comments
 (0)