Skip to content

Commit 69a153e

Browse files
author
jef
committedMay 18, 2010
postgres provider: lazy feature count
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13524 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
139139

140140
deduceEndian();
141141
calculateExtents();
142-
getFeatureCount();
142+
featuresCounted = -1;
143143

144144
// set the primary key
145145
getPrimaryKey();
@@ -735,14 +735,6 @@ QGis::WkbType QgsPostgresProvider::geometryType() const
735735
return geomType;
736736
}
737737

738-
/**
739-
* Return the feature type
740-
*/
741-
long QgsPostgresProvider::featureCount() const
742-
{
743-
return featuresCounted;
744-
}
745-
746738
const QgsField &QgsPostgresProvider::field( int index ) const
747739
{
748740
QgsFieldMap::const_iterator it = attributeFields.find( index );
@@ -2753,14 +2745,20 @@ bool QgsPostgresProvider::setSubsetString( QString theSQL )
27532745
setDataSourceUri( mUri.uri() );
27542746

27552747
// need to recalculate the number of features...
2756-
getFeatureCount();
2748+
featuresCounted = -1;
27572749
calculateExtents();
27582750

27592751
return true;
27602752
}
27612753

2762-
long QgsPostgresProvider::getFeatureCount()
2754+
/**
2755+
* Return the feature count
2756+
*/
2757+
long QgsPostgresProvider::featureCount() const
27632758
{
2759+
if( featuresCounted >= 0 )
2760+
return featuresCounted;
2761+
27642762
// get total number of features
27652763

27662764
// First get an approximate count; then delegate to
@@ -2783,12 +2781,12 @@ long QgsPostgresProvider::getFeatureCount()
27832781

27842782
Result result = connectionRO->PQexec( sql );
27852783

2786-
QgsDebugMsg( "Approximate Number of features as text: " +
2784+
QgsDebugMsg( "number of features as text: " +
27872785
QString::fromUtf8( PQgetvalue( result, 0, 0 ) ) );
27882786

27892787
featuresCounted = QString::fromUtf8( PQgetvalue( result, 0, 0 ) ).toLong();
27902788

2791-
QgsDebugMsg( "Approximate Number of features: " + QString::number( featuresCounted ) );
2789+
QgsDebugMsg( "number of features: " + QString::number( featuresCounted ) );
27922790

27932791
return featuresCounted;
27942792
}

‎src/providers/postgres/qgspostgresprovider.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
446446
/**
447447
* Number of features in the layer
448448
*/
449-
long featuresCounted;
449+
mutable long featuresCounted;
450450

451451
/**
452452
* Feature queue that GetNextFeature will retrieve from
@@ -576,9 +576,6 @@ class QgsPostgresProvider : public QgsVectorDataProvider
576576

577577
int enabledCapabilities;
578578

579-
//! Get the feature count based on the where clause
580-
long getFeatureCount();
581-
582579
//! Calculate the extents of the layer
583580
void calculateExtents();
584581

0 commit comments

Comments
 (0)
Please sign in to comment.