Skip to content
Permalink
Browse files

postgres provider: avoid additional fetch after all features have alr…

…eady been processed
  • Loading branch information
jef-n committed Nov 10, 2015
1 parent 452e61c commit 81bbb8235c8073382d03eba356f3a66822b73d69
@@ -35,6 +35,7 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
, mFetched( 0 )
, mFetchGeometry( false )
, mExpressionCompiled( false )
, mLastFetch( false )
{
if ( !source->mTransactionConnection )
{
@@ -119,7 +120,7 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
if ( mClosed )
return false;

if ( mFeatureQueue.empty() )
if ( mFeatureQueue.empty() && !mLastFetch )
{
QString fetch = QString( "FETCH FORWARD %1 FROM %2" ).arg( mFeatureQueueSize ).arg( mCursorName );
QgsDebugMsgLevel( QString( "fetching %1 features." ).arg( mFeatureQueueSize ), 4 );
@@ -145,6 +146,8 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
if ( rows == 0 )
continue;

mLastFetch = rows < mFeatureQueueSize;

for ( int row = 0; row < rows; row++ )
{
mFeatureQueue.enqueue( QgsFeature() );
@@ -323,7 +326,6 @@ QString QgsPostgresFeatureIterator::whereClauseRect()
bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
{
mFetchGeometry = !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && !mSource->mGeometryColumn.isNull();

#if 0
// TODO: check that all field indexes exist
if ( !hasAllFields )
@@ -432,6 +434,7 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
return false;
}

mLastFetch = false;
return true;
}

@@ -125,6 +125,7 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIteratorFromSource<Q
virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;

bool mExpressionCompiled;
bool mLastFetch;
};

#endif // QGSPOSTGRESFEATUREITERATOR_H

0 comments on commit 81bbb82

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