2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void QgsOgrFeatureIterator::ensureRelevantFields()
{
mFetchGeometry = ( mRequest.filterType() == QgsFeatureRequest::FilterRect ) || !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
QgsAttributeList attrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : P->attributeIndexes();
P->setRelevantFields( mFetchGeometry, attrs );
P->setRelevantFields( ogrLayer, mFetchGeometry, attrs );
P->mRelevantFieldsForNextFeature = true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ QStringList QgsOgrProvider::subLayers() const
// Count features for geometry types
QMap<OGRwkbGeometryType, int> fCount;
// TODO: avoid reading attributes, setRelevantFields cannot be called here because it is not constant
//setRelevantFields( true, QgsAttributeList() );
//setRelevantFields( ogrLayer, true, QgsAttributeList() );
OGR_L_ResetReading( layer );
OGRFeatureH fet;
while (( fet = OGR_L_GetNextFeature( layer ) ) )
Expand Down Expand Up @@ -714,7 +714,7 @@ QString QgsOgrProvider::storageType() const
return ogrDriverName;
}

void QgsOgrProvider::setRelevantFields( bool fetchGeometry, const QgsAttributeList &fetchAttributes )
void QgsOgrProvider::setRelevantFields( OGRLayerH ogrLayer, bool fetchGeometry, const QgsAttributeList &fetchAttributes )
{
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
if ( OGR_L_TestCapability( ogrLayer, OLCIgnoreFields ) )
Expand Down Expand Up @@ -972,7 +972,7 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )

bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
{
setRelevantFields( true, attributeIndexes() );
setRelevantFields( ogrLayer, true, attributeIndexes() );

bool returnvalue = true;
for ( QgsFeatureList::iterator it = flist.begin(); it != flist.end(); ++it )
Expand Down Expand Up @@ -1074,7 +1074,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr

clearMinMaxCache();

setRelevantFields( true, attributeIndexes() );
setRelevantFields( ogrLayer, true, attributeIndexes() );

for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin(); it != attr_map.end(); ++it )
{
Expand Down Expand Up @@ -1170,7 +1170,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
OGRFeatureH theOGRFeature = 0;
OGRGeometryH theNewGeometry = 0;

setRelevantFields( true, attributeIndexes() );
setRelevantFields( ogrLayer, true, attributeIndexes() );

for ( QgsGeometryMap::iterator it = geometry_map.begin(); it != geometry_map.end(); ++it )
{
Expand Down Expand Up @@ -2382,7 +2382,7 @@ void QgsOgrProvider::recalculateFeatureCount()
{
featuresCounted = 0;
OGR_L_ResetReading( ogrLayer );
setRelevantFields( true, QgsAttributeList() );
setRelevantFields( ogrLayer, true, QgsAttributeList() );
OGR_L_ResetReading( ogrLayer );
OGRFeatureH fet;
while (( fet = OGR_L_GetNextFeature( ogrLayer ) ) )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
void recalculateFeatureCount();

/** tell OGR, which fields to fetch in nextFeature/featureAtId (ie. which not to ignore) */
void setRelevantFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes );
void setRelevantFields( OGRLayerH ogrLayer, bool fetchGeometry, const QgsAttributeList& fetchAttributes );

/** convert a QgsField to work with OGR */
static bool convertField( QgsField &field, const QTextCodec &encoding );
Expand Down
8 changes: 6 additions & 2 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
// handling a VirtualShape layer
whereClause += QString( "MbrIntersects(%1, BuildMbr(%2))" ).arg( P->quotedIdentifier( P->mGeometryColumn ) ).arg( mbr( rect ) );
}
else
else if ( rect.isFinite() )
{
if ( P->spatialIndexRTree && rect.isFinite() )
if ( P->spatialIndexRTree )
{
// using the RTree spatial index
QString mbrFilter = QString( "xmin <= %1 AND " ).arg( qgsDoubleToString( rect.xMaximum() ) );
Expand Down Expand Up @@ -251,6 +251,10 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
whereClause += QString( "MbrIntersects(%1, BuildMbr(%2))" ).arg( P->quotedIdentifier( P->mGeometryColumn ) ).arg( mbr( rect ) );
}
}
else
{
whereClause = "1";
}
return whereClause;
}

Expand Down