Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Postgres feature iterator fixes (rewind, FID filter, closing)
  • Loading branch information
wonder-sk committed Jan 6, 2013
1 parent 5b00800 commit 353e7ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -32,7 +32,6 @@ const int QgsPostgresFeatureIterator::sFeatureQueueSize = 2000;
QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p )
, mFeatureQueueSize( sFeatureQueueSize )
, mUseQueue( true )
{
mCursorName = QString( "qgisf%1" ).arg( P->mProviderId );

Expand All @@ -45,7 +44,6 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresProvider* p,
else if ( request.filterType() == QgsFeatureRequest::FilterFid )
{
whereClause = P->whereClause( request.filterFid() );
mUseQueue = false; // queue not necessary
}

if ( !P->mSqlWhereClause.isEmpty() )
Expand Down Expand Up @@ -79,12 +77,12 @@ bool QgsPostgresFeatureIterator::nextFeature( QgsFeature& feature )
if ( mClosed )
return false;

#if 0
// featureAtId used to have some special checks - necessary?
if ( !mUseQueue )
{
QgsPostgresResult queryResult = P->mConnectionRO->PQexec( QString( "FETCH FORWARD 1 FROM %1" ).arg( mCursorName ) );

/*
// TODO: really needed?
int rows = queryResult.PQntuples();
if ( rows == 0 )
{
Expand All @@ -95,14 +93,15 @@ bool QgsPostgresFeatureIterator::nextFeature( QgsFeature& feature )
else if ( rows != 1 )
{
QgsMessageLog::logMessage( tr( "found %1 features instead of just one." ).arg( rows ), tr( "PostGIS" ) );
}*/
}

bool gotit = getFeature( queryResult, 0, feature );

feature.setValid( gotit );
feature.setFields( &P->mAttributeFields ); // allow name-based attribute lookups
return gotit;
}
#endif

if ( mFeatureQueue.empty() )
{
Expand Down Expand Up @@ -141,8 +140,7 @@ bool QgsPostgresFeatureIterator::nextFeature( QgsFeature& feature )
if ( mFeatureQueue.empty() )
{
QgsDebugMsg( QString( "Finished after %1 features" ).arg( mFetched ) );
P->mConnectionRO->closeCursor( mCursorName );
mClosed = true;

if ( P->mFeaturesCounted < mFetched )
{
QgsDebugMsg( QString( "feature count adjusted from %1 to %2" ).arg( P->mFeaturesCounted ).arg( mFetched ) );
Expand Down Expand Up @@ -179,8 +177,9 @@ bool QgsPostgresFeatureIterator::rewind()
return false;

// move cursor to first record
P->mConnectionRO->PQexecNR( QString( "move 0 in %1" ).arg( mCursorName ) );
P->mConnectionRO->PQexecNR( QString( "move absolute 0 in %1" ).arg( mCursorName ) );
mFeatureQueue.empty();
mFetched = 0;

return true;
}
Expand All @@ -197,6 +196,7 @@ bool QgsPostgresFeatureIterator::close()
mFeatureQueue.dequeue();
}

mClosed = true;
return true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/providers/postgres/qgspostgresfeatureiterator.h
Expand Up @@ -49,8 +49,6 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIterator

static const int sFeatureQueueSize;

//! Whether to use mFeatureQueue
bool mUseQueue;
};

#endif // QGSPOSTGRESFEATUREITERATOR_H

0 comments on commit 353e7ab

Please sign in to comment.