Skip to content
Permalink
Browse files
postgres provider: lazy feature count
git-svn-id: http://svn.osgeo.org/qgis/trunk@13524 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 18, 2010
1 parent a0a699d commit 7366f4ca1b134cb9e851ec1fc847bd14b75dabed
Showing with 12 additions and 17 deletions.
  1. +11 −13 src/providers/postgres/qgspostgresprovider.cpp
  2. +1 −4 src/providers/postgres/qgspostgresprovider.h
@@ -139,7 +139,7 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )

deduceEndian();
calculateExtents();
getFeatureCount();
featuresCounted = -1;

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

/**
* Return the feature type
*/
long QgsPostgresProvider::featureCount() const
{
return featuresCounted;
}

const QgsField &QgsPostgresProvider::field( int index ) const
{
QgsFieldMap::const_iterator it = attributeFields.find( index );
@@ -2753,14 +2745,20 @@ bool QgsPostgresProvider::setSubsetString( QString theSQL )
setDataSourceUri( mUri.uri() );

// need to recalculate the number of features...
getFeatureCount();
featuresCounted = -1;
calculateExtents();

return true;
}

long QgsPostgresProvider::getFeatureCount()
/**
* Return the feature count
*/
long QgsPostgresProvider::featureCount() const
{
if( featuresCounted >= 0 )
return featuresCounted;

// get total number of features

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

Result result = connectionRO->PQexec( sql );

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

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

QgsDebugMsg( "Approximate Number of features: " + QString::number( featuresCounted ) );
QgsDebugMsg( "number of features: " + QString::number( featuresCounted ) );

return featuresCounted;
}
@@ -446,7 +446,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
/**
* Number of features in the layer
*/
long featuresCounted;
mutable long featuresCounted;

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

int enabledCapabilities;

//! Get the feature count based on the where clause
long getFeatureCount();

//! Calculate the extents of the layer
void calculateExtents();

0 comments on commit 7366f4c

Please sign in to comment.