Skip to content
Permalink
Browse files

fix where clause when multiple features are filtered by ids (fixes #1…

…2616, followup d1e23a6)

(cherry picked from commit 02f5c73)
  • Loading branch information
jef-n committed Apr 21, 2015
1 parent 464646d commit 9e0893f67d318a8a6f0d3bc637130164542c9ad1
@@ -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( ")" );
}


@@ -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
@@ -44,6 +44,11 @@ QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeature
whereClause += whereClauseFid();
}

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

if ( !mSource->mSubsetString.isEmpty() )
{
if ( !whereClause.isEmpty() )
@@ -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();
@@ -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();

0 comments on commit 9e0893f

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