Skip to content

Commit

Permalink
Fix for buffer plugin (ticket #349).
Browse files Browse the repository at this point in the history
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 7f74008
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/plugins/geoprocessing/qgspggeoprocessing.cpp
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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()");
Expand Down Expand Up @@ -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))));
Expand Down

0 comments on commit 7f74008

Please sign in to comment.