Skip to content

Commit

Permalink
Applied bugfix patch from Stefanie Tellex:
Browse files Browse the repository at this point in the history
 - 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@8092 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 30, 2008
1 parent b0425be commit fc0a8a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -57,14 +57,17 @@

const QString POSTGRES_KEY = "postgres";
const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";

int QgsPostgresProvider::providerIds = 0;

QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
: QgsVectorDataProvider(uri),
geomType(QGis::WKBUnknown),
mFeatureQueueSize(200),
gotPostgisVersion(FALSE)
{

providerId = QString("%1").arg(providerIds++);

// assume this is a valid layer until we determine otherwise
valid = true;
/* OPEN LOG FILE */
Expand Down Expand Up @@ -330,7 +333,7 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
// Top up our queue if it is empty
if (mFeatureQueue.empty())
{
QString fetch = QString("fetch forward %1 from qgisf")
QString fetch = QString("fetch forward %1 from qgisf" + providerId)
.arg(mFeatureQueueSize);

if(mFirstFetch)
Expand Down Expand Up @@ -472,7 +475,7 @@ void QgsPostgresProvider::select(QgsAttributeList fetchAttributes,
}
}

QString declare = "declare qgisf binary cursor for select \"" + primaryKey + "\"";
QString declare = "declare qgisf" + providerId + " binary cursor for select \"" + primaryKey + "\"";

if(fetchGeometry)
{
Expand Down Expand Up @@ -566,7 +569,7 @@ bool QgsPostgresProvider::getFeatureAtId(int featureId,
}
}

QString sql = "declare qgisfid binary cursor for select \"" + primaryKey + "\"";
QString sql = "declare qgisfid" + providerId + " binary cursor for select \"" + primaryKey + "\"";

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

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

int rows = PQntuples(res);
if (rows == 0)
Expand Down Expand Up @@ -712,7 +715,7 @@ QString QgsPostgresProvider::dataComment() const

void QgsPostgresProvider::reset()
{
QString move = "move 0 in qgisf"; //move cursor to first record
QString move = "move 0 in qgisf" + providerId; //move cursor to first record
PQexec(connection, (const char *)(move.utf8()));
mFeatureQueue.empty();
loadFields();
Expand Down
2 changes: 2 additions & 0 deletions src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -566,6 +566,8 @@ class QgsPostgresProvider:public QgsVectorDataProvider
void disconnectDb();

static QMap<QString, Conn *> connections;
static int providerIds;
QString providerId;
};

#endif

0 comments on commit fc0a8a1

Please sign in to comment.