@@ -564,7 +564,6 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes, QgsRect rect,
564564 return ;
565565
566566 mFetching = true ;
567- mFirstFetch = true ;
568567}
569568
570569bool QgsPostgresProvider::getNextFeature (QgsFeature& feature)
@@ -577,43 +576,37 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
577576 return false ;
578577 }
579578
580- // Top up our queue if it is empty
581- if (mFeatureQueue .empty ())
579+ if ( mFeatureQueue .empty () )
582580 {
583581 QString fetch = QString (" fetch forward %1 from %2" ).arg (mFeatureQueueSize ).arg (cursorName);
584- if (mFirstFetch )
582+ if (PQsendQuery (connection, fetch. toUtf8 ()) == 0 ) // fetch features in asynchronously
585583 {
586- if (PQsendQuery (connection, fetch.toUtf8 ()) == 0 ) // fetch features in asynchronously
587- {
588- qWarning (" PQsendQuery failed (1)" );
589- }
584+ qWarning (" PQsendQuery failed (1)" );
590585 }
591- mFirstFetch = false ;
592- queryResult = PQgetResult (connection);
593- PQgetResult (connection); // just to get the 0 pointer...
594586
595- int rows = PQntuples ( queryResult) ;
596- if (rows == 0 )
587+ PGresult * queryResult;
588+ while ( (queryResult = PQgetResult (connection)) )
597589 {
598- QgsDebugMsg (" End of features" );
599- PQclear (queryResult);
600- return false ;
601- }
602-
603- for (int row = 0 ; row < rows; row++)
604- {
605- mFeatureQueue .push (QgsFeature ());
606- getFeature (queryResult, row, mFetchGeom , mFeatureQueue .back (), mAttributesToFetch );
607- } // for each row in queue
590+ int rows = PQntuples (queryResult);
591+ if (rows == 0 )
592+ continue ;
608593
609- PQclear (queryResult);
594+ for (int row = 0 ; row < rows; row++)
595+ {
596+ mFeatureQueue .push (QgsFeature ());
597+ getFeature (queryResult, row, mFetchGeom , mFeatureQueue .back (), mAttributesToFetch );
598+ } // for each row in queue
610599
611- if (PQsendQuery (connection, fetch.toUtf8 ()) == 0 ) // already fetch the next couple of features asynchronously
612- {
613- qWarning (" PQsendQuery failed (2)" );
600+ PQclear (queryResult);
614601 }
615- } // if new queue is required
602+ }
616603
604+ if ( mFeatureQueue .empty () )
605+ {
606+ QgsDebugMsg (" End of features" );
607+ return false ;
608+ }
609+
617610 // Now return the next feature from the queue
618611 if (mFetchGeom )
619612 {
@@ -1890,8 +1883,10 @@ bool QgsPostgresProvider::deleteFeatures(const QgsFeatureIds & id)
18901883 PQexecNR (connection,QString (" BEGIN" ).toUtf8 ());
18911884
18921885 for (QgsFeatureIds::const_iterator it=id.begin ();it!=id.end ();++it) {
1893- QString sql (" DELETE FROM " +mSchemaTableName +" WHERE " +quotedIdentifier (primaryKey)+" =" +QString::number (*it));
1894-
1886+ QString sql = QString (" DELETE FROM %1 WHERE %2=%3" )
1887+ .arg (mSchemaTableName )
1888+ .arg (quotedIdentifier (primaryKey))
1889+ .arg (*it);
18951890 QgsDebugMsg (" delete sql: " +sql);
18961891
18971892 // send DELETE statement and do error handling
@@ -1920,8 +1915,10 @@ bool QgsPostgresProvider::addAttributes(const QgsNewAttributesMap & name)
19201915
19211916 for (QgsNewAttributesMap::const_iterator iter=name.begin ();iter!=name.end ();++iter)
19221917 {
1923- QString sql=" ALTER TABLE " +mSchemaTableName +" ADD COLUMN " +quotedIdentifier (iter.key ())+" " +iter.value ();
1924-
1918+ QString sql = QString (" ALTER TABLE %1 ADD COLUMN %2 %3" )
1919+ .arg (mSchemaTableName )
1920+ .arg (quotedIdentifier (iter.key ()))
1921+ .arg (iter.value ());
19251922 QgsDebugMsg (sql);
19261923
19271924 // send sql statement and do error handling
@@ -1956,7 +1953,9 @@ bool QgsPostgresProvider::deleteAttributes(const QgsAttributeIds& ids)
19561953 continue ;
19571954
19581955 QString column = field_it->name ();
1959- QString sql=" ALTER TABLE " +mSchemaTableName +" DROP COLUMN " +quotedIdentifier (column);
1956+ QString sql = QString (" ALTER TABLE %1 DROP COLUMN %2" )
1957+ .arg (mSchemaTableName )
1958+ .arg (quotedIdentifier (column));
19601959
19611960 // send sql statement and do error handling
19621961 PGresult* result=PQexec (connection, sql.toUtf8 ());
0 commit comments