[GRASS-SVN] r55307 - grass/trunk/vector/v.out.postgis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Mar 10 14:09:37 PDT 2013
Author: martinl
Date: 2013-03-10 14:09:37 -0700 (Sun, 10 Mar 2013)
New Revision: 55307
Modified:
grass/trunk/vector/v.out.postgis/Makefile
grass/trunk/vector/v.out.postgis/main.c
Log:
v.out.postgis: remove feature table on error
Modified: grass/trunk/vector/v.out.postgis/Makefile
===================================================================
--- grass/trunk/vector/v.out.postgis/Makefile 2013-03-10 21:03:38 UTC (rev 55306)
+++ grass/trunk/vector/v.out.postgis/Makefile 2013-03-10 21:09:37 UTC (rev 55307)
@@ -2,9 +2,9 @@
PGM=v.out.postgis
-LIBES = $(GPROJLIB) $(VECTORLIB) $(DBMILIB) $(GISLIB)
+LIBES = $(GPROJLIB) $(VECTORLIB) $(DBMILIB) $(GISLIB) $(PQLIB)
DEPENDENCIES = $(GPROJDEP) $(VECTORDEP) $(DBMIDEP) $(GISDEP)
-EXTRA_INC = $(VECT_INC) $(PROJINC)
+EXTRA_INC = $(VECT_INC) $(PROJINC) $(PQINCPATH)
EXTRA_CFLAGS = $(VECT_CFLAGS)
include $(MODULE_TOPDIR)/include/Make/Module.make
Modified: grass/trunk/vector/v.out.postgis/main.c
===================================================================
--- grass/trunk/vector/v.out.postgis/main.c 2013-03-10 21:03:38 UTC (rev 55306)
+++ grass/trunk/vector/v.out.postgis/main.c 2013-03-10 21:09:37 UTC (rev 55307)
@@ -19,9 +19,12 @@
#include <grass/gis.h>
#include <grass/glocale.h>
+#include <libpq-fe.h>
+
#include "local_proto.h"
static void link_handler(void *);
+static void output_handler(void *);
int main(int argc, char *argv[])
{
@@ -122,6 +125,7 @@
if (-1 == Vect_open_new(&Out, olayer, Vect_is_3d(&In)))
G_fatal_error(_("Unable to create PostGIS layer <%s>"),
olayer);
+ G_add_error_handler(output_handler, &Out);
/* define attributes */
field = Vect_get_field_number(&In, params.layer->answer);
@@ -158,10 +162,40 @@
exit(EXIT_SUCCESS);
}
-void link_handler(void *p) {
+void link_handler(void *p)
+{
const char *link = (const char *) p;
G_debug(1, "link_handler: %s", link);
if (G_find_vector2(link, G_mapset()))
Vect_delete(link);
}
+
+void output_handler(void *p)
+{
+ char stmt[DB_SQL_MAX];
+
+ struct Map_info *Map;
+ struct Format_info_pg *pg_info;
+ PGresult *result;
+
+ Map = (struct Map_info *) p;
+ pg_info = &Map->fInfo.pg;
+
+ G_debug(1, "output_handler(): schema = %s; olayer = %s", pg_info->schema_name, pg_info->table_name);
+ sprintf(stmt, "SELECT DropGeometryTable('%s', '%s')", pg_info->schema_name, pg_info->table_name);
+ result = PQexec(pg_info->conn, stmt);
+ if (!result || PQresultStatus(result) != PGRES_TUPLES_OK) {
+ G_warning(_("Unable to drop table <%s.%s>"), pg_info->schema_name, pg_info->table_name);
+ }
+ PQclear(result);
+
+ if (pg_info->toposchema_name) {
+ sprintf(stmt, "SELECT topology.DropTopology('%s')", pg_info->toposchema_name);
+ result = PQexec(pg_info->conn, stmt);
+ if (!result || PQresultStatus(result) != PGRES_TUPLES_OK) {
+ G_warning(_("Unable to drop topology schema <%s>"), pg_info->toposchema_name);
+ }
+ }
+ PQclear(result);
+}
More information about the grass-commit
mailing list