[GRASS-SVN] r64279 - grass/trunk/vector/v.extract

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 22 01:38:42 PST 2015


Author: mmetz
Date: 2015-01-22 01:38:42 -0800 (Thu, 22 Jan 2015)
New Revision: 64279

Modified:
   grass/trunk/vector/v.extract/copy_tab.c
Log:
v.extract: +index, grant privileges on table

Modified: grass/trunk/vector/v.extract/copy_tab.c
===================================================================
--- grass/trunk/vector/v.extract/copy_tab.c	2015-01-22 08:04:23 UTC (rev 64278)
+++ grass/trunk/vector/v.extract/copy_tab.c	2015-01-22 09:38:42 UTC (rev 64279)
@@ -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