Skip to content
Permalink
Browse files
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
  • Loading branch information
gsherman committed Nov 11, 2006
1 parent 8c28c1c commit 7f7400838d04625d19f55ae6705f9631c2e64d7c
Showing with 22 additions and 3 deletions.
  1. +22 −3 src/plugins/geoprocessing/qgspggeoprocessing.cpp
@@ -209,7 +209,7 @@ void QgsPgGeoprocessing::buffer()
}
// first create the new table

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

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

}
}
else
{
#ifdef QGISDEBUG
std::cerr << "Status from drop constraint is " << PQresultStatus(result) << std::endl;
std::cerr << "Error message is " << PQresStatus(PQresultStatus(result)) << std::endl;
#endif
}
}
else
{
#ifdef QGISDEBUG
std::cerr << "Status from add geometry column is " << PQresultStatus(geoCol) << std::endl;
std::cerr << "Error message is " << PQresStatus(PQresultStatus(geoCol)) << std::endl;
#endif
QMessageBox::critical(0, tr("Unable to add geometry column"),
QString(tr("Unable to add geometry column to the output table ") +
QString("%1-%2").arg(bb->bufferLayerName()).arg(PQerrorMessage(conn))));

0 comments on commit 7f74008

Please sign in to comment.