[GRASS-SVN] r72945 - grass/trunk/scripts/v.db.addtable
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 3 08:10:19 PDT 2018
Author: mmetz
Date: 2018-07-03 08:10:19 -0700 (Tue, 03 Jul 2018)
New Revision: 72945
Modified:
grass/trunk/scripts/v.db.addtable/v.db.addtable.py
Log:
v.db.addtable: create unique index
Modified: grass/trunk/scripts/v.db.addtable/v.db.addtable.py
===================================================================
--- grass/trunk/scripts/v.db.addtable/v.db.addtable.py 2018-07-03 08:15:08 UTC (rev 72944)
+++ grass/trunk/scripts/v.db.addtable/v.db.addtable.py 2018-07-03 15:10:19 UTC (rev 72945)
@@ -136,6 +136,14 @@
except CalledModuleError:
grass.fatal(_("Unable to create table <%s>") % table)
+ if driver != "dbf":
+ sql = "CREATE UNIQUE INDEX IF NOT EXISTS %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)
+
# connect the map to the DB:
if schema:
table = '{schema}.{table}'.format(schema=schema, table=table)
More information about the grass-commit
mailing list