Browse Source

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.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70506 15284696-431f-4ddb-bdfa-cd5b030d7da7
Huidae Cho 8 years ago
parent
commit
eade3d5db6
2 changed files with 34 additions and 3 deletions
  1. 3 3
      raster/r.to.vect/main.c
  2. 31 0
      raster/r.to.vect/set_error_handler.c

+ 3 - 3
raster/r.to.vect/main.c

@@ -151,10 +151,11 @@ int main(int argc, char *argv[])
 	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 @@ int main(int argc, char *argv[])
 	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);

+ 31 - 0
raster/r.to.vect/set_error_handler.c

@@ -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);
+}