Skip to content

Commit a49dac5

Browse files
author
timlinux
committed
Applied bugfix patch from Stefanie Tellex:
- The bug occurs when you make two providers that access the same table, and then try to iterate through the features in each provider in a nested loop. - The provider in the inner loop would never have any features because all providers use the same cursor name so things would get messed up. - This patch fixes the bug by adding a providerId member to QgsPostgresProvider, and appending the id to all cursor names. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8092 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d3b27e5 commit a49dac5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/providers/postgres/qgspostgresprovider.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@
5757

5858
const QString POSTGRES_KEY = "postgres";
5959
const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
60-
60+
int QgsPostgresProvider::providerIds = 0;
6161

6262
QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
6363
: QgsVectorDataProvider(uri),
6464
geomType(QGis::WKBUnknown),
6565
mFeatureQueueSize(200),
6666
gotPostgisVersion(FALSE)
6767
{
68+
69+
providerId = QString("%1").arg(providerIds++);
70+
6871
// assume this is a valid layer until we determine otherwise
6972
valid = true;
7073
/* OPEN LOG FILE */
@@ -330,7 +333,7 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
330333
// Top up our queue if it is empty
331334
if (mFeatureQueue.empty())
332335
{
333-
QString fetch = QString("fetch forward %1 from qgisf")
336+
QString fetch = QString("fetch forward %1 from qgisf" + providerId)
334337
.arg(mFeatureQueueSize);
335338

336339
if(mFirstFetch)
@@ -472,7 +475,7 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes,
472475
}
473476
}
474477

475-
QString declare = "declare qgisf binary cursor for select \"" + primaryKey + "\"";
478+
QString declare = "declare qgisf" + providerId + " binary cursor for select \"" + primaryKey + "\"";
476479

477480
if(fetchGeometry)
478481
{
@@ -566,7 +569,7 @@ bool QgsPostgresProvider::getFeatureAtId(int featureId,
566569
}
567570
}
568571

569-
QString sql = "declare qgisfid binary cursor for select \"" + primaryKey + "\"";
572+
QString sql = "declare qgisfid" + providerId + " binary cursor for select \"" + primaryKey + "\"";
570573

571574
if(fetchGeometry)
572575
{
@@ -591,7 +594,7 @@ bool QgsPostgresProvider::getFeatureAtId(int featureId,
591594
// execute query
592595
PQexec(connection, (const char *)(sql.utf8()));
593596

594-
PGresult *res = PQexec(connection, "fetch forward 1 from qgisfid");
597+
PGresult *res = PQexec(connection, "fetch forward 1 from qgisfid" + providerId);
595598

596599
int rows = PQntuples(res);
597600
if (rows == 0)
@@ -712,7 +715,7 @@ QString QgsPostgresProvider::dataComment() const
712715

713716
void QgsPostgresProvider::reset()
714717
{
715-
QString move = "move 0 in qgisf"; //move cursor to first record
718+
QString move = "move 0 in qgisf" + providerId; //move cursor to first record
716719
PQexec(connection, (const char *)(move.utf8()));
717720
mFeatureQueue.empty();
718721
loadFields();

src/providers/postgres/qgspostgresprovider.h

+2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ class QgsPostgresProvider:public QgsVectorDataProvider
566566
void disconnectDb();
567567

568568
static QMap<QString, Conn *> connections;
569+
static int providerIds;
570+
QString providerId;
569571
};
570572

571573
#endif

0 commit comments

Comments
 (0)