@@ -68,7 +68,7 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
6868QgsPostgresProvider::QgsPostgresProvider (QString const & uri)
6969 : QgsVectorDataProvider(uri),
7070 geomType(QGis::WKBUnknown),
71- mFeatureQueueSize(200 ),
71+ mFeatureQueueSize(200 ),
7272 gotPostgisVersion(FALSE )
7373{
7474 // assume this is a valid layer until we determine otherwise
@@ -397,9 +397,18 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
397397 {
398398 QString fetch = QString (" fetch forward %1 from qgisf" )
399399 .arg (mFeatureQueueSize );
400-
401- queryResult = PQexec (connection, (const char *)fetch);
402-
400+
401+ if (mFirstFetch )
402+ {
403+ if (PQsendQuery (connection, (const char *)fetch) == 0 ) // fetch features in asynchronously
404+ {
405+ qWarning (" PQsendQuery failed (1)" );
406+ }
407+ }
408+ mFirstFetch = false ;
409+ queryResult = PQgetResult (connection);
410+ PGresult* bla = PQgetResult (connection); // just to get the 0 pointer...
411+
403412 int rows = PQntuples (queryResult);
404413
405414 if (rows == 0 )
@@ -434,7 +443,7 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
434443 char * attribute = PQgetvalue (queryResult, row, PQfnumber (queryResult,*name_it));
435444
436445 QString val = QString::fromUtf8 (attribute);
437- switch (attributeFields[*index_it].type ())
446+ switch (attributeFields[*index_it].type ())
438447 {
439448 case QVariant::Int:
440449 feature.addAttribute (*index_it, val.toInt ());
@@ -463,19 +472,20 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
463472 }
464473 else
465474 {
466- // QgsDebugMsg("Couldn't get the feature geometry in binary form");
475+ QgsDebugMsg (" Couldn't get the feature geometry in binary form" );
467476 }
468- }
469-
470- // QgsDebugMsg(" pushing " + QString::number(f->featureId());
477+ }
471478
472479 mFeatureQueue .push (feature);
473480
474481 } // for each row in queue
475-
476- // QgsDebugMsg("retrieved batch of features.");
477482
478483 PQclear (queryResult);
484+
485+ if (PQsendQuery (connection, (const char *)fetch) == 0 ) // already fetch the next couple of features asynchronously
486+ {
487+ qWarning (" PQsendQuery failed (2)" );
488+ }
479489
480490 } // if new queue is required
481491
@@ -486,11 +496,9 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
486496 }
487497 else
488498 {
489- // QgsDebugMsg("Read attempt on an invalid postgresql data source");
499+ QgsDebugMsg (" Read attempt on an invalid postgresql data source" );
490500 return false ;
491501 }
492-
493- // QgsDebugMsg("returning feature " + QString::number(feat.featureId()));
494502
495503 return true ;
496504}
@@ -583,6 +591,7 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes,
583591 PQexec (connection, (const char *)(declare.utf8 ()));
584592
585593 mFeatureQueue .empty ();
594+ mFirstFetch = true ;
586595}
587596
588597bool QgsPostgresProvider::getFeatureAtId (int featureId,
0 commit comments