Skip to content
Permalink
Browse files
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
  • Loading branch information
timlinux committed Jan 30, 2008
1 parent d3b27e5 commit a49dac53bffd041ddcb47c5056a30d07f10917cc
Showing with 11 additions and 6 deletions.
  1. +9 −6 src/providers/postgres/qgspostgresprovider.cpp
  2. +2 −0 src/providers/postgres/qgspostgresprovider.h
@@ -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 */
@@ -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)
@@ -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)
{
@@ -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)
{
@@ -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)
@@ -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();
@@ -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 a49dac5

Please sign in to comment.