[GRASS-SVN] r70506 - grass/trunk/raster/r.to.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 8 09:48:13 PST 2017


Author: hcho
Date: 2017-02-08 09:48:13 -0800 (Wed, 08 Feb 2017)
New Revision: 70506

Added:
   grass/trunk/raster/r.to.vect/set_error_handler.c
Modified:
   grass/trunk/raster/r.to.vect/main.c
Log:
Call the DB error handler before the vector handler to avoid busy database warnings

Reproduce this issue in the North Carolina sample dataset:
	r.to.vect input=aspect output=aspect type=line

Any unthinned input raster will produce the same issue.


Modified: grass/trunk/raster/r.to.vect/main.c
===================================================================
--- grass/trunk/raster/r.to.vect/main.c	2017-02-08 17:37:18 UTC (rev 70505)
+++ grass/trunk/raster/r.to.vect/main.c	2017-02-08 17:48:13 UTC (rev 70506)
@@ -151,10 +151,11 @@
 	G_warning(_("Categories will be unique sequence, raster values will be lost."));
     }
 
+    set_error_handler(&Map, &driver);
+
     if (Vect_open_new(&Map, out_opt->answer, z_flg->answer) < 0)
 	G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
-    Vect_set_error_handler_io(NULL, &Map);
-                              
+
     Vect_hist_command(&Map);
 
     Cats = Vect_new_cats_struct();
@@ -186,7 +187,6 @@
 	if (driver == NULL)
 	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
 			  Fi->database, Fi->driver);
-        db_set_error_handler_driver(driver);
 
 	/* Create new table */
 	db_zero_string(&sql);

Added: grass/trunk/raster/r.to.vect/set_error_handler.c
===================================================================
--- grass/trunk/raster/r.to.vect/set_error_handler.c	                        (rev 0)
+++ grass/trunk/raster/r.to.vect/set_error_handler.c	2017-02-08 17:48:13 UTC (rev 70506)
@@ -0,0 +1,31 @@
+#include <grass/gis.h>
+#include <grass/vector.h>
+
+struct handler_input
+{
+    struct Map_info *Map;
+    dbDriver **driver;
+};
+
+static void error_handler(void *p)
+{
+    const struct handler_input *input = (const struct handler_input *)p;
+
+    if (input->driver && *input->driver)
+	db_close_database_shutdown_driver(*(input->driver));
+    if (input->Map) {
+	if (input->Map->open == VECT_OPEN_CODE)
+	    Vect_close(input->Map);
+	Vect_delete(input->Map->name);
+    }
+}
+
+void set_error_handler(struct Map_info *Map, dbDriver **driver)
+{
+    struct handler_input *input = G_malloc(sizeof(struct handler_input));
+
+    input->Map = Map;
+    input->driver = driver;
+
+    G_add_error_handler(error_handler, input);
+}



More information about the grass-commit mailing list