[GRASS-SVN] r64389 - grass/branches/releasebranch_7_0/vector/v.extract

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 2 00:02:05 PST 2015


Author: mmetz
Date: 2015-02-02 00:02:05 -0800 (Mon, 02 Feb 2015)
New Revision: 64389

Modified:
   grass/branches/releasebranch_7_0/vector/v.extract/copy_tab.c
Log:
v.extract: +index, grant privileges on table (backport from trunk)

Modified: grass/branches/releasebranch_7_0/vector/v.extract/copy_tab.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.extract/copy_tab.c	2015-02-02 03:27:58 UTC (rev 64388)
+++ grass/branches/releasebranch_7_0/vector/v.extract/copy_tab.c	2015-02-02 08:02:05 UTC (rev 64389)
@@ -14,6 +14,7 @@
     
     struct field_info *IFi, *OFi;
     struct line_cats *Cats;
+    dbDriver *driver;
     
     ntabs = 0;
     
@@ -38,14 +39,17 @@
 	for (i = 0; i < Cats->n_cats; i++) {
 	    int f, j;
 	    
+	    f = -1;
 	    for (j = 0; j < nfields; j++) {	/* find field */
 		if (fields[j] == Cats->field[i]) {
 		    f = j;
 		    break;
 		}
 	    }
-	    ocats[f][nocats[f]] = Cats->cat[i];
-	    nocats[f]++;
+	    if (f >= 0) {
+		ocats[f][nocats[f]] = Cats->cat[i];
+		nocats[f]++;
+	    }
 	}
     }
     
@@ -104,6 +108,31 @@
 	    G_warning(_("Unable to copy table <%s>"), IFi->table);
 	}
 	else {
+
+	    driver = db_start_driver_open_database(OFi->driver,
+						   Vect_subst_var(OFi->database,
+								    Out));
+
+	    if (!driver) {
+		G_warning(_("Unable to open database <%s> with driver <%s>"),
+			      OFi->database, OFi->driver);
+	    }
+	    else {
+
+		/* do not allow duplicate keys */
+		if (db_create_index2(driver, OFi->table, IFi->key) != DB_OK) {
+		    G_warning(_("Unable to create index"));
+		}
+
+		if (db_grant_on_table(driver, OFi->table, DB_PRIV_SELECT,
+		     DB_GROUP | DB_PUBLIC) != DB_OK) {
+		    G_warning(_("Unable to grant privileges on table <%s>"),
+				  OFi->table);
+		}
+
+		db_close_database_shutdown_driver(driver);
+	    }
+
 	    Vect_map_add_dblink(Out, OFi->number, OFi->name, OFi->table,
 				IFi->key, OFi->database, OFi->driver);
 	}



More information about the grass-commit mailing list