@@ -564,7 +564,6 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes, QgsRect rect,
564
564
return ;
565
565
566
566
mFetching = true ;
567
- mFirstFetch = true ;
568
567
}
569
568
570
569
bool QgsPostgresProvider::getNextFeature (QgsFeature& feature)
@@ -577,43 +576,37 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
577
576
return false ;
578
577
}
579
578
580
- // Top up our queue if it is empty
581
- if (mFeatureQueue .empty ())
579
+ if ( mFeatureQueue .empty () )
582
580
{
583
581
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
585
583
{
586
- if (PQsendQuery (connection, fetch.toUtf8 ()) == 0 ) // fetch features in asynchronously
587
- {
588
- qWarning (" PQsendQuery failed (1)" );
589
- }
584
+ qWarning (" PQsendQuery failed (1)" );
590
585
}
591
- mFirstFetch = false ;
592
- queryResult = PQgetResult (connection);
593
- PQgetResult (connection); // just to get the 0 pointer...
594
586
595
- int rows = PQntuples ( queryResult) ;
596
- if (rows == 0 )
587
+ PGresult * queryResult;
588
+ while ( (queryResult = PQgetResult (connection)) )
597
589
{
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 ;
608
593
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
610
599
611
- if (PQsendQuery (connection, fetch.toUtf8 ()) == 0 ) // already fetch the next couple of features asynchronously
612
- {
613
- qWarning (" PQsendQuery failed (2)" );
600
+ PQclear (queryResult);
614
601
}
615
- } // if new queue is required
602
+ }
616
603
604
+ if ( mFeatureQueue .empty () )
605
+ {
606
+ QgsDebugMsg (" End of features" );
607
+ return false ;
608
+ }
609
+
617
610
// Now return the next feature from the queue
618
611
if (mFetchGeom )
619
612
{
@@ -1890,8 +1883,10 @@ bool QgsPostgresProvider::deleteFeatures(const QgsFeatureIds & id)
1890
1883
PQexecNR (connection,QString (" BEGIN" ).toUtf8 ());
1891
1884
1892
1885
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);
1895
1890
QgsDebugMsg (" delete sql: " +sql);
1896
1891
1897
1892
// send DELETE statement and do error handling
@@ -1920,8 +1915,10 @@ bool QgsPostgresProvider::addAttributes(const QgsNewAttributesMap & name)
1920
1915
1921
1916
for (QgsNewAttributesMap::const_iterator iter=name.begin ();iter!=name.end ();++iter)
1922
1917
{
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 ());
1925
1922
QgsDebugMsg (sql);
1926
1923
1927
1924
// send sql statement and do error handling
@@ -1956,7 +1953,9 @@ bool QgsPostgresProvider::deleteAttributes(const QgsAttributeIds& ids)
1956
1953
continue ;
1957
1954
1958
1955
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));
1960
1959
1961
1960
// send sql statement and do error handling
1962
1961
PGresult* result=PQexec (connection, sql.toUtf8 ());
0 commit comments