Skip to content

Commit 3486d4b

Browse files
author
g_j_m
committed
Fix for ticket #406 (problems with copying selected attributes from a postgres
layer). Has the side-effect of eliminating the postgresql server 'no transaction in progress warnings'. git-svn-id: http://svn.osgeo.org/qgis/trunk@6171 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f6053ce commit 3486d4b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ QgsFeature *QgsPostgresProvider::getNextFeature(bool fetchAttributes)
443443
// std::cerr << "Error: " << PQerrorMessage(connection) << std::endl;
444444
// std::cerr << "Fetched " << PQntuples(queryResult) << "rows" << std::endl;
445445
if(PQntuples(queryResult) == 0){
446-
PQexec(connection, "end work");
446+
if (ready)
447+
PQexec(connection, "end work");
447448
ready = false;
448449
return 0;
449450
}
@@ -525,7 +526,8 @@ QgsFeature* QgsPostgresProvider::getNextFeature(std::list<int> const & attlist,
525526
if (rows == 0)
526527
{
527528
QgsDebugMsg("End of features.");
528-
PQexec(connection, "end work");
529+
if (ready)
530+
PQexec(connection, "end work");
529531
ready = false;
530532
return 0;
531533
}
@@ -644,6 +646,7 @@ void QgsPostgresProvider::select(QgsRect * rect, bool useIntersect)
644646
PQexec(connection, "end work");
645647
}
646648
PQexec(connection,"begin work");
649+
ready = true;
647650
PQexec(connection, (const char *)(declare.utf8()));
648651

649652
// TODO - see if this deallocates member features
@@ -791,7 +794,10 @@ void QgsPostgresProvider::getFeatureGeometry(int key, QgsFeature *f)
791794

792795
QgsDebugMsg("QgsPostgresProvider::getFeatureGeometry using: " + cursor);
793796

797+
if (ready)
798+
PQexec(connection, "end work");
794799
PQexec(connection, "begin work");
800+
ready = true;
795801
PQexec(connection, (const char *)(cursor.utf8()));
796802

797803
QString fetch = "fetch forward 1 from qgisf";
@@ -801,6 +807,7 @@ void QgsPostgresProvider::getFeatureGeometry(int key, QgsFeature *f)
801807
{
802808
// Nothing found - therefore nothing to change
803809
PQexec(connection,"end work");
810+
ready = false;
804811
PQclear(geomResult);
805812
return;
806813
}
@@ -822,8 +829,9 @@ void QgsPostgresProvider::getFeatureGeometry(int key, QgsFeature *f)
822829

823830
PQclear(geomResult);
824831

825-
PQexec(connection,"end work");
826-
832+
if (ready)
833+
PQexec(connection,"end work");
834+
ready = false;
827835
}
828836

829837

@@ -848,16 +856,17 @@ void QgsPostgresProvider::reset()
848856
QgsDebugMsg("Setting up binary cursor: " + declare);
849857

850858
// set up the cursor
851-
PQexec(connection,"end work");
859+
if (ready)
860+
PQexec(connection,"end work");
852861

853862
PQexec(connection,"begin work");
863+
ready = true;
854864
PQexec(connection, (const char *)(declare.utf8()));
855865
//QgsDebugMsg("Error: " + PQerrorMessage(connection));
856866

857867
// TODO - see if this deallocates member features
858868
mFeatureQueue.empty();
859869

860-
ready = true;
861870
}
862871
/* QString QgsPostgresProvider::getFieldTypeName(PGconn * pd, int oid)
863872
{

0 commit comments

Comments
 (0)