Skip to content
Permalink
Browse files

Fixes #16798 FilterFid feature requests with virtual layers

  • Loading branch information
pblottiere committed Nov 22, 2017
1 parent 10b34b9 commit 577c1f2eabd453ee38fd5e4390f7d9904c5e371f
Showing with 28 additions and 2 deletions.
  1. +28 −2 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
@@ -37,6 +37,7 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
QString tableName = mSource->provider()->mTableName;

QStringList wheres;
QString offset;
QString subset = mSource->provider()->mSubset;
if ( !subset.isNull() )
{
@@ -76,6 +77,17 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
values += ")";
wheres << values;
}
else if ( mDefinition.uid().isNull() && request.filterType() == QgsFeatureRequest::FilterFid )
{
if ( request.filterFid() >= 0 )
{
offset = QString( " LIMIT 1 OFFSET %1" ).arg( request.filterFid() );
}
else // never return a feature if the id is negative
{
offset = QString( " LIMIT 0" );
}
}

mFields = mSource->provider()->fields();
if ( request.flags() & QgsFeatureRequest::SubsetOfAttributes )
@@ -111,7 +123,15 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
}
else
{
columns = "0";
columns = QString( "0" );
if ( request.filterType() == QgsFeatureRequest::FilterFid )
{
columns = QString::number( request.filterFid() );
}
else
{
columns = QString( "0" );
}
}
Q_FOREACH ( int i, mAttributes )
{
@@ -134,6 +154,11 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
mSqlQuery += " WHERE " + wheres.join( " AND " );
}

if ( !offset.isEmpty() )
{
mSqlQuery += offset;
}

mQuery.reset( new Sqlite::Query( mSqlite, mSqlQuery ) );

mFid = 0;
@@ -191,7 +216,8 @@ bool QgsVirtualLayerFeatureIterator::fetchFeature( QgsFeature& feature )

feature.setFields( mFields, /* init */ true );

if ( mDefinition.uid().isNull() )
if ( mDefinition.uid().isNull() &&
mRequest.filterType() != QgsFeatureRequest::FilterFid )
{
// no id column => autoincrement
feature.setFeatureId( mFid++ );

0 comments on commit 577c1f2

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