Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #16798 FilterFid feature requests with virtual layers
  • Loading branch information
pblottiere committed Nov 15, 2017
1 parent ac574e2 commit d0d88e4
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
Expand Up @@ -63,6 +63,7 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
QString tableName = mSource->mTableName;

QStringList wheres;
QString offset;
QString subset = mSource->mSubset;
if ( !subset.isNull() )
{
Expand Down Expand Up @@ -105,6 +106,13 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
wheres << values;
}
}
else
{
if ( request.filterType() == QgsFeatureRequest::FilterFid )
{
offset = QStringLiteral( " LIMIT 1 OFFSET %1" ).arg( request.filterFid() );
}
}

if ( request.flags() & QgsFeatureRequest::SubsetOfAttributes )
{
Expand Down Expand Up @@ -150,7 +158,14 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
}
else
{
columns = QStringLiteral( "0" );
if ( request.filterType() == QgsFeatureRequest::FilterFid )
{
columns = QStringLiteral( "%1" ).arg( request.filterFid() );
}
else
{
columns = QStringLiteral( "0" );
}
}
Q_FOREACH ( int i, mAttributes )
{
Expand All @@ -173,6 +188,11 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
mSqlQuery += " WHERE " + wheres.join( QStringLiteral( " AND " ) );
}

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

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

mFid = 0;
Expand Down Expand Up @@ -232,8 +252,15 @@ bool QgsVirtualLayerFeatureIterator::fetchFeature( QgsFeature &feature )

if ( mSource->mDefinition.uid().isNull() )
{
// no id column => autoincrement
feature.setId( mFid++ );
if ( mRequest.filterType() == QgsFeatureRequest::FilterFid )
{
feature.setId( mQuery->columnInt64( 0 ) );
}
else
{
// no id column => autoincrement
feature.setId( mFid++ );
}
}
else
{
Expand Down

0 comments on commit d0d88e4

Please sign in to comment.