Skip to content

Commit 7f74008

Browse files
author
gsherman
committedNov 11, 2006
Fix for buffer plugin (ticket #349).
This fix has been tested with: ** POSTGIS="1.1.1" GEOS="2.0.1" PROJ="Rel. 4.4.9, 29 Oct 2004" ** PostgreSQL 8.1.3 Because of the change in the name of the geometry check constraint created by addgeometrycolumn (from $2 to enforce_geotype_shape) this fix requires a recent version of PostGIS. The minimum PostGIS version that will work with this fix is unknown. Additional testing is needed by other PostGIS/PostgreSQL version combinations. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6077 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed
 

‎src/plugins/geoprocessing/qgspggeoprocessing.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void QgsPgGeoprocessing::buffer()
209209
}
210210
// first create the new table
211211

212-
sql = QString("create table %1.%2 (%3 %4)")
212+
sql = QString("create table %1.%2 (%3 %4 PRIMARY KEY)")
213213
.arg(bb->schema())
214214
.arg(bb->bufferLayerName())
215215
.arg(objId)
@@ -220,6 +220,7 @@ void QgsPgGeoprocessing::buffer()
220220
result = PQexec(conn, (const char *) sql);
221221
#ifdef QGISDEBUG
222222
std::cerr << "Status from create table is " << PQresultStatus(result) << std::endl;
223+
std::cerr << "Error message is " << PQresStatus(PQresultStatus(result)) << std::endl;
223224
#endif
224225
if (PQresultStatus(result) == PGRES_COMMAND_OK) {
225226
PQclear(result);
@@ -237,16 +238,22 @@ void QgsPgGeoprocessing::buffer()
237238
#endif
238239
PGresult *geoCol = PQexec(conn, (const char *) sql);
239240

240-
if (PQresultStatus(geoCol) == PGRES_COMMAND_OK) {
241+
if (PQresultStatus(geoCol) == PGRES_TUPLES_OK) {
241242
PQclear(geoCol);
243+
/* The constraint naming convention has changed in PostGIS
244+
* from $2 to enforce_geotype_shape. This change means the
245+
* buffer plugin will fail for older version of PostGIS.
246+
*/
242247
// drop the check constraint based on geometry type
243-
sql = QString("alter table %1.%2 drop constraint \"$2\"")
248+
sql = QString("alter table %1.%2 drop constraint \"enforce_geotype_shape\"")
244249
.arg(bb->schema())
245250
.arg(bb->bufferLayerName());
246251
#ifdef QGISDEBUG
247252
std::cerr << sql.toLocal8Bit().data() << std::endl;
248253
#endif
249254
result = PQexec(conn, (const char *) sql);
255+
if(PQresultStatus(result) == PGRES_COMMAND_OK)
256+
{
250257
PQclear(result);
251258
// check pg version and formulate insert query accordingly
252259
result = PQexec(conn,"select version()");
@@ -325,9 +332,21 @@ void QgsPgGeoprocessing::buffer()
325332
"postgres");
326333

327334
}
335+
}
336+
else
337+
{
338+
#ifdef QGISDEBUG
339+
std::cerr << "Status from drop constraint is " << PQresultStatus(result) << std::endl;
340+
std::cerr << "Error message is " << PQresStatus(PQresultStatus(result)) << std::endl;
341+
#endif
342+
}
328343
}
329344
else
330345
{
346+
#ifdef QGISDEBUG
347+
std::cerr << "Status from add geometry column is " << PQresultStatus(geoCol) << std::endl;
348+
std::cerr << "Error message is " << PQresStatus(PQresultStatus(geoCol)) << std::endl;
349+
#endif
331350
QMessageBox::critical(0, tr("Unable to add geometry column"),
332351
QString(tr("Unable to add geometry column to the output table ") +
333352
QString("%1-%2").arg(bb->bufferLayerName()).arg(PQerrorMessage(conn))));

0 commit comments

Comments
 (0)
Please sign in to comment.