[GRASS-SVN] r73041 - grass/branches/releasebranch_7_4/scripts/v.db.addtable

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 3 14:23:24 PDT 2018


Author: mmetz
Date: 2018-08-03 14:23:24 -0700 (Fri, 03 Aug 2018)
New Revision: 73041

Modified:
   grass/branches/releasebranch_7_4/scripts/v.db.addtable/v.db.addtable.py
Log:
v.db.addtable: create unique index (backport trunk r72945)

Modified: grass/branches/releasebranch_7_4/scripts/v.db.addtable/v.db.addtable.py
===================================================================
--- grass/branches/releasebranch_7_4/scripts/v.db.addtable/v.db.addtable.py	2018-08-03 21:20:28 UTC (rev 73040)
+++ grass/branches/releasebranch_7_4/scripts/v.db.addtable/v.db.addtable.py	2018-08-03 21:23:24 UTC (rev 73041)
@@ -6,6 +6,7 @@
 # AUTHOR(S):    Markus Neteler
 #               Converted to Python by Glynn Clements
 #               Key column added by Martin Landa <landa.martin gmail.com>
+#               Table index added by Markus Metz
 # PURPOSE:      interface to db.execute to creates and add a new table to given vector map
 # COPYRIGHT:    (C) 2005, 2007, 2008, 2011  by Markus Neteler & the GRASS Development Team
 #
@@ -136,6 +137,16 @@
         except CalledModuleError:
             grass.fatal(_("Unable to create table <%s>") % table)
 
+	# create index, see db/driver/*/index.c
+        if driver != "dbf":
+            sql = "CREATE UNIQUE INDEX %s_%s ON %s (%s)" % (table, key, table, key)
+            try:
+		grass.run_command('db.execute',
+				  database=database, driver=driver, sql=sql)
+	    except:
+		grass.warning(_("Unable to create index on table <%s>") % table)
+		pass
+
     # connect the map to the DB:
     if schema:
         table = '{schema}.{table}'.format(schema=schema, table=table)



More information about the grass-commit mailing list