[GRASS-SVN] r60046 - grass/trunk/vector/v.in.db

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 2 09:30:15 PDT 2014


Author: hcho
Date: 2014-05-02 09:30:15 -0700 (Fri, 02 May 2014)
New Revision: 60046

Modified:
   grass/trunk/vector/v.in.db/main.c
Log:
Disallow overwriting the output vector when the input table is linked to the output vector because overwrting will delete the table first.

Modified: grass/trunk/vector/v.in.db/main.c
===================================================================
--- grass/trunk/vector/v.in.db/main.c	2014-05-02 15:25:56 UTC (rev 60045)
+++ grass/trunk/vector/v.in.db/main.c	2014-05-02 16:30:15 UTC (rev 60046)
@@ -116,6 +116,36 @@
     Cats = Vect_new_cats_struct();
     db_init_string(&sql);
 
+    if (G_get_overwrite()) {
+	/* We don't want to delete the input table when overwriting the output
+	 * vector. */
+	char name[GNAME_MAX], mapset[GMAPSET_MAX];
+
+	if (G_name_is_fully_qualified(outvect->answer, name, mapset)) {
+	} else {
+	    strcpy(name, outvect->answer);
+	    strcpy(mapset, G_mapset());
+	}
+
+	Vect_set_open_level(1); /* no topo needed */
+	if (G_find_vector2(name, mapset) && Vect_open_old(&Map, name, mapset)) {
+	    int num_dblinks;
+
+	    num_dblinks = Vect_get_num_dblinks(&Map);
+	    for (i = 0; i < num_dblinks; i++) {
+		if ((fi = Vect_get_dblink(&Map, i)) != NULL &&
+		    strcmp(fi->driver, driver_opt->answer) == 0 &&
+		    strcmp(fi->database, database_opt->answer) == 0 &&
+		    strcmp(fi->table, table_opt->answer) == 0)
+		    G_fatal_error(_("Vector <%s> cannot be overwritten "
+				    "because input table <%s> is linked to "
+				    "the output vector."),
+				    outvect->answer, table_opt->answer);
+	    }
+	    Vect_close(&Map);
+	}
+    }
+
     Vect_open_new(&Map, outvect->answer, with_z);
     Vect_set_error_handler_io(NULL, &Map);
     



More information about the grass-commit mailing list