Skip to content

Commit

Permalink
fix where clause when multiple features are filtered by ids (fixes #1…
Browse files Browse the repository at this point in the history
…2616, followup d1e23a6)

(cherry picked from commit 02f5c73)
  • Loading branch information
jef-n committed Apr 26, 2015
1 parent 464646d commit 9e0893f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/providers/oracle/qgsoracleprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ QString QgsOracleUtils::whereClause( QgsFeatureIds featureIds, const QgsFields &
{
whereClauses << whereClause( featureId, fields, primaryKeyType, primaryKeyAttrs, sharedData );
}
return whereClauses.join( " AND " );
return whereClauses.isEmpty() ? "" : whereClauses.join( " OR " ).prepend( "(" ).append( ")" );
}


Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ QString QgsPostgresUtils::whereClause( QgsFeatureIds featureIds, const QgsFields
whereClauses << whereClause( featureId, fields, conn, pkType, pkAttrs, sharedData );
}

return whereClauses.join( " OR " );
return whereClauses.isEmpty() ? "" : whereClauses.join( " OR " ).prepend( "(" ).append( ")" );
}

QString QgsPostgresProvider::filterWhereClause() const
Expand Down
15 changes: 15 additions & 0 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeature
whereClause += whereClauseFid();
}

if ( request.filterType() == QgsFeatureRequest::FilterFids )
{
whereClause += whereClauseFids();
}

if ( !mSource->mSubsetString.isEmpty() )
{
if ( !whereClause.isEmpty() )
Expand Down Expand Up @@ -196,6 +201,16 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseFid()
return QString( "%1=%2" ).arg( quotedPrimaryKey() ).arg( mRequest.filterFid() );
}

QString QgsSpatiaLiteFeatureIterator::whereClauseFids()
{
QStringList whereClauses;
foreach ( const QgsFeatureId featureId, mRequest.filterFids() )
{
whereClauses << QString( "%1=%2" ).arg( quotedPrimaryKey() ).arg( featureId );
}
return whereClauses.isEmpty() ? "" : whereClauses.join( " OR " ).prepend( "(" ).append( ")" );
}

QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
{
QgsRectangle rect = mRequest.filterRect();
Expand Down
1 change: 1 addition & 0 deletions src/providers/spatialite/qgsspatialitefeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class QgsSpatiaLiteFeatureIterator : public QgsAbstractFeatureIteratorFromSource

QString whereClauseRect();
QString whereClauseFid();
QString whereClauseFids();
QString mbr( const QgsRectangle& rect );
bool prepareStatement( QString whereClause );
QString quotedPrimaryKey();
Expand Down

0 comments on commit 9e0893f

Please sign in to comment.