diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index 81752c5ed383..57c86f44f7a1 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -443,7 +443,8 @@ QgsFeature *QgsPostgresProvider::getNextFeature(bool fetchAttributes) // std::cerr << "Error: " << PQerrorMessage(connection) << std::endl; // std::cerr << "Fetched " << PQntuples(queryResult) << "rows" << std::endl; if(PQntuples(queryResult) == 0){ - PQexec(connection, "end work"); + if (ready) + PQexec(connection, "end work"); ready = false; return 0; } @@ -525,7 +526,8 @@ QgsFeature* QgsPostgresProvider::getNextFeature(std::list const & attlist, if (rows == 0) { QgsDebugMsg("End of features."); - PQexec(connection, "end work"); + if (ready) + PQexec(connection, "end work"); ready = false; return 0; } @@ -644,6 +646,7 @@ void QgsPostgresProvider::select(QgsRect * rect, bool useIntersect) PQexec(connection, "end work"); } PQexec(connection,"begin work"); + ready = true; PQexec(connection, (const char *)(declare.utf8())); // TODO - see if this deallocates member features @@ -791,7 +794,10 @@ void QgsPostgresProvider::getFeatureGeometry(int key, QgsFeature *f) QgsDebugMsg("QgsPostgresProvider::getFeatureGeometry using: " + cursor); + if (ready) + PQexec(connection, "end work"); PQexec(connection, "begin work"); + ready = true; PQexec(connection, (const char *)(cursor.utf8())); QString fetch = "fetch forward 1 from qgisf"; @@ -801,6 +807,7 @@ void QgsPostgresProvider::getFeatureGeometry(int key, QgsFeature *f) { // Nothing found - therefore nothing to change PQexec(connection,"end work"); + ready = false; PQclear(geomResult); return; } @@ -822,8 +829,9 @@ void QgsPostgresProvider::getFeatureGeometry(int key, QgsFeature *f) PQclear(geomResult); - PQexec(connection,"end work"); - + if (ready) + PQexec(connection,"end work"); + ready = false; } @@ -848,16 +856,17 @@ void QgsPostgresProvider::reset() QgsDebugMsg("Setting up binary cursor: " + declare); // set up the cursor - PQexec(connection,"end work"); + if (ready) + PQexec(connection,"end work"); PQexec(connection,"begin work"); + ready = true; PQexec(connection, (const char *)(declare.utf8())); //QgsDebugMsg("Error: " + PQerrorMessage(connection)); // TODO - see if this deallocates member features mFeatureQueue.empty(); - ready = true; } /* QString QgsPostgresProvider::getFieldTypeName(PGconn * pd, int oid) {