Skip to content
Permalink
Browse files

Fixes #16798 FilterFid feature requests with virtual layers

  • Loading branch information
pblottiere committed Nov 7, 2017
1 parent ac574e2 commit d0d88e440a7c847953b49004b6725f90276dc7e3
Showing with 30 additions and 3 deletions.
  1. +30 −3 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
@@ -63,6 +63,7 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
QString tableName = mSource->mTableName;

QStringList wheres;
QString offset;
QString subset = mSource->mSubset;
if ( !subset.isNull() )
{
@@ -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 )
{
@@ -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 )
{
@@ -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;
@@ -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
{

0 comments on commit d0d88e4

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